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

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

Issue 477663004: Merged FakedDBusThreadManager with DBusThreadManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
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 "base/callback.h" 8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 18 matching lines...) Expand all
29 class BluetoothGattCharacteristicClient; 29 class BluetoothGattCharacteristicClient;
30 class BluetoothGattDescriptorClient; 30 class BluetoothGattDescriptorClient;
31 class BluetoothGattManagerClient; 31 class BluetoothGattManagerClient;
32 class BluetoothGattServiceClient; 32 class BluetoothGattServiceClient;
33 class BluetoothInputClient; 33 class BluetoothInputClient;
34 class BluetoothProfileManagerClient; 34 class BluetoothProfileManagerClient;
35 class CrasAudioClient; 35 class CrasAudioClient;
36 class CrosDisksClient; 36 class CrosDisksClient;
37 class CryptohomeClient; 37 class CryptohomeClient;
38 class DBusClient; 38 class DBusClient;
39 class DBusThreadManager;
40 class DBusThreadManagerTestHelper;
39 class DebugDaemonClient; 41 class DebugDaemonClient;
40 class EasyUnlockClient; 42 class EasyUnlockClient;
41 class GsmSMSClient; 43 class GsmSMSClient;
42 class ImageBurnerClient; 44 class ImageBurnerClient;
43 class IntrospectableClient; 45 class IntrospectableClient;
44 class LorgnetteManagerClient; 46 class LorgnetteManagerClient;
45 class ModemMessagingClient; 47 class ModemMessagingClient;
46 class NfcAdapterClient; 48 class NfcAdapterClient;
47 class NfcDeviceClient; 49 class NfcDeviceClient;
48 class NfcManagerClient; 50 class NfcManagerClient;
(...skipping 30 matching lines...) Expand all
79 // WeakPtrFactory when creating callbacks that run on UI thread. See 81 // WeakPtrFactory when creating callbacks that run on UI thread. See
80 // session_manager_client.cc for examples. 82 // session_manager_client.cc for examples.
81 // 83 //
82 class CHROMEOS_EXPORT DBusThreadManager { 84 class CHROMEOS_EXPORT DBusThreadManager {
83 public: 85 public:
84 // Sets the global instance. Must be called before any calls to Get(). 86 // Sets the global instance. Must be called before any calls to Get().
85 // We explicitly initialize and shut down the global object, rather than 87 // We explicitly initialize and shut down the global object, rather than
86 // making it a Singleton, to ensure clean startup and shutdown. 88 // making it a Singleton, to ensure clean startup and shutdown.
87 static void Initialize(); 89 static void Initialize();
88 90
89 // Sets an alternative DBusThreadManager such as MockDBusThreadManager 91 // Returns DBusThreadManagerTestHelper instance that allows tests to
90 // to be used in |Initialize()| for testing. Tests that call 92 // replace individual dbus clients with their own implementations.
91 // DBusThreadManager::Initialize() (such as browser_tests and 93 static scoped_ptr<DBusThreadManagerTestHelper>
92 // interactive_ui_tests) should use this instead of calling 94 GetDBusThreadManagerTestHelper();
93 // |InitiailzeForTesting|. The injected object will be owned by the
94 // internal pointer and deleted by Shutdown().
95 static void SetInstanceForTesting(DBusThreadManager* dbus_thread_manager);
96
97 // Similar to Initialize(), but injects an alternative
98 // DBusThreadManager using SetInstanceForTest first. The injected
99 // object will be owned by the internal pointer and deleted by
100 // Shutdown(). Does not create any Fake client implementations.
101 static void InitializeForTesting(DBusThreadManager* dbus_thread_manager);
102
103 // Initialize with stub implementations for tests, creating a complete set
104 // of fake/stub client implementations. Also initializes a default set of
105 // fake Shill devices and services, customizable with switches::kShillStub.
106 static void InitializeWithStub();
107 95
108 // Returns true if DBusThreadManager has been initialized. Call this to 96 // Returns true if DBusThreadManager has been initialized. Call this to
109 // avoid initializing + shutting down DBusThreadManager more than once. 97 // avoid initializing + shutting down DBusThreadManager more than once.
110 static bool IsInitialized(); 98 static bool IsInitialized();
111 99
112 // Destroys the global instance. 100 // Destroys the global instance.
113 static void Shutdown(); 101 static void Shutdown();
114 102
115 // Gets the global instance. Initialize() must be called first. 103 // Gets the global instance. Initialize() must be called first.
116 static DBusThreadManager* Get(); 104 static DBusThreadManager* Get();
117 105
118 // Returns true if |client| is stubbed. 106 // Returns true if |client| is stubbed.
119 static bool IsUsingStub(DBusClientBundle::DBusClientType client); 107 static bool IsUsingStub(DBusClientBundle::DBusClientType client);
120 108
121 // Returns various D-Bus bus instances, owned by DBusThreadManager. 109 // Returns various D-Bus bus instances, owned by DBusThreadManager.
122 virtual dbus::Bus* GetSystemBus() = 0; 110 dbus::Bus* GetSystemBus();
123 111
124 // All returned objects are owned by DBusThreadManager. Do not cache these 112 // All returned objects are owned by DBusThreadManager. Do not cache these
125 // pointers and use them after DBusThreadManager has been shut down. 113 // pointers and use them after DBusThreadManager has been shut down.
126 virtual BluetoothAdapterClient* GetBluetoothAdapterClient() = 0; 114 BluetoothAdapterClient* GetBluetoothAdapterClient();
127 virtual BluetoothAgentManagerClient* GetBluetoothAgentManagerClient() = 0; 115 BluetoothAgentManagerClient* GetBluetoothAgentManagerClient();
128 virtual BluetoothDeviceClient* GetBluetoothDeviceClient() = 0; 116 BluetoothDeviceClient* GetBluetoothDeviceClient();
129 virtual BluetoothGattCharacteristicClient* 117 BluetoothGattCharacteristicClient* GetBluetoothGattCharacteristicClient();
130 GetBluetoothGattCharacteristicClient() = 0; 118 BluetoothGattDescriptorClient* GetBluetoothGattDescriptorClient();
131 virtual BluetoothGattDescriptorClient* GetBluetoothGattDescriptorClient() = 0; 119 BluetoothGattManagerClient* GetBluetoothGattManagerClient();
132 virtual BluetoothGattManagerClient* GetBluetoothGattManagerClient() = 0; 120 BluetoothGattServiceClient* GetBluetoothGattServiceClient();
133 virtual BluetoothGattServiceClient* GetBluetoothGattServiceClient() = 0; 121 BluetoothInputClient* GetBluetoothInputClient();
134 virtual BluetoothInputClient* GetBluetoothInputClient() = 0; 122 BluetoothProfileManagerClient* GetBluetoothProfileManagerClient();
135 virtual BluetoothProfileManagerClient* GetBluetoothProfileManagerClient() = 0; 123 CrasAudioClient* GetCrasAudioClient();
136 virtual CrasAudioClient* GetCrasAudioClient() = 0; 124 CrosDisksClient* GetCrosDisksClient();
137 virtual CrosDisksClient* GetCrosDisksClient() = 0; 125 CryptohomeClient* GetCryptohomeClient();
138 virtual CryptohomeClient* GetCryptohomeClient() = 0; 126 DebugDaemonClient* GetDebugDaemonClient();
139 virtual DebugDaemonClient* GetDebugDaemonClient() = 0; 127 EasyUnlockClient* GetEasyUnlockClient();
140 virtual EasyUnlockClient* GetEasyUnlockClient() = 0; 128 GsmSMSClient* GetGsmSMSClient();
141 virtual GsmSMSClient* GetGsmSMSClient() = 0; 129 ImageBurnerClient* GetImageBurnerClient();
142 virtual ImageBurnerClient* GetImageBurnerClient() = 0; 130 IntrospectableClient* GetIntrospectableClient();
143 virtual IntrospectableClient* GetIntrospectableClient() = 0; 131 LorgnetteManagerClient* GetLorgnetteManagerClient();
144 virtual LorgnetteManagerClient* GetLorgnetteManagerClient() = 0; 132 ModemMessagingClient* GetModemMessagingClient();
145 virtual ModemMessagingClient* GetModemMessagingClient() = 0; 133 NfcAdapterClient* GetNfcAdapterClient();
146 virtual NfcAdapterClient* GetNfcAdapterClient() = 0; 134 NfcDeviceClient* GetNfcDeviceClient();
147 virtual NfcDeviceClient* GetNfcDeviceClient() = 0; 135 NfcManagerClient* GetNfcManagerClient();
148 virtual NfcManagerClient* GetNfcManagerClient() = 0; 136 NfcRecordClient* GetNfcRecordClient();
149 virtual NfcRecordClient* GetNfcRecordClient() = 0; 137 NfcTagClient* GetNfcTagClient();
150 virtual NfcTagClient* GetNfcTagClient() = 0; 138 PermissionBrokerClient* GetPermissionBrokerClient();
151 virtual PermissionBrokerClient* GetPermissionBrokerClient() = 0; 139 PowerManagerClient* GetPowerManagerClient();
152 virtual PowerManagerClient* GetPowerManagerClient() = 0; 140 PowerPolicyController* GetPowerPolicyController();
153 virtual PowerPolicyController* GetPowerPolicyController() = 0; 141 SessionManagerClient* GetSessionManagerClient();
154 virtual SessionManagerClient* GetSessionManagerClient() = 0; 142 ShillDeviceClient* GetShillDeviceClient();
155 virtual ShillDeviceClient* GetShillDeviceClient() = 0; 143 ShillIPConfigClient* GetShillIPConfigClient();
156 virtual ShillIPConfigClient* GetShillIPConfigClient() = 0; 144 ShillManagerClient* GetShillManagerClient();
157 virtual ShillManagerClient* GetShillManagerClient() = 0; 145 ShillServiceClient* GetShillServiceClient();
158 virtual ShillServiceClient* GetShillServiceClient() = 0; 146 ShillProfileClient* GetShillProfileClient();
159 virtual ShillProfileClient* GetShillProfileClient() = 0; 147 SMSClient* GetSMSClient();
160 virtual SMSClient* GetSMSClient() = 0; 148 SystemClockClient* GetSystemClockClient();
161 virtual SystemClockClient* GetSystemClockClient() = 0; 149 UpdateEngineClient* GetUpdateEngineClient();
162 virtual UpdateEngineClient* GetUpdateEngineClient() = 0;
163
164 virtual ~DBusThreadManager();
165
166 protected:
167 DBusThreadManager();
168 150
169 private: 151 private:
152 friend class DBusThreadManagerTestHelper;
153
154 DBusThreadManager();
155 ~DBusThreadManager();
156
170 // Initialize global thread manager instance. 157 // Initialize global thread manager instance.
171 static void InitializeRegular(); 158 static void InitializeRegular();
172 159
160 // Initialize global thread manager instance for testing which has stubbed-out
161 // dbus client implementations.
162 static void InitializeForTesting();
163
173 // Initialize with stub implementations for only certain clients that are 164 // Initialize with stub implementations for only certain clients that are
174 // not included in comma-separated |unstub_clients| list. 165 // not included in comma-separated |unstub_clients| list.
175 static void InitializeWithPartialStub(const std::string& unstub_clients); 166 static void InitializeWithPartialStub(const std::string& unstub_clients);
176 167
177 // InitializeClients is called after g_dbus_thread_manager is set. 168 // Creates instance of DBusThreadManager.
178 // NOTE: Clients that access other clients in their Init() must be 169 static DBusThreadManager* CreateInstance();
179 // initialized in the correct order.
180 static void InitializeClients();
181 170
182 // Initializes |client| with the |system_bus_|. 171 // Constructs all clients and stores them in the respective *_client_ member
183 static void InitClient(DBusClient* client); 172 // variable.
173 void CreateDefaultClients();
174
175 // Constructs all clients and stores them in the respective *_client_ member
176 // variable.
177 void InitializeClients();
184 178
185 // Bitmask that defines which dbus clients are not stubbed out. Bitmap flags 179 // Bitmask that defines which dbus clients are not stubbed out. Bitmap flags
186 // are defined within DBusClientBundle::DBusClientType enum. 180 // are defined within DBusClientBundle::DBusClientType enum.
187 static DBusClientBundle::DBusClientTypeMask unstub_client_mask_; 181 static DBusClientBundle::DBusClientTypeMask unstub_client_mask_;
188 182
183 scoped_ptr<base::Thread> dbus_thread_;
184 scoped_refptr<dbus::Bus> system_bus_;
185 scoped_ptr<DBusClientBundle> client_bundle_;
186 scoped_ptr<PowerPolicyController> power_policy_controller_;
187
189 DISALLOW_COPY_AND_ASSIGN(DBusThreadManager); 188 DISALLOW_COPY_AND_ASSIGN(DBusThreadManager);
190 }; 189 };
191 190
191 class CHROMEOS_EXPORT DBusThreadManagerTestHelper {
192 public:
193 ~DBusThreadManagerTestHelper();
194
195 void SetBluetoothAdapterClient(scoped_ptr<BluetoothAdapterClient> client);
196 void SetBluetoothAgentManagerClient(
197 scoped_ptr<BluetoothAgentManagerClient> client);
198 void SetBluetoothDeviceClient(scoped_ptr<BluetoothDeviceClient> client);
199 void SetBluetoothGattCharacteristicClient(
200 scoped_ptr<BluetoothGattCharacteristicClient> client);
201 void SetBluetoothGattDescriptorClient(
202 scoped_ptr<BluetoothGattDescriptorClient> client);
203 void SetBluetoothGattManagerClient(
204 scoped_ptr<BluetoothGattManagerClient> client);
205 void SetBluetoothGattServiceClient(
206 scoped_ptr<BluetoothGattServiceClient> client);
207 void SetBluetoothInputClient(scoped_ptr<BluetoothInputClient> client);
208 void SetBluetoothProfileManagerClient(
209 scoped_ptr<BluetoothProfileManagerClient> client);
210 void SetCrasAudioClient(scoped_ptr<CrasAudioClient> client);
211 void SetCrosDisksClient(scoped_ptr<CrosDisksClient> client);
212 void SetCryptohomeClient(scoped_ptr<CryptohomeClient> client);
213 void SetDebugDaemonClient(scoped_ptr<DebugDaemonClient> client);
214 void SetEasyUnlockClient(scoped_ptr<EasyUnlockClient> client);
215 void SetLorgnetteManagerClient(scoped_ptr<LorgnetteManagerClient> client);
216 void SetShillDeviceClient(scoped_ptr<ShillDeviceClient> client);
217 void SetShillIPConfigClient(scoped_ptr<ShillIPConfigClient> client);
218 void SetShillManagerClient(scoped_ptr<ShillManagerClient> client);
219 void SetShillServiceClient(scoped_ptr<ShillServiceClient> client);
220 void SetShillProfileClient(scoped_ptr<ShillProfileClient> client);
221 void SetGsmSMSClient(scoped_ptr<GsmSMSClient> client);
222 void SetImageBurnerClient(scoped_ptr<ImageBurnerClient> client);
223 void SetIntrospectableClient(scoped_ptr<IntrospectableClient> client);
224 void SetModemMessagingClient(scoped_ptr<ModemMessagingClient> client);
225 void SetNfcAdapterClient(scoped_ptr<NfcAdapterClient> client);
226 void SetNfcDeviceClient(scoped_ptr<NfcDeviceClient> client);
227 void SetNfcManagerClient(scoped_ptr<NfcManagerClient> client);
228 void SetNfcRecordClient(scoped_ptr<NfcRecordClient> client);
229 void SetNfcTagClient(scoped_ptr<NfcTagClient> client);
230 void SetPermissionBrokerClient(scoped_ptr<PermissionBrokerClient> client);
231 void SetPowerManagerClient(scoped_ptr<PowerManagerClient> client);
232 void SetPowerPolicyController(scoped_ptr<PowerPolicyController> client);
233 void SetSessionManagerClient(scoped_ptr<SessionManagerClient> client);
234 void SetSMSClient(scoped_ptr<SMSClient> client);
235 void SetSystemClockClient(scoped_ptr<SystemClockClient> client);
236 void SetUpdateEngineClient(scoped_ptr<UpdateEngineClient> client);
237
238 private:
239 friend class DBusThreadManager;
240
241 DBusThreadManagerTestHelper();
242
243 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerTestHelper);
244 };
245
192 } // namespace chromeos 246 } // namespace chromeos
193 247
194 #endif // CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ 248 #endif // CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698