OLD | NEW |
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 Loading... |
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 DBusThreadManagerSetter; |
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 Loading... |
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 DBusThreadManagerSetter 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<DBusThreadManagerSetter> GetSetterForTesting(); |
92 // interactive_ui_tests) should use this instead of calling | |
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 | 94 |
108 // Returns true if DBusThreadManager has been initialized. Call this to | 95 // Returns true if DBusThreadManager has been initialized. Call this to |
109 // avoid initializing + shutting down DBusThreadManager more than once. | 96 // avoid initializing + shutting down DBusThreadManager more than once. |
110 static bool IsInitialized(); | 97 static bool IsInitialized(); |
111 | 98 |
112 // Destroys the global instance. | 99 // Destroys the global instance. |
113 static void Shutdown(); | 100 static void Shutdown(); |
114 | 101 |
115 // Gets the global instance. Initialize() must be called first. | 102 // Gets the global instance. Initialize() must be called first. |
116 static DBusThreadManager* Get(); | 103 static DBusThreadManager* Get(); |
117 | 104 |
118 // Returns true if |client| is stubbed. | 105 // Returns true if |client| is stubbed. |
119 static bool IsUsingStub(DBusClientBundle::DBusClientType client); | 106 static bool IsUsingStub(DBusClientBundle::DBusClientType client); |
120 | 107 |
121 // Returns various D-Bus bus instances, owned by DBusThreadManager. | 108 // Returns various D-Bus bus instances, owned by DBusThreadManager. |
122 virtual dbus::Bus* GetSystemBus() = 0; | 109 dbus::Bus* GetSystemBus(); |
123 | 110 |
124 // All returned objects are owned by DBusThreadManager. Do not cache these | 111 // All returned objects are owned by DBusThreadManager. Do not cache these |
125 // pointers and use them after DBusThreadManager has been shut down. | 112 // pointers and use them after DBusThreadManager has been shut down. |
126 virtual BluetoothAdapterClient* GetBluetoothAdapterClient() = 0; | 113 BluetoothAdapterClient* GetBluetoothAdapterClient(); |
127 virtual BluetoothAgentManagerClient* GetBluetoothAgentManagerClient() = 0; | 114 BluetoothAgentManagerClient* GetBluetoothAgentManagerClient(); |
128 virtual BluetoothDeviceClient* GetBluetoothDeviceClient() = 0; | 115 BluetoothDeviceClient* GetBluetoothDeviceClient(); |
129 virtual BluetoothGattCharacteristicClient* | 116 BluetoothGattCharacteristicClient* GetBluetoothGattCharacteristicClient(); |
130 GetBluetoothGattCharacteristicClient() = 0; | 117 BluetoothGattDescriptorClient* GetBluetoothGattDescriptorClient(); |
131 virtual BluetoothGattDescriptorClient* GetBluetoothGattDescriptorClient() = 0; | 118 BluetoothGattManagerClient* GetBluetoothGattManagerClient(); |
132 virtual BluetoothGattManagerClient* GetBluetoothGattManagerClient() = 0; | 119 BluetoothGattServiceClient* GetBluetoothGattServiceClient(); |
133 virtual BluetoothGattServiceClient* GetBluetoothGattServiceClient() = 0; | 120 BluetoothInputClient* GetBluetoothInputClient(); |
134 virtual BluetoothInputClient* GetBluetoothInputClient() = 0; | 121 BluetoothProfileManagerClient* GetBluetoothProfileManagerClient(); |
135 virtual BluetoothProfileManagerClient* GetBluetoothProfileManagerClient() = 0; | 122 CrasAudioClient* GetCrasAudioClient(); |
136 virtual CrasAudioClient* GetCrasAudioClient() = 0; | 123 CrosDisksClient* GetCrosDisksClient(); |
137 virtual CrosDisksClient* GetCrosDisksClient() = 0; | 124 CryptohomeClient* GetCryptohomeClient(); |
138 virtual CryptohomeClient* GetCryptohomeClient() = 0; | 125 DebugDaemonClient* GetDebugDaemonClient(); |
139 virtual DebugDaemonClient* GetDebugDaemonClient() = 0; | 126 EasyUnlockClient* GetEasyUnlockClient(); |
140 virtual EasyUnlockClient* GetEasyUnlockClient() = 0; | 127 GsmSMSClient* GetGsmSMSClient(); |
141 virtual GsmSMSClient* GetGsmSMSClient() = 0; | 128 ImageBurnerClient* GetImageBurnerClient(); |
142 virtual ImageBurnerClient* GetImageBurnerClient() = 0; | 129 IntrospectableClient* GetIntrospectableClient(); |
143 virtual IntrospectableClient* GetIntrospectableClient() = 0; | 130 LorgnetteManagerClient* GetLorgnetteManagerClient(); |
144 virtual LorgnetteManagerClient* GetLorgnetteManagerClient() = 0; | 131 ModemMessagingClient* GetModemMessagingClient(); |
145 virtual ModemMessagingClient* GetModemMessagingClient() = 0; | 132 NfcAdapterClient* GetNfcAdapterClient(); |
146 virtual NfcAdapterClient* GetNfcAdapterClient() = 0; | 133 NfcDeviceClient* GetNfcDeviceClient(); |
147 virtual NfcDeviceClient* GetNfcDeviceClient() = 0; | 134 NfcManagerClient* GetNfcManagerClient(); |
148 virtual NfcManagerClient* GetNfcManagerClient() = 0; | 135 NfcRecordClient* GetNfcRecordClient(); |
149 virtual NfcRecordClient* GetNfcRecordClient() = 0; | 136 NfcTagClient* GetNfcTagClient(); |
150 virtual NfcTagClient* GetNfcTagClient() = 0; | 137 PermissionBrokerClient* GetPermissionBrokerClient(); |
151 virtual PermissionBrokerClient* GetPermissionBrokerClient() = 0; | 138 PowerManagerClient* GetPowerManagerClient(); |
152 virtual PowerManagerClient* GetPowerManagerClient() = 0; | 139 PowerPolicyController* GetPowerPolicyController(); |
153 virtual PowerPolicyController* GetPowerPolicyController() = 0; | 140 SessionManagerClient* GetSessionManagerClient(); |
154 virtual SessionManagerClient* GetSessionManagerClient() = 0; | 141 ShillDeviceClient* GetShillDeviceClient(); |
155 virtual ShillDeviceClient* GetShillDeviceClient() = 0; | 142 ShillIPConfigClient* GetShillIPConfigClient(); |
156 virtual ShillIPConfigClient* GetShillIPConfigClient() = 0; | 143 ShillManagerClient* GetShillManagerClient(); |
157 virtual ShillManagerClient* GetShillManagerClient() = 0; | 144 ShillServiceClient* GetShillServiceClient(); |
158 virtual ShillServiceClient* GetShillServiceClient() = 0; | 145 ShillProfileClient* GetShillProfileClient(); |
159 virtual ShillProfileClient* GetShillProfileClient() = 0; | 146 SMSClient* GetSMSClient(); |
160 virtual SMSClient* GetSMSClient() = 0; | 147 SystemClockClient* GetSystemClockClient(); |
161 virtual SystemClockClient* GetSystemClockClient() = 0; | 148 UpdateEngineClient* GetUpdateEngineClient(); |
162 virtual UpdateEngineClient* GetUpdateEngineClient() = 0; | |
163 | |
164 virtual ~DBusThreadManager(); | |
165 | |
166 protected: | |
167 DBusThreadManager(); | |
168 | 149 |
169 private: | 150 private: |
| 151 friend class DBusThreadManagerSetter; |
| 152 |
| 153 DBusThreadManager(); |
| 154 ~DBusThreadManager(); |
| 155 |
| 156 // Creates a global instance of DBusThreadManager. Can not be called more |
| 157 // than once. |
| 158 static void CreateGlobalInstance(); |
| 159 |
170 // Initialize global thread manager instance. | 160 // Initialize global thread manager instance. |
171 static void InitializeRegular(); | 161 static void InitializeRegular(); |
172 | 162 |
| 163 // Initialize global thread manager instance with stubbed-out dbus clients |
| 164 // implementation. |
| 165 static void InitializeWithStubs(); |
| 166 |
173 // Initialize with stub implementations for only certain clients that are | 167 // Initialize with stub implementations for only certain clients that are |
174 // not included in comma-separated |unstub_clients| list. | 168 // not included in comma-separated |unstub_clients| list. |
175 static void InitializeWithPartialStub(const std::string& unstub_clients); | 169 static void InitializeWithPartialStub(const std::string& unstub_clients); |
176 | 170 |
177 // InitializeClients is called after g_dbus_thread_manager is set. | 171 // Constructs all clients and stores them in the respective *_client_ member |
178 // NOTE: Clients that access other clients in their Init() must be | 172 // variable. |
179 // initialized in the correct order. | 173 void CreateDefaultClients(); |
180 static void InitializeClients(); | |
181 | 174 |
182 // Initializes |client| with the |system_bus_|. | 175 // Constructs all clients and stores them in the respective *_client_ member |
183 static void InitClient(DBusClient* client); | 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 DBusThreadManagerSetter { |
| 192 public: |
| 193 ~DBusThreadManagerSetter(); |
| 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 DBusThreadManagerSetter(); |
| 242 |
| 243 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerSetter); |
| 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_ |
OLD | NEW |