summaryrefslogtreecommitdiff
path: root/chromium/services/ui/service.h
blob: 6bf24632ee0c4e96e481610de70ef8c8b77343ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SERVICES_UI_SERVICE_H_
#define SERVICES_UI_SERVICE_H_

#include <stdint.h>

#include <map>
#include <memory>
#include <string>
#include <vector>

#include "base/macros.h"
#include "components/discardable_memory/public/interfaces/discardable_shared_memory_manager.mojom.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/cpp/service_runner.h"
#include "services/ui/ime/ime_registrar_impl.h"
#include "services/ui/ime/ime_server_impl.h"
#include "services/ui/input_devices/input_device_server.h"
#include "services/ui/public/interfaces/accessibility_manager.mojom.h"
#include "services/ui/public/interfaces/clipboard.mojom.h"
#include "services/ui/public/interfaces/display_manager.mojom.h"
#include "services/ui/public/interfaces/gpu.mojom.h"
#include "services/ui/public/interfaces/ime/ime.mojom.h"
#include "services/ui/public/interfaces/user_access_manager.mojom.h"
#include "services/ui/public/interfaces/user_activity_monitor.mojom.h"
#include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom.h"
#include "services/ui/public/interfaces/window_server_test.mojom.h"
#include "services/ui/public/interfaces/window_tree.mojom.h"
#include "services/ui/public/interfaces/window_tree_host.mojom.h"
#include "services/ui/ws/user_id.h"
#include "services/ui/ws/window_server_delegate.h"

#if defined(USE_OZONE)
#include "ui/ozone/public/client_native_pixmap_factory_ozone.h"
#endif

namespace discardable_memory {
class DiscardableSharedMemoryManager;
}

namespace display {
class ScreenManager;
}

namespace service_manager {
class Connector;
class Identity;
}

namespace ui {

class PlatformEventSource;

namespace ws {
class WindowServer;
}

class Service : public service_manager::Service,
                public ws::WindowServerDelegate {
 public:
  Service();
  ~Service() override;

 private:
  // How the ScreenManager is configured.
  enum ScreenManagerConfig {
    // Initial state.
    UNKNOWN,

    // ScreenManager runs locally.
    INTERNAL,

    // Used when the window manager supplies a value of false for
    // |automatically_create_display_roots|. In this config the ScreenManager
    // is configured to forward calls.
    FORWARDING,
  };

  // Holds InterfaceRequests received before the first WindowTreeHost Display
  // has been established.
  struct PendingRequest;
  struct UserState;

  using UserIdToUserState = std::map<ws::UserId, std::unique_ptr<UserState>>;

  // Attempts to initialize the resource bundle. Returns true if successful,
  // otherwise false if resources cannot be loaded.
  bool InitializeResources(service_manager::Connector* connector);

  // Returns the user specific state for the user id of |remote_identity|.
  // Service owns the return value.
  // TODO(sky): if we allow removal of user ids then we need to close anything
  // associated with the user (all incoming pipes...) on removal.
  UserState* GetUserState(const service_manager::Identity& remote_identity);

  void AddUserIfNecessary(const service_manager::Identity& remote_identity);

  // service_manager::Service:
  void OnStart() override;
  void OnBindInterface(const service_manager::BindSourceInfo& source_info,
                       const std::string& interface_name,
                       mojo::ScopedMessagePipeHandle interface_pipe) override;

  // WindowServerDelegate:
  void StartDisplayInit() override;
  void OnFirstDisplayReady() override;
  void OnNoMoreDisplays() override;
  bool IsTestConfig() const override;
  void OnWillCreateTreeForWindowManager(
      bool automatically_create_display_roots) override;

  void BindAccessibilityManagerRequest(
      const service_manager::BindSourceInfo& source_info,
      mojom::AccessibilityManagerRequest request);

  void BindClipboardRequest(const service_manager::BindSourceInfo& source_info,
                            mojom::ClipboardRequest request);

  void BindDisplayManagerRequest(
      const service_manager::BindSourceInfo& source_info,
      mojom::DisplayManagerRequest request);

  void BindGpuRequest(const service_manager::BindSourceInfo& source_info,
                      mojom::GpuRequest request);

  void BindIMERegistrarRequest(
      const service_manager::BindSourceInfo& source_info,
      mojom::IMERegistrarRequest request);

  void BindIMEServerRequest(const service_manager::BindSourceInfo& source_info,
                            mojom::IMEServerRequest request);

  void BindUserAccessManagerRequest(
      const service_manager::BindSourceInfo& source_info,
      mojom::UserAccessManagerRequest request);

  void BindUserActivityMonitorRequest(
      const service_manager::BindSourceInfo& source_info,
      mojom::UserActivityMonitorRequest request);

  void BindWindowManagerWindowTreeFactoryRequest(
      const service_manager::BindSourceInfo& source_info,
      mojom::WindowManagerWindowTreeFactoryRequest request);

  void BindWindowTreeFactoryRequest(
      const service_manager::BindSourceInfo& source_info,
      mojom::WindowTreeFactoryRequest request);

  void BindWindowTreeHostFactoryRequest(
      const service_manager::BindSourceInfo& source_info,
      mojom::WindowTreeHostFactoryRequest request);

  void BindDiscardableSharedMemoryManagerRequest(
      const service_manager::BindSourceInfo& source_info,
      discardable_memory::mojom::DiscardableSharedMemoryManagerRequest request);

  void BindWindowServerTestRequest(
      const service_manager::BindSourceInfo& source_info,
      mojom::WindowServerTestRequest request);

  std::unique_ptr<ws::WindowServer> window_server_;
  std::unique_ptr<ui::PlatformEventSource> event_source_;
  using PendingRequests = std::vector<std::unique_ptr<PendingRequest>>;
  PendingRequests pending_requests_;

  UserIdToUserState user_id_to_user_state_;

  // Provides input-device information via Mojo IPC. Registers Mojo interfaces
  // and must outlive |registry_|.
  InputDeviceServer input_device_server_;

  bool test_config_;
#if defined(USE_OZONE)
  std::unique_ptr<gfx::ClientNativePixmapFactory> client_native_pixmap_factory_;
#endif

  // Manages display hardware and handles display management. May register Mojo
  // interfaces and must outlive |registry_|.
  std::unique_ptr<display::ScreenManager> screen_manager_;

  IMERegistrarImpl ime_registrar_;
  IMEServerImpl ime_server_;

  std::unique_ptr<discardable_memory::DiscardableSharedMemoryManager>
      discardable_shared_memory_manager_;

  service_manager::BinderRegistry registry_;

  // Set to true in StartDisplayInit().
  bool is_gpu_ready_ = false;
  ScreenManagerConfig screen_manager_config_ = ScreenManagerConfig::UNKNOWN;

  DISALLOW_COPY_AND_ASSIGN(Service);
};

}  // namespace ui

#endif  // SERVICES_UI_SERVICE_H_