Chromium Code Reviews| 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 DBusThreadManagerImpl; | |
| 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; |
| 49 class NfcRecordClient; | 51 class NfcRecordClient; |
| 50 class NfcTagClient; | 52 class NfcTagClient; |
| 51 class PermissionBrokerClient; | 53 class PermissionBrokerClient; |
| 52 class PowerManagerClient; | 54 class PowerManagerClient; |
| 53 class PowerPolicyController; | 55 class PowerPolicyController; |
| 54 class SessionManagerClient; | 56 class SessionManagerClient; |
| 55 class ShillDeviceClient; | 57 class ShillDeviceClient; |
| 56 class ShillIPConfigClient; | 58 class ShillIPConfigClient; |
| 57 class ShillManagerClient; | 59 class ShillManagerClient; |
| 58 class ShillProfileClient; | 60 class ShillProfileClient; |
| 59 class ShillServiceClient; | 61 class ShillServiceClient; |
| 60 class SMSClient; | 62 class SMSClient; |
| 61 class SystemClockClient; | 63 class SystemClockClient; |
| 62 class UpdateEngineClient; | 64 class UpdateEngineClient; |
|
hashimoto
2014/08/18 04:55:58
nit: Please keep a blank line here.
zel
2014/08/18 23:41:52
Done.
| |
| 63 | |
| 64 // DBusThreadManager manages the D-Bus thread, the thread dedicated to | 65 // DBusThreadManager manages the D-Bus thread, the thread dedicated to |
| 65 // handling asynchronous D-Bus operations. | 66 // handling asynchronous D-Bus operations. |
| 66 // | 67 // |
| 67 // This class also manages D-Bus connections and D-Bus clients, which | 68 // This class also manages D-Bus connections and D-Bus clients, which |
| 68 // depend on the D-Bus thread to ensure the right order of shutdowns for | 69 // depend on the D-Bus thread to ensure the right order of shutdowns for |
| 69 // the D-Bus thread, the D-Bus connections, and the D-Bus clients. | 70 // the D-Bus thread, the D-Bus connections, and the D-Bus clients. |
| 70 // | 71 // |
| 71 // CALLBACKS IN D-BUS CLIENTS: | 72 // CALLBACKS IN D-BUS CLIENTS: |
| 72 // | 73 // |
| 73 // D-Bus clients managed by DBusThreadManager are guaranteed to be deleted | 74 // D-Bus clients managed by DBusThreadManager are guaranteed to be deleted |
| 74 // after the D-Bus thread so the clients don't need to worry if new | 75 // after the D-Bus thread so the clients don't need to worry if new |
| 75 // incoming messages arrive from the D-Bus thread during shutdown of the | 76 // incoming messages arrive from the D-Bus thread during shutdown of the |
| 76 // clients. The UI message loop is not running during the shutdown hence | 77 // clients. The UI message loop is not running during the shutdown hence |
| 77 // the UI message loop won't post tasks to D-BUS clients during the | 78 // the UI message loop won't post tasks to D-BUS clients during the |
| 78 // shutdown. However, to be extra cautious, clients should use | 79 // shutdown. However, to be extra cautious, clients should use |
| 79 // WeakPtrFactory when creating callbacks that run on UI thread. See | 80 // WeakPtrFactory when creating callbacks that run on UI thread. See |
| 80 // session_manager_client.cc for examples. | 81 // session_manager_client.cc for examples. |
| 81 // | 82 // |
| 82 class CHROMEOS_EXPORT DBusThreadManager { | 83 class CHROMEOS_EXPORT DBusThreadManager { |
| 83 public: | 84 public: |
| 84 // Sets the global instance. Must be called before any calls to Get(). | 85 // Sets the global instance. Must be called before any calls to Get(). |
| 85 // We explicitly initialize and shut down the global object, rather than | 86 // We explicitly initialize and shut down the global object, rather than |
| 86 // making it a Singleton, to ensure clean startup and shutdown. | 87 // making it a Singleton, to ensure clean startup and shutdown. |
| 87 static void Initialize(); | 88 static void Initialize(); |
| 88 | 89 |
| 89 // Sets an alternative DBusThreadManager such as MockDBusThreadManager | |
| 90 // to be used in |Initialize()| for testing. Tests that call | |
| 91 // DBusThreadManager::Initialize() (such as browser_tests and | |
| 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 | 90 // Initialize with stub implementations for tests, creating a complete set |
| 104 // of fake/stub client implementations. Also initializes a default set of | 91 // of fake/stub client implementations. Also initializes a default set of |
| 105 // fake Shill devices and services, customizable with switches::kShillStub. | 92 // fake Shill devices and services, customizable with switches::kShillStub. |
| 106 static void InitializeWithStub(); | 93 static void InitializeWithStub(); |
| 107 | 94 |
| 95 // Similar to Initialize(), but configures DBusThreadManager to use stub/fake | |
| 96 // clients. | |
| 97 static scoped_ptr<DBusThreadManagerTestHelper> InitializeForTesting(); | |
|
hashimoto
2014/08/18 04:55:58
Can't we delete one of InitializeWithStub() or Ini
zel
2014/08/18 23:41:52
InitilizeForTesting() still does one trick for us
hashimoto
2014/08/19 02:31:58
Adding setters should be harmless as long as DBusC
zel
2014/08/19 04:44:39
What harm are you talking about here? What you are
hashimoto
2014/08/19 05:11:59
The effect on the binary size (i.e. compiled&linke
zel
2014/08/22 22:24:18
Yeah, you are right about the runtime size I forgo
hashimoto
2014/08/25 06:56:19
You can make it clear by naming the bundle getter
zel
2014/08/25 17:21:41
I have picked better class/method names now, it's:
| |
| 98 | |
| 108 // Returns true if DBusThreadManager has been initialized. Call this to | 99 // Returns true if DBusThreadManager has been initialized. Call this to |
| 109 // avoid initializing + shutting down DBusThreadManager more than once. | 100 // avoid initializing + shutting down DBusThreadManager more than once. |
| 110 static bool IsInitialized(); | 101 static bool IsInitialized(); |
| 111 | 102 |
| 112 // Destroys the global instance. | 103 // Destroys the global instance. |
| 113 static void Shutdown(); | 104 static void Shutdown(); |
| 114 | 105 |
| 115 // Gets the global instance. Initialize() must be called first. | 106 // Gets the global instance. Initialize() must be called first. |
| 116 static DBusThreadManager* Get(); | 107 static DBusThreadManager* Get(); |
| 117 | 108 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 DBusThreadManager(); | 158 DBusThreadManager(); |
| 168 | 159 |
| 169 private: | 160 private: |
| 170 // Initialize global thread manager instance. | 161 // Initialize global thread manager instance. |
| 171 static void InitializeRegular(); | 162 static void InitializeRegular(); |
| 172 | 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. | |
| 178 // NOTE: Clients that access other clients in their Init() must be | |
| 179 // initialized in the correct order. | |
| 180 static void InitializeClients(); | |
| 181 | |
| 182 // Initializes |client| with the |system_bus_|. | |
| 183 static void InitClient(DBusClient* client); | |
| 184 | |
| 185 // Bitmask that defines which dbus clients are not stubbed out. Bitmap flags | 168 // Bitmask that defines which dbus clients are not stubbed out. Bitmap flags |
| 186 // are defined within DBusClientBundle::DBusClientType enum. | 169 // are defined within DBusClientBundle::DBusClientType enum. |
| 187 static DBusClientBundle::DBusClientTypeMask unstub_client_mask_; | 170 static DBusClientBundle::DBusClientTypeMask unstub_client_mask_; |
| 188 | 171 |
| 189 DISALLOW_COPY_AND_ASSIGN(DBusThreadManager); | 172 DISALLOW_COPY_AND_ASSIGN(DBusThreadManager); |
| 190 }; | 173 }; |
| 191 | 174 |
| 175 class CHROMEOS_EXPORT DBusThreadManagerTestHelper { | |
| 176 public: | |
| 177 explicit DBusThreadManagerTestHelper( | |
| 178 DBusThreadManagerImpl* dbus_thread_manager); | |
| 179 ~DBusThreadManagerTestHelper(); | |
| 180 | |
| 181 void SetBluetoothAdapterClient(scoped_ptr<BluetoothAdapterClient> client); | |
| 182 void SetBluetoothAgentManagerClient( | |
| 183 scoped_ptr<BluetoothAgentManagerClient> client); | |
| 184 void SetBluetoothDeviceClient(scoped_ptr<BluetoothDeviceClient> client); | |
| 185 void SetBluetoothGattCharacteristicClient( | |
| 186 scoped_ptr<BluetoothGattCharacteristicClient> client); | |
| 187 void SetBluetoothGattDescriptorClient( | |
| 188 scoped_ptr<BluetoothGattDescriptorClient> client); | |
| 189 void SetBluetoothGattManagerClient( | |
| 190 scoped_ptr<BluetoothGattManagerClient> client); | |
| 191 void SetBluetoothGattServiceClient( | |
| 192 scoped_ptr<BluetoothGattServiceClient> client); | |
| 193 void SetBluetoothInputClient(scoped_ptr<BluetoothInputClient> client); | |
| 194 void SetBluetoothProfileManagerClient( | |
| 195 scoped_ptr<BluetoothProfileManagerClient> client); | |
| 196 void SetCrasAudioClient(scoped_ptr<CrasAudioClient> client); | |
| 197 void SetCrosDisksClient(scoped_ptr<CrosDisksClient> client); | |
| 198 void SetCryptohomeClient(scoped_ptr<CryptohomeClient> client); | |
| 199 void SetDebugDaemonClient(scoped_ptr<DebugDaemonClient> client); | |
| 200 void SetEasyUnlockClient(scoped_ptr<EasyUnlockClient> client); | |
| 201 void SetLorgnetteManagerClient(scoped_ptr<LorgnetteManagerClient> client); | |
| 202 void SetShillDeviceClient(scoped_ptr<ShillDeviceClient> client); | |
| 203 void SetShillIPConfigClient(scoped_ptr<ShillIPConfigClient> client); | |
| 204 void SetShillManagerClient(scoped_ptr<ShillManagerClient> client); | |
| 205 void SetShillServiceClient(scoped_ptr<ShillServiceClient> client); | |
| 206 void SetShillProfileClient(scoped_ptr<ShillProfileClient> client); | |
| 207 void SetGsmSMSClient(scoped_ptr<GsmSMSClient> client); | |
| 208 void SetImageBurnerClient(scoped_ptr<ImageBurnerClient> client); | |
| 209 void SetIntrospectableClient(scoped_ptr<IntrospectableClient> client); | |
| 210 void SetModemMessagingClient(scoped_ptr<ModemMessagingClient> client); | |
| 211 void SetNfcAdapterClient(scoped_ptr<NfcAdapterClient> client); | |
| 212 void SetNfcDeviceClient(scoped_ptr<NfcDeviceClient> client); | |
| 213 void SetNfcManagerClient(scoped_ptr<NfcManagerClient> client); | |
| 214 void SetNfcRecordClient(scoped_ptr<NfcRecordClient> client); | |
| 215 void SetNfcTagClient(scoped_ptr<NfcTagClient> client); | |
| 216 void SetPermissionBrokerClient(scoped_ptr<PermissionBrokerClient> client); | |
| 217 void SetPowerManagerClient(scoped_ptr<PowerManagerClient> client); | |
| 218 void SetPowerPolicyController(scoped_ptr<PowerPolicyController> client); | |
| 219 void SetSessionManagerClient(scoped_ptr<SessionManagerClient> client); | |
| 220 void SetSMSClient(scoped_ptr<SMSClient> client); | |
| 221 void SetSystemClockClient(scoped_ptr<SystemClockClient> client); | |
| 222 void SetUpdateEngineClient(scoped_ptr<UpdateEngineClient> client); | |
| 223 | |
| 224 private: | |
| 225 DBusThreadManagerImpl* dbus_thread_manager_; | |
| 226 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerTestHelper); | |
| 227 }; | |
| 228 | |
| 192 } // namespace chromeos | 229 } // namespace chromeos |
| 193 | 230 |
| 194 #endif // CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ | 231 #endif // CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ |
| OLD | NEW |