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 #include "chromeos/dbus/dbus_thread_manager.h" | 5 #include "chromeos/dbus/dbus_thread_manager.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/observer_list.h" | 8 #include "base/observer_list.h" |
| 9 #include "base/sys_info.h" | 9 #include "base/sys_info.h" |
| 10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 11 #include "chromeos/chromeos_switches.h" | 11 #include "chromeos/chromeos_switches.h" |
| 12 #include "chromeos/dbus/bluetooth_adapter_client.h" | 12 #include "chromeos/dbus/bluetooth_adapter_client.h" |
| 13 #include "chromeos/dbus/bluetooth_agent_manager_client.h" | 13 #include "chromeos/dbus/bluetooth_agent_manager_client.h" |
| 14 #include "chromeos/dbus/bluetooth_device_client.h" | 14 #include "chromeos/dbus/bluetooth_device_client.h" |
| 15 #include "chromeos/dbus/bluetooth_gatt_characteristic_client.h" | 15 #include "chromeos/dbus/bluetooth_gatt_characteristic_client.h" |
| 16 #include "chromeos/dbus/bluetooth_gatt_descriptor_client.h" | 16 #include "chromeos/dbus/bluetooth_gatt_descriptor_client.h" |
| 17 #include "chromeos/dbus/bluetooth_gatt_manager_client.h" | 17 #include "chromeos/dbus/bluetooth_gatt_manager_client.h" |
| 18 #include "chromeos/dbus/bluetooth_gatt_service_client.h" | 18 #include "chromeos/dbus/bluetooth_gatt_service_client.h" |
| 19 #include "chromeos/dbus/bluetooth_input_client.h" | 19 #include "chromeos/dbus/bluetooth_input_client.h" |
| 20 #include "chromeos/dbus/bluetooth_profile_manager_client.h" | 20 #include "chromeos/dbus/bluetooth_profile_manager_client.h" |
| 21 #include "chromeos/dbus/cras_audio_client.h" | 21 #include "chromeos/dbus/cras_audio_client.h" |
| 22 #include "chromeos/dbus/cros_disks_client.h" | 22 #include "chromeos/dbus/cros_disks_client.h" |
| 23 #include "chromeos/dbus/cryptohome_client.h" | 23 #include "chromeos/dbus/cryptohome_client.h" |
| 24 #include "chromeos/dbus/dbus_client.h" | 24 #include "chromeos/dbus/dbus_client.h" |
| 25 #include "chromeos/dbus/dbus_client_bundle.h" | |
| 25 #include "chromeos/dbus/dbus_thread_manager_observer.h" | 26 #include "chromeos/dbus/dbus_thread_manager_observer.h" |
| 26 #include "chromeos/dbus/debug_daemon_client.h" | 27 #include "chromeos/dbus/debug_daemon_client.h" |
| 27 #include "chromeos/dbus/easy_unlock_client.h" | 28 #include "chromeos/dbus/easy_unlock_client.h" |
| 28 #include "chromeos/dbus/fake_dbus_thread_manager.h" | 29 #include "chromeos/dbus/fake_dbus_thread_manager.h" |
| 29 #include "chromeos/dbus/gsm_sms_client.h" | 30 #include "chromeos/dbus/gsm_sms_client.h" |
| 30 #include "chromeos/dbus/image_burner_client.h" | 31 #include "chromeos/dbus/image_burner_client.h" |
| 31 #include "chromeos/dbus/introspectable_client.h" | 32 #include "chromeos/dbus/introspectable_client.h" |
| 32 #include "chromeos/dbus/lorgnette_manager_client.h" | 33 #include "chromeos/dbus/lorgnette_manager_client.h" |
| 34 #include "chromeos/dbus/mixed_dbus_thread_manager.h" | |
| 33 #include "chromeos/dbus/modem_messaging_client.h" | 35 #include "chromeos/dbus/modem_messaging_client.h" |
| 34 #include "chromeos/dbus/nfc_adapter_client.h" | 36 #include "chromeos/dbus/nfc_adapter_client.h" |
| 35 #include "chromeos/dbus/nfc_device_client.h" | 37 #include "chromeos/dbus/nfc_device_client.h" |
| 36 #include "chromeos/dbus/nfc_manager_client.h" | 38 #include "chromeos/dbus/nfc_manager_client.h" |
| 37 #include "chromeos/dbus/nfc_record_client.h" | 39 #include "chromeos/dbus/nfc_record_client.h" |
| 38 #include "chromeos/dbus/nfc_tag_client.h" | 40 #include "chromeos/dbus/nfc_tag_client.h" |
| 39 #include "chromeos/dbus/permission_broker_client.h" | 41 #include "chromeos/dbus/permission_broker_client.h" |
| 40 #include "chromeos/dbus/power_manager_client.h" | 42 #include "chromeos/dbus/power_manager_client.h" |
| 41 #include "chromeos/dbus/power_policy_controller.h" | 43 #include "chromeos/dbus/power_policy_controller.h" |
| 42 #include "chromeos/dbus/session_manager_client.h" | 44 #include "chromeos/dbus/session_manager_client.h" |
| 43 #include "chromeos/dbus/shill_device_client.h" | 45 #include "chromeos/dbus/shill_device_client.h" |
| 44 #include "chromeos/dbus/shill_ipconfig_client.h" | 46 #include "chromeos/dbus/shill_ipconfig_client.h" |
| 45 #include "chromeos/dbus/shill_manager_client.h" | 47 #include "chromeos/dbus/shill_manager_client.h" |
| 46 #include "chromeos/dbus/shill_profile_client.h" | 48 #include "chromeos/dbus/shill_profile_client.h" |
| 47 #include "chromeos/dbus/shill_service_client.h" | 49 #include "chromeos/dbus/shill_service_client.h" |
| 48 #include "chromeos/dbus/sms_client.h" | 50 #include "chromeos/dbus/sms_client.h" |
| 49 #include "chromeos/dbus/system_clock_client.h" | 51 #include "chromeos/dbus/system_clock_client.h" |
| 50 #include "chromeos/dbus/update_engine_client.h" | 52 #include "chromeos/dbus/update_engine_client.h" |
| 51 #include "dbus/bus.h" | 53 #include "dbus/bus.h" |
| 52 #include "dbus/dbus_statistics.h" | 54 #include "dbus/dbus_statistics.h" |
| 53 | 55 |
| 54 namespace chromeos { | 56 namespace chromeos { |
| 55 | 57 |
| 56 static DBusThreadManager* g_dbus_thread_manager = NULL; | 58 static DBusThreadManager* g_dbus_thread_manager = NULL; |
| 57 static DBusThreadManager* g_dbus_thread_manager_for_testing = NULL; | 59 static DBusThreadManager* g_dbus_thread_manager_for_testing = NULL; |
| 58 | 60 |
| 59 // The bundle of all D-Bus clients used in DBusThreadManagerImpl. The bundle | 61 DBusClientBundle::DBusClientTypeMask |
| 60 // is used to delete them at once in the right order before shutting down the | 62 DBusThreadManager::unstub_client_mask_ = DBusClientBundle::ALL_CLIENTS; |
| 61 // system bus. See also the comment in the destructor of DBusThreadManagerImpl. | |
| 62 class DBusClientBundle { | |
| 63 public: | |
| 64 DBusClientBundle() { | |
| 65 const DBusClientImplementationType type = REAL_DBUS_CLIENT_IMPLEMENTATION; | |
| 66 | |
| 67 bluetooth_adapter_client_.reset(BluetoothAdapterClient::Create()); | |
| 68 bluetooth_agent_manager_client_.reset( | |
| 69 BluetoothAgentManagerClient::Create()); | |
| 70 bluetooth_device_client_.reset(BluetoothDeviceClient::Create()); | |
| 71 bluetooth_gatt_characteristic_client_.reset( | |
| 72 BluetoothGattCharacteristicClient::Create()); | |
| 73 bluetooth_gatt_descriptor_client_.reset( | |
| 74 BluetoothGattDescriptorClient::Create()); | |
| 75 bluetooth_gatt_manager_client_.reset(BluetoothGattManagerClient::Create()); | |
| 76 bluetooth_gatt_service_client_.reset(BluetoothGattServiceClient::Create()); | |
| 77 bluetooth_input_client_.reset(BluetoothInputClient::Create()); | |
| 78 bluetooth_profile_manager_client_.reset( | |
| 79 BluetoothProfileManagerClient::Create()); | |
| 80 cras_audio_client_.reset(CrasAudioClient::Create()); | |
| 81 cros_disks_client_.reset(CrosDisksClient::Create(type)); | |
| 82 cryptohome_client_.reset(CryptohomeClient::Create()); | |
| 83 debug_daemon_client_.reset(DebugDaemonClient::Create()); | |
| 84 easy_unlock_client_.reset(EasyUnlockClient::Create()); | |
| 85 lorgnette_manager_client_.reset(LorgnetteManagerClient::Create()); | |
| 86 shill_manager_client_.reset(ShillManagerClient::Create()); | |
| 87 shill_device_client_.reset(ShillDeviceClient::Create()); | |
| 88 shill_ipconfig_client_.reset(ShillIPConfigClient::Create()); | |
| 89 shill_service_client_.reset(ShillServiceClient::Create()); | |
| 90 shill_profile_client_.reset(ShillProfileClient::Create()); | |
| 91 gsm_sms_client_.reset(GsmSMSClient::Create()); | |
| 92 image_burner_client_.reset(ImageBurnerClient::Create()); | |
| 93 introspectable_client_.reset(IntrospectableClient::Create()); | |
| 94 modem_messaging_client_.reset(ModemMessagingClient::Create()); | |
| 95 // Create the NFC clients in the correct order based on their dependencies. | |
| 96 nfc_manager_client_.reset(NfcManagerClient::Create()); | |
| 97 nfc_adapter_client_.reset( | |
| 98 NfcAdapterClient::Create(nfc_manager_client_.get())); | |
| 99 nfc_device_client_.reset( | |
| 100 NfcDeviceClient::Create(nfc_adapter_client_.get())); | |
| 101 nfc_tag_client_.reset(NfcTagClient::Create(nfc_adapter_client_.get())); | |
| 102 nfc_record_client_.reset(NfcRecordClient::Create(nfc_device_client_.get(), | |
| 103 nfc_tag_client_.get())); | |
| 104 permission_broker_client_.reset(PermissionBrokerClient::Create()); | |
| 105 power_manager_client_.reset(PowerManagerClient::Create(type)); | |
| 106 session_manager_client_.reset(SessionManagerClient::Create(type)); | |
| 107 sms_client_.reset(SMSClient::Create()); | |
| 108 system_clock_client_.reset(SystemClockClient::Create()); | |
| 109 update_engine_client_.reset(UpdateEngineClient::Create(type)); | |
| 110 } | |
| 111 | |
| 112 BluetoothAdapterClient* bluetooth_adapter_client() { | |
| 113 return bluetooth_adapter_client_.get(); | |
| 114 } | |
| 115 BluetoothAgentManagerClient* bluetooth_agent_manager_client() { | |
| 116 return bluetooth_agent_manager_client_.get(); | |
| 117 } | |
| 118 BluetoothDeviceClient* bluetooth_device_client() { | |
| 119 return bluetooth_device_client_.get(); | |
| 120 } | |
| 121 BluetoothGattCharacteristicClient* bluetooth_gatt_characteristic_client() { | |
| 122 return bluetooth_gatt_characteristic_client_.get(); | |
| 123 } | |
| 124 BluetoothGattDescriptorClient* bluetooth_gatt_descriptor_client() { | |
| 125 return bluetooth_gatt_descriptor_client_.get(); | |
| 126 } | |
| 127 BluetoothGattManagerClient* bluetooth_gatt_manager_client() { | |
| 128 return bluetooth_gatt_manager_client_.get(); | |
| 129 } | |
| 130 BluetoothGattServiceClient* bluetooth_gatt_service_client() { | |
| 131 return bluetooth_gatt_service_client_.get(); | |
| 132 } | |
| 133 BluetoothInputClient* bluetooth_input_client() { | |
| 134 return bluetooth_input_client_.get(); | |
| 135 } | |
| 136 BluetoothProfileManagerClient* bluetooth_profile_manager_client() { | |
| 137 return bluetooth_profile_manager_client_.get(); | |
| 138 } | |
| 139 CrasAudioClient* cras_audio_client() { | |
| 140 return cras_audio_client_.get(); | |
| 141 } | |
| 142 CrosDisksClient* cros_disks_client() { | |
| 143 return cros_disks_client_.get(); | |
| 144 } | |
| 145 CryptohomeClient* cryptohome_client() { | |
| 146 return cryptohome_client_.get(); | |
| 147 } | |
| 148 DebugDaemonClient* debug_daemon_client() { | |
| 149 return debug_daemon_client_.get(); | |
| 150 } | |
| 151 EasyUnlockClient* easy_unlock_client() { | |
| 152 return easy_unlock_client_.get(); | |
| 153 } | |
| 154 LorgnetteManagerClient* lorgnette_manager_client() { | |
| 155 return lorgnette_manager_client_.get(); | |
| 156 } | |
| 157 ShillDeviceClient* shill_device_client() { | |
| 158 return shill_device_client_.get(); | |
| 159 } | |
| 160 ShillIPConfigClient* shill_ipconfig_client() { | |
| 161 return shill_ipconfig_client_.get(); | |
| 162 } | |
| 163 ShillManagerClient* shill_manager_client() { | |
| 164 return shill_manager_client_.get(); | |
| 165 } | |
| 166 ShillServiceClient* shill_service_client() { | |
| 167 return shill_service_client_.get(); | |
| 168 } | |
| 169 ShillProfileClient* shill_profile_client() { | |
| 170 return shill_profile_client_.get(); | |
| 171 } | |
| 172 GsmSMSClient* gsm_sms_client() { | |
| 173 return gsm_sms_client_.get(); | |
| 174 } | |
| 175 ImageBurnerClient* image_burner_client() { | |
| 176 return image_burner_client_.get(); | |
| 177 } | |
| 178 IntrospectableClient* introspectable_client() { | |
| 179 return introspectable_client_.get(); | |
| 180 } | |
| 181 ModemMessagingClient* modem_messaging_client() { | |
| 182 return modem_messaging_client_.get(); | |
| 183 } | |
| 184 NfcManagerClient* nfc_manager_client() { | |
| 185 return nfc_manager_client_.get(); | |
| 186 } | |
| 187 NfcAdapterClient* nfc_adapter_client() { | |
| 188 return nfc_adapter_client_.get(); | |
| 189 } | |
| 190 NfcDeviceClient* nfc_device_client() { | |
| 191 return nfc_device_client_.get(); | |
| 192 } | |
| 193 NfcTagClient* nfc_tag_client() { | |
| 194 return nfc_tag_client_.get(); | |
| 195 } | |
| 196 NfcRecordClient* nfc_record_client() { | |
| 197 return nfc_record_client_.get(); | |
| 198 } | |
| 199 PermissionBrokerClient* permission_broker_client() { | |
| 200 return permission_broker_client_.get(); | |
| 201 } | |
| 202 SystemClockClient* system_clock_client() { | |
| 203 return system_clock_client_.get(); | |
| 204 } | |
| 205 PowerManagerClient* power_manager_client() { | |
| 206 return power_manager_client_.get(); | |
| 207 } | |
| 208 SessionManagerClient* session_manager_client() { | |
| 209 return session_manager_client_.get(); | |
| 210 } | |
| 211 SMSClient* sms_client() { | |
| 212 return sms_client_.get(); | |
| 213 } | |
| 214 UpdateEngineClient* update_engine_client() { | |
| 215 return update_engine_client_.get(); | |
| 216 } | |
| 217 | |
| 218 private: | |
| 219 scoped_ptr<BluetoothAdapterClient> bluetooth_adapter_client_; | |
| 220 scoped_ptr<BluetoothAgentManagerClient> bluetooth_agent_manager_client_; | |
| 221 scoped_ptr<BluetoothDeviceClient> bluetooth_device_client_; | |
| 222 scoped_ptr<BluetoothGattCharacteristicClient> | |
| 223 bluetooth_gatt_characteristic_client_; | |
| 224 scoped_ptr<BluetoothGattDescriptorClient> bluetooth_gatt_descriptor_client_; | |
| 225 scoped_ptr<BluetoothGattManagerClient> bluetooth_gatt_manager_client_; | |
| 226 scoped_ptr<BluetoothGattServiceClient> bluetooth_gatt_service_client_; | |
| 227 scoped_ptr<BluetoothInputClient> bluetooth_input_client_; | |
| 228 scoped_ptr<BluetoothProfileManagerClient> bluetooth_profile_manager_client_; | |
| 229 scoped_ptr<CrasAudioClient> cras_audio_client_; | |
| 230 scoped_ptr<CrosDisksClient> cros_disks_client_; | |
| 231 scoped_ptr<CryptohomeClient> cryptohome_client_; | |
| 232 scoped_ptr<DebugDaemonClient> debug_daemon_client_; | |
| 233 scoped_ptr<EasyUnlockClient> easy_unlock_client_; | |
| 234 scoped_ptr<LorgnetteManagerClient> lorgnette_manager_client_; | |
| 235 scoped_ptr<ShillDeviceClient> shill_device_client_; | |
| 236 scoped_ptr<ShillIPConfigClient> shill_ipconfig_client_; | |
| 237 scoped_ptr<ShillManagerClient> shill_manager_client_; | |
| 238 scoped_ptr<ShillServiceClient> shill_service_client_; | |
| 239 scoped_ptr<ShillProfileClient> shill_profile_client_; | |
| 240 scoped_ptr<GsmSMSClient> gsm_sms_client_; | |
| 241 scoped_ptr<ImageBurnerClient> image_burner_client_; | |
| 242 scoped_ptr<IntrospectableClient> introspectable_client_; | |
| 243 scoped_ptr<ModemMessagingClient> modem_messaging_client_; | |
| 244 // The declaration order for NFC client objects is important. See | |
| 245 // DBusThreadManager::CreateDefaultClients for the dependencies. | |
| 246 scoped_ptr<NfcManagerClient> nfc_manager_client_; | |
| 247 scoped_ptr<NfcAdapterClient> nfc_adapter_client_; | |
| 248 scoped_ptr<NfcDeviceClient> nfc_device_client_; | |
| 249 scoped_ptr<NfcTagClient> nfc_tag_client_; | |
| 250 scoped_ptr<NfcRecordClient> nfc_record_client_; | |
| 251 scoped_ptr<PermissionBrokerClient> permission_broker_client_; | |
| 252 scoped_ptr<SystemClockClient> system_clock_client_; | |
| 253 scoped_ptr<PowerManagerClient> power_manager_client_; | |
| 254 scoped_ptr<SessionManagerClient> session_manager_client_; | |
| 255 scoped_ptr<SMSClient> sms_client_; | |
| 256 scoped_ptr<UpdateEngineClient> update_engine_client_; | |
| 257 | |
| 258 DISALLOW_COPY_AND_ASSIGN(DBusClientBundle); | |
| 259 }; | |
| 260 | 63 |
| 261 // The DBusThreadManager implementation used in production. | 64 // The DBusThreadManager implementation used in production. |
| 262 class DBusThreadManagerImpl : public DBusThreadManager { | 65 class DBusThreadManagerImpl : public DBusThreadManager { |
| 263 public: | 66 public: |
| 264 DBusThreadManagerImpl() { | 67 DBusThreadManagerImpl() { |
| 265 // Create the D-Bus thread. | 68 // Create the D-Bus thread. |
| 266 base::Thread::Options thread_options; | 69 base::Thread::Options thread_options; |
| 267 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; | 70 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 268 dbus_thread_.reset(new base::Thread("D-Bus thread")); | 71 dbus_thread_.reset(new base::Thread("D-Bus thread")); |
| 269 dbus_thread_->StartWithOptions(thread_options); | 72 dbus_thread_->StartWithOptions(thread_options); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 289 client_bundle_.reset(); | 92 client_bundle_.reset(); |
| 290 | 93 |
| 291 // Shut down the bus. During the browser shutdown, it's ok to shut down | 94 // Shut down the bus. During the browser shutdown, it's ok to shut down |
| 292 // the bus synchronously. | 95 // the bus synchronously. |
| 293 system_bus_->ShutdownOnDBusThreadAndBlock(); | 96 system_bus_->ShutdownOnDBusThreadAndBlock(); |
| 294 | 97 |
| 295 // Stop the D-Bus thread. | 98 // Stop the D-Bus thread. |
| 296 dbus_thread_->Stop(); | 99 dbus_thread_->Stop(); |
| 297 } | 100 } |
| 298 | 101 |
| 299 // DBusThreadManager overrides: | |
| 300 virtual void AddObserver(DBusThreadManagerObserver* observer) OVERRIDE { | 102 virtual void AddObserver(DBusThreadManagerObserver* observer) OVERRIDE { |
| 301 DCHECK(observer); | 103 DCHECK(observer); |
| 302 observers_.AddObserver(observer); | 104 observers_.AddObserver(observer); |
| 303 } | 105 } |
| 304 | 106 |
| 305 virtual void RemoveObserver(DBusThreadManagerObserver* observer) OVERRIDE { | 107 virtual void RemoveObserver(DBusThreadManagerObserver* observer) OVERRIDE { |
| 306 DCHECK(observer); | 108 DCHECK(observer); |
| 307 observers_.RemoveObserver(observer); | 109 observers_.RemoveObserver(observer); |
| 308 } | 110 } |
| 309 | 111 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 455 } | 257 } |
| 456 | 258 |
| 457 virtual PowerPolicyController* GetPowerPolicyController() OVERRIDE { | 259 virtual PowerPolicyController* GetPowerPolicyController() OVERRIDE { |
| 458 return power_policy_controller_.get(); | 260 return power_policy_controller_.get(); |
| 459 } | 261 } |
| 460 | 262 |
| 461 private: | 263 private: |
| 462 // Constructs all clients and stores them in the respective *_client_ member | 264 // Constructs all clients and stores them in the respective *_client_ member |
| 463 // variable. | 265 // variable. |
| 464 void CreateDefaultClients() { | 266 void CreateDefaultClients() { |
| 465 client_bundle_.reset(new DBusClientBundle); | 267 client_bundle_.reset(new DBusClientBundle()); |
| 466 power_policy_controller_.reset(new PowerPolicyController); | 268 if (!DBusThreadManager::IsUsingStub(DBusClientBundle::POWER_MANAGER)) |
|
satorux1
2014/08/13 01:09:20
while you are at it, could you add:
// TODO(crbug
zel
2014/08/13 01:36:02
Done.
| |
| 269 power_policy_controller_.reset(new PowerPolicyController); | |
| 467 } | 270 } |
| 468 | 271 |
| 469 // Note: Keep this before other members so they can call AddObserver() in | 272 // Note: Keep this before other members so they can call AddObserver() in |
| 470 // their c'tors. | 273 // their c'tors. |
| 471 ObserverList<DBusThreadManagerObserver> observers_; | 274 ObserverList<DBusThreadManagerObserver> observers_; |
| 472 | 275 |
| 473 scoped_ptr<base::Thread> dbus_thread_; | 276 scoped_ptr<base::Thread> dbus_thread_; |
| 474 scoped_refptr<dbus::Bus> system_bus_; | 277 scoped_refptr<dbus::Bus> system_bus_; |
| 475 scoped_ptr<DBusClientBundle> client_bundle_; | 278 scoped_ptr<DBusClientBundle> client_bundle_; |
| 476 scoped_ptr<PowerPolicyController> power_policy_controller_; | 279 scoped_ptr<PowerPolicyController> power_policy_controller_; |
| 477 | 280 |
| 478 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerImpl); | 281 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerImpl); |
| 479 }; | 282 }; |
| 480 | 283 |
| 284 | |
| 285 // static | |
| 286 bool DBusThreadManager::IsUsingStub(DBusClientBundle::DBusClientType client) { | |
| 287 return !(unstub_client_mask_ & client); | |
| 288 } | |
| 289 | |
| 481 // static | 290 // static |
| 482 void DBusThreadManager::Initialize() { | 291 void DBusThreadManager::Initialize() { |
| 483 // If we initialize DBusThreadManager twice we may also be shutting it down | 292 // If we initialize DBusThreadManager twice we may also be shutting it down |
| 484 // early; do not allow that. | 293 // early; do not allow that. |
| 485 CHECK(g_dbus_thread_manager == NULL); | 294 CHECK(g_dbus_thread_manager == NULL); |
| 486 | 295 |
| 487 if (g_dbus_thread_manager_for_testing) { | 296 if (g_dbus_thread_manager_for_testing) { |
| 488 g_dbus_thread_manager = g_dbus_thread_manager_for_testing; | 297 g_dbus_thread_manager = g_dbus_thread_manager_for_testing; |
| 489 InitializeClients(); | 298 InitializeClients(); |
| 490 VLOG(1) << "DBusThreadManager initialized with test implementation"; | 299 VLOG(1) << "DBusThreadManager initialized with test implementation"; |
| 491 return; | 300 return; |
| 492 } | 301 } |
| 493 | 302 |
| 303 bool use_dbus_stub = !base::SysInfo::IsRunningOnChromeOS() || | |
| 304 CommandLine::ForCurrentProcess()->HasSwitch( | |
| 305 chromeos::switches::kDbusStub); | |
| 306 bool force_unstub_clients = CommandLine::ForCurrentProcess()->HasSwitch( | |
| 307 chromeos::switches::kDbusUnstubClients); | |
| 494 // Determine whether we use stub or real client implementations. | 308 // Determine whether we use stub or real client implementations. |
| 495 if (!base::SysInfo::IsRunningOnChromeOS() || | 309 if (force_unstub_clients) { |
| 496 CommandLine::ForCurrentProcess()->HasSwitch( | 310 InitializeWithPartialStub( |
| 497 chromeos::switches::kDbusStub)) { | 311 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 312 chromeos::switches::kDbusUnstubClients)); | |
| 313 } else if (use_dbus_stub) { | |
| 498 InitializeWithStub(); | 314 InitializeWithStub(); |
| 499 } else { | 315 } else { |
| 500 g_dbus_thread_manager = new DBusThreadManagerImpl; | 316 InitializeRegular(); |
| 501 InitializeClients(); | |
| 502 VLOG(1) << "DBusThreadManager initialized for Chrome OS"; | |
| 503 } | 317 } |
| 504 } | 318 } |
| 505 | 319 |
| 506 // static | 320 // static |
| 507 void DBusThreadManager::SetInstanceForTesting( | 321 void DBusThreadManager::SetInstanceForTesting( |
| 508 DBusThreadManager* dbus_thread_manager) { | 322 DBusThreadManager* dbus_thread_manager) { |
| 509 CHECK(!g_dbus_thread_manager); | 323 CHECK(!g_dbus_thread_manager); |
| 510 CHECK(!g_dbus_thread_manager_for_testing); | 324 CHECK(!g_dbus_thread_manager_for_testing); |
| 511 g_dbus_thread_manager_for_testing = dbus_thread_manager; | 325 g_dbus_thread_manager_for_testing = dbus_thread_manager; |
| 512 } | 326 } |
| 513 | 327 |
| 514 // static | 328 // static |
| 515 void DBusThreadManager::InitializeForTesting( | 329 void DBusThreadManager::InitializeForTesting( |
| 516 DBusThreadManager* dbus_thread_manager) { | 330 DBusThreadManager* dbus_thread_manager) { |
| 517 SetInstanceForTesting(dbus_thread_manager); | 331 SetInstanceForTesting(dbus_thread_manager); |
| 518 Initialize(); | 332 Initialize(); |
| 519 } | 333 } |
| 520 | 334 |
| 521 // static | 335 // static |
| 336 void DBusThreadManager::InitializeRegular() { | |
| 337 g_dbus_thread_manager = new DBusThreadManagerImpl(); | |
| 338 InitializeClients(); | |
| 339 VLOG(1) << "DBusThreadManager initialized for Chrome OS"; | |
| 340 } | |
| 341 | |
| 342 // static | |
| 343 void DBusThreadManager::InitializeWithPartialStub( | |
| 344 const std::string& unstub_clients) { | |
| 345 // If we initialize DBusThreadManager twice we may also be shutting it down | |
| 346 // early; do not allow that. | |
| 347 CHECK(g_dbus_thread_manager == NULL); | |
| 348 | |
| 349 unstub_client_mask_ = DBusClientBundle::ParseUnstubList(unstub_clients); | |
| 350 // We should have something parsed correctly here. | |
| 351 if (unstub_client_mask_ == 0) { | |
| 352 LOG(FATAL) << "Switch values for --" | |
| 353 << chromeos::switches::kDbusUnstubClients | |
| 354 << " cannot be parsed: " | |
| 355 << unstub_clients; | |
| 356 } | |
| 357 DBusThreadManager* real_thread_manager = new DBusThreadManagerImpl(); | |
| 358 FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager; | |
| 359 fake_dbus_thread_manager->SetFakeClients(); | |
| 360 VLOG(1) << "DBusThreadManager initialized for mixed runtime environment"; | |
| 361 g_dbus_thread_manager = new MixedDBusThreadManager(real_thread_manager, | |
| 362 fake_dbus_thread_manager); | |
| 363 InitializeClients(); | |
| 364 fake_dbus_thread_manager->SetupDefaultEnvironment(); | |
| 365 } | |
| 366 | |
| 367 // static | |
| 522 void DBusThreadManager::InitializeWithStub() { | 368 void DBusThreadManager::InitializeWithStub() { |
| 523 // If we initialize DBusThreadManager twice we may also be shutting it down | 369 // If we initialize DBusThreadManager twice we may also be shutting it down |
| 524 // early; do not allow that. | 370 // early; do not allow that. |
| 525 CHECK(g_dbus_thread_manager == NULL); | 371 CHECK(g_dbus_thread_manager == NULL); |
| 526 FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager; | 372 FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager; |
| 527 fake_dbus_thread_manager->SetFakeClients(); | 373 fake_dbus_thread_manager->SetFakeClients(); |
| 528 g_dbus_thread_manager = fake_dbus_thread_manager; | 374 g_dbus_thread_manager = fake_dbus_thread_manager; |
| 529 InitializeClients(); | 375 InitializeClients(); |
| 530 fake_dbus_thread_manager->SetupDefaultEnvironment(); | 376 fake_dbus_thread_manager->SetupDefaultEnvironment(); |
| 531 VLOG(1) << "DBusThreadManager initialized with stub implementation"; | 377 VLOG(1) << "DBusThreadManager initialized with stub implementation"; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 629 g_dbus_thread_manager->GetSystemBus()->GetManagedObjects(); | 475 g_dbus_thread_manager->GetSystemBus()->GetManagedObjects(); |
| 630 } | 476 } |
| 631 | 477 |
| 632 // static | 478 // static |
| 633 void DBusThreadManager::InitClient(DBusClient* client) { | 479 void DBusThreadManager::InitClient(DBusClient* client) { |
| 634 if (client) | 480 if (client) |
| 635 client->Init(g_dbus_thread_manager->GetSystemBus()); | 481 client->Init(g_dbus_thread_manager->GetSystemBus()); |
| 636 } | 482 } |
| 637 | 483 |
| 638 } // namespace chromeos | 484 } // namespace chromeos |
| OLD | NEW |