Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Side by Side Diff: chromeos/dbus/dbus_thread_manager.h

Issue 2343993003: chromeos: Refactor D-Bus client creation for ash and browser processes (Closed)
Patch Set: cleanup, extend tests Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ 5 #ifndef CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_
6 #define CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ 6 #define CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
(...skipping 12 matching lines...) Expand all
23 class ObjectPath; 23 class ObjectPath;
24 } // namespace dbus 24 } // namespace dbus
25 25
26 namespace chromeos { 26 namespace chromeos {
27 27
28 // Style Note: Clients are sorted by names. 28 // Style Note: Clients are sorted by names.
29 class ArcObbMounterClient; 29 class ArcObbMounterClient;
30 class CrasAudioClient; 30 class CrasAudioClient;
31 class CrosDisksClient; 31 class CrosDisksClient;
32 class CryptohomeClient; 32 class CryptohomeClient;
33 class DBusClientBundle; 33 class DBusClientsAsh;
34 class DBusClientsBrowser;
35 class DBusClientsCommon;
34 class DBusThreadManagerSetter; 36 class DBusThreadManagerSetter;
35 class DebugDaemonClient; 37 class DebugDaemonClient;
36 class EasyUnlockClient; 38 class EasyUnlockClient;
37 class GsmSMSClient; 39 class GsmSMSClient;
38 class ImageBurnerClient; 40 class ImageBurnerClient;
39 class LorgnetteManagerClient; 41 class LorgnetteManagerClient;
40 class ModemMessagingClient; 42 class ModemMessagingClient;
41 class PermissionBrokerClient; 43 class PermissionBrokerClient;
42 class PowerManagerClient; 44 class PowerManagerClient;
43 class SMSClient; 45 class SMSClient;
(...skipping 20 matching lines...) Expand all
64 // after the D-Bus thread so the clients don't need to worry if new 66 // after the D-Bus thread so the clients don't need to worry if new
65 // incoming messages arrive from the D-Bus thread during shutdown of the 67 // incoming messages arrive from the D-Bus thread during shutdown of the
66 // clients. The UI message loop is not running during the shutdown hence 68 // clients. The UI message loop is not running during the shutdown hence
67 // the UI message loop won't post tasks to D-BUS clients during the 69 // the UI message loop won't post tasks to D-BUS clients during the
68 // shutdown. However, to be extra cautious, clients should use 70 // shutdown. However, to be extra cautious, clients should use
69 // WeakPtrFactory when creating callbacks that run on UI thread. See 71 // WeakPtrFactory when creating callbacks that run on UI thread. See
70 // session_manager_client.cc for examples. 72 // session_manager_client.cc for examples.
71 // 73 //
72 class CHROMEOS_EXPORT DBusThreadManager { 74 class CHROMEOS_EXPORT DBusThreadManager {
73 public: 75 public:
76 // Processes for which to create and initialize the D-Bus clients.
77 // TODO(jamescook): Move creation of clients into //ash and //chrome/browser.
78 // http://crbug.com/647367
79 enum ProcessMask {
80 PROCESS_ASH = 1 << 0,
81 PROCESS_BROWSER = 1 << 1,
82 PROCESS_ALL = ~0,
83 };
74 // Sets the global instance. Must be called before any calls to Get(). 84 // Sets the global instance. Must be called before any calls to Get().
75 // We explicitly initialize and shut down the global object, rather than 85 // We explicitly initialize and shut down the global object, rather than
76 // making it a Singleton, to ensure clean startup and shutdown. 86 // making it a Singleton, to ensure clean startup and shutdown.
77 // This will initialize real or fake DBusClients depending on command-line 87 // This will initialize real or fake DBusClients depending on command-line
78 // arguments and whether this process runs in a ChromeOS environment. 88 // arguments and whether this process runs in a ChromeOS environment.
89 // Only D-Bus clients available in the processes in |process_mask| will be
90 // created.
91 static void Initialize(ProcessMask process_mask);
92
93 // Equivalent to Initialize(PROCESS_ALL).
79 static void Initialize(); 94 static void Initialize();
80 95
81 // Returns a DBusThreadManagerSetter instance that allows tests to 96 // Returns a DBusThreadManagerSetter instance that allows tests to
82 // replace individual D-Bus clients with their own implementations. 97 // replace individual D-Bus clients with their own implementations.
83 // Also initializes the main DBusThreadManager for testing if necessary. 98 // Also initializes the main DBusThreadManager for testing if necessary.
84 static std::unique_ptr<DBusThreadManagerSetter> GetSetterForTesting(); 99 static std::unique_ptr<DBusThreadManagerSetter> GetSetterForTesting();
85 100
86 // Returns true if DBusThreadManager has been initialized. Call this to 101 // Returns true if DBusThreadManager has been initialized. Call this to
87 // avoid initializing + shutting down DBusThreadManager more than once. 102 // avoid initializing + shutting down DBusThreadManager more than once.
88 static bool IsInitialized(); 103 static bool IsInitialized();
89 104
90 // Destroys the global instance. 105 // Destroys the global instance.
91 static void Shutdown(); 106 static void Shutdown();
92 107
93 // Gets the global instance. Initialize() must be called first. 108 // Gets the global instance. Initialize() must be called first.
94 static DBusThreadManager* Get(); 109 static DBusThreadManager* Get();
95 110
96 // Returns true if |client| is faked. 111 // Returns true if |client| is faked.
97 bool IsUsingFake(DBusClientType client); 112 bool IsUsingFake(DBusClientType client);
98 113
99 // Returns various D-Bus bus instances, owned by DBusThreadManager. 114 // Returns various D-Bus bus instances, owned by DBusThreadManager.
100 dbus::Bus* GetSystemBus(); 115 dbus::Bus* GetSystemBus();
101 116
102 // All returned objects are owned by DBusThreadManager. Do not use these 117 // All returned objects are owned by DBusThreadManager. Do not use these
103 // pointers after DBusThreadManager has been shut down. 118 // pointers after DBusThreadManager has been shut down.
119 // TODO(jamescook): Replace this with calls to FooClient::Get().
120 // http://crbug.com/647367
104 ArcObbMounterClient* GetArcObbMounterClient(); 121 ArcObbMounterClient* GetArcObbMounterClient();
105 CrasAudioClient* GetCrasAudioClient(); 122 CrasAudioClient* GetCrasAudioClient();
106 CrosDisksClient* GetCrosDisksClient(); 123 CrosDisksClient* GetCrosDisksClient();
107 CryptohomeClient* GetCryptohomeClient(); 124 CryptohomeClient* GetCryptohomeClient();
108 DebugDaemonClient* GetDebugDaemonClient(); 125 DebugDaemonClient* GetDebugDaemonClient();
109 EasyUnlockClient* GetEasyUnlockClient(); 126 EasyUnlockClient* GetEasyUnlockClient();
110 GsmSMSClient* GetGsmSMSClient(); 127 GsmSMSClient* GetGsmSMSClient();
111 ImageBurnerClient* GetImageBurnerClient(); 128 ImageBurnerClient* GetImageBurnerClient();
112 LorgnetteManagerClient* GetLorgnetteManagerClient(); 129 LorgnetteManagerClient* GetLorgnetteManagerClient();
113 ModemMessagingClient* GetModemMessagingClient(); 130 ModemMessagingClient* GetModemMessagingClient();
114 PermissionBrokerClient* GetPermissionBrokerClient(); 131 PermissionBrokerClient* GetPermissionBrokerClient();
115 PowerManagerClient* GetPowerManagerClient(); 132 PowerManagerClient* GetPowerManagerClient();
116 SessionManagerClient* GetSessionManagerClient(); 133 SessionManagerClient* GetSessionManagerClient();
117 ShillDeviceClient* GetShillDeviceClient(); 134 ShillDeviceClient* GetShillDeviceClient();
118 ShillIPConfigClient* GetShillIPConfigClient(); 135 ShillIPConfigClient* GetShillIPConfigClient();
119 ShillManagerClient* GetShillManagerClient(); 136 ShillManagerClient* GetShillManagerClient();
120 ShillServiceClient* GetShillServiceClient(); 137 ShillServiceClient* GetShillServiceClient();
121 ShillProfileClient* GetShillProfileClient(); 138 ShillProfileClient* GetShillProfileClient();
122 ShillThirdPartyVpnDriverClient* GetShillThirdPartyVpnDriverClient(); 139 ShillThirdPartyVpnDriverClient* GetShillThirdPartyVpnDriverClient();
123 SMSClient* GetSMSClient(); 140 SMSClient* GetSMSClient();
124 SystemClockClient* GetSystemClockClient(); 141 SystemClockClient* GetSystemClockClient();
125 UpdateEngineClient* GetUpdateEngineClient(); 142 UpdateEngineClient* GetUpdateEngineClient();
126 143
127 private: 144 private:
128 friend class DBusThreadManagerSetter; 145 friend class DBusThreadManagerSetter;
129 146
130 // Creates a new DBusThreadManager using the DBusClients set in 147 DBusThreadManager(ProcessMask process_mask,
131 // |client_bundle|. 148 DBusClientTypeMask real_client_mask);
132 explicit DBusThreadManager(std::unique_ptr<DBusClientBundle> client_bundle);
133 ~DBusThreadManager(); 149 ~DBusThreadManager();
134 150
135 // Creates a global instance of DBusThreadManager with the real 151 // Creates a global instance of DBusThreadManager with the real
136 // implementations for all clients that are listed in |real_client_mask| and 152 // implementations for all clients that are listed in |real_client_mask| and
137 // fake implementations for all clients that are not included. Cannot be 153 // fake implementations for all clients that are not included. Cannot be
138 // called more than once. 154 // called more than once.
139 static void CreateGlobalInstance(DBusClientTypeMask real_client_mask); 155 static void CreateGlobalInstance(ProcessMask process_mask,
156 DBusClientTypeMask real_client_mask);
140 157
141 // Initialize global thread manager instance with all real dbus client 158 // Initialize global thread manager instance with all real dbus client
142 // implementations. 159 // implementations.
143 static void InitializeWithRealClients(); 160 static void InitializeWithRealClients(ProcessMask process_mask);
144 161
145 // Initialize global thread manager instance with fake dbus clients. 162 // Initialize global thread manager instance with fake dbus clients.
146 static void InitializeWithFakeClients(); 163 static void InitializeWithFakeClients(ProcessMask process_mask);
147 164
148 // Initialize with fake implementations for only certain clients that are 165 // Initialize with fake implementations for only certain clients that are
149 // not included in the comma-separated |force_real_clients| list. 166 // not included in the comma-separated |force_real_clients| list.
150 static void InitializeWithPartialFakes(const std::string& force_real_clients); 167 static void InitializeWithPartialFakes(ProcessMask process_mask,
168 const std::string& force_real_clients);
151 169
152 // Initializes all currently stored DBusClients with the system bus and 170 // Initializes all currently stored DBusClients with the system bus and
153 // performs additional setup. 171 // performs additional setup.
154 void InitializeClients(); 172 void InitializeClients();
155 173
156 std::unique_ptr<base::Thread> dbus_thread_; 174 std::unique_ptr<base::Thread> dbus_thread_;
157 scoped_refptr<dbus::Bus> system_bus_; 175 scoped_refptr<dbus::Bus> system_bus_;
158 std::unique_ptr<DBusClientBundle> client_bundle_; 176
177 // Clients used by multiple processes.
178 std::unique_ptr<DBusClientsCommon> clients_common_;
179
180 // Clients used by the browser process. Null in other processes.
181 std::unique_ptr<DBusClientsBrowser> clients_browser_;
182
183 // Clients used by the ash window manager process. Null in other processes.
184 std::unique_ptr<DBusClientsAsh> clients_ash_;
159 185
160 DISALLOW_COPY_AND_ASSIGN(DBusThreadManager); 186 DISALLOW_COPY_AND_ASSIGN(DBusThreadManager);
161 }; 187 };
162 188
189 // TODO(jamescook): Replace these with FooClient::InitializeForTesting().
163 class CHROMEOS_EXPORT DBusThreadManagerSetter { 190 class CHROMEOS_EXPORT DBusThreadManagerSetter {
164 public: 191 public:
165 ~DBusThreadManagerSetter(); 192 ~DBusThreadManagerSetter();
166 193
167 void SetCrasAudioClient(std::unique_ptr<CrasAudioClient> client); 194 void SetCrasAudioClient(std::unique_ptr<CrasAudioClient> client);
168 void SetCrosDisksClient(std::unique_ptr<CrosDisksClient> client); 195 void SetCrosDisksClient(std::unique_ptr<CrosDisksClient> client);
169 void SetCryptohomeClient(std::unique_ptr<CryptohomeClient> client); 196 void SetCryptohomeClient(std::unique_ptr<CryptohomeClient> client);
170 void SetDebugDaemonClient(std::unique_ptr<DebugDaemonClient> client); 197 void SetDebugDaemonClient(std::unique_ptr<DebugDaemonClient> client);
171 void SetEasyUnlockClient(std::unique_ptr<EasyUnlockClient> client);
172 void SetLorgnetteManagerClient(
173 std::unique_ptr<LorgnetteManagerClient> client);
174 void SetShillDeviceClient(std::unique_ptr<ShillDeviceClient> client); 198 void SetShillDeviceClient(std::unique_ptr<ShillDeviceClient> client);
175 void SetShillIPConfigClient(std::unique_ptr<ShillIPConfigClient> client); 199 void SetShillIPConfigClient(std::unique_ptr<ShillIPConfigClient> client);
176 void SetShillManagerClient(std::unique_ptr<ShillManagerClient> client); 200 void SetShillManagerClient(std::unique_ptr<ShillManagerClient> client);
177 void SetShillServiceClient(std::unique_ptr<ShillServiceClient> client); 201 void SetShillServiceClient(std::unique_ptr<ShillServiceClient> client);
178 void SetShillProfileClient(std::unique_ptr<ShillProfileClient> client); 202 void SetShillProfileClient(std::unique_ptr<ShillProfileClient> client);
179 void SetShillThirdPartyVpnDriverClient( 203 void SetShillThirdPartyVpnDriverClient(
180 std::unique_ptr<ShillThirdPartyVpnDriverClient> client); 204 std::unique_ptr<ShillThirdPartyVpnDriverClient> client);
181 void SetGsmSMSClient(std::unique_ptr<GsmSMSClient> client);
182 void SetImageBurnerClient(std::unique_ptr<ImageBurnerClient> client); 205 void SetImageBurnerClient(std::unique_ptr<ImageBurnerClient> client);
183 void SetModemMessagingClient(std::unique_ptr<ModemMessagingClient> client);
184 void SetPermissionBrokerClient( 206 void SetPermissionBrokerClient(
185 std::unique_ptr<PermissionBrokerClient> client); 207 std::unique_ptr<PermissionBrokerClient> client);
186 void SetPowerManagerClient(std::unique_ptr<PowerManagerClient> client); 208 void SetPowerManagerClient(std::unique_ptr<PowerManagerClient> client);
187 void SetSessionManagerClient(std::unique_ptr<SessionManagerClient> client); 209 void SetSessionManagerClient(std::unique_ptr<SessionManagerClient> client);
188 void SetSMSClient(std::unique_ptr<SMSClient> client);
189 void SetSystemClockClient(std::unique_ptr<SystemClockClient> client);
190 void SetUpdateEngineClient(std::unique_ptr<UpdateEngineClient> client); 210 void SetUpdateEngineClient(std::unique_ptr<UpdateEngineClient> client);
191 211
192 private: 212 private:
193 friend class DBusThreadManager; 213 friend class DBusThreadManager;
194 214
195 DBusThreadManagerSetter(); 215 DBusThreadManagerSetter();
196 216
197 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerSetter); 217 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerSetter);
198 }; 218 };
199 219
200 } // namespace chromeos 220 } // namespace chromeos
201 221
202 #endif // CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ 222 #endif // CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698