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

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

Powered by Google App Engine
This is Rietveld 408576698