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/strings/string_split.h" | |
| 10 #include "base/strings/string_util.h" | |
| 9 #include "base/sys_info.h" | 11 #include "base/sys_info.h" |
| 10 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 11 #include "chromeos/chromeos_switches.h" | 13 #include "chromeos/chromeos_switches.h" |
| 12 #include "chromeos/dbus/bluetooth_adapter_client.h" | 14 #include "chromeos/dbus/bluetooth_adapter_client.h" |
| 13 #include "chromeos/dbus/bluetooth_agent_manager_client.h" | 15 #include "chromeos/dbus/bluetooth_agent_manager_client.h" |
| 14 #include "chromeos/dbus/bluetooth_device_client.h" | 16 #include "chromeos/dbus/bluetooth_device_client.h" |
| 15 #include "chromeos/dbus/bluetooth_gatt_characteristic_client.h" | 17 #include "chromeos/dbus/bluetooth_gatt_characteristic_client.h" |
| 16 #include "chromeos/dbus/bluetooth_gatt_descriptor_client.h" | 18 #include "chromeos/dbus/bluetooth_gatt_descriptor_client.h" |
| 17 #include "chromeos/dbus/bluetooth_gatt_manager_client.h" | 19 #include "chromeos/dbus/bluetooth_gatt_manager_client.h" |
| 18 #include "chromeos/dbus/bluetooth_gatt_service_client.h" | 20 #include "chromeos/dbus/bluetooth_gatt_service_client.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 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 | |
| 59 // The bundle of all D-Bus clients used in DBusThreadManagerImpl. The bundle | 60 // The bundle of all D-Bus clients used in DBusThreadManagerImpl. The bundle |
| 60 // is used to delete them at once in the right order before shutting down the | 61 // is used to delete them at once in the right order before shutting down the |
| 61 // system bus. See also the comment in the destructor of DBusThreadManagerImpl. | 62 // system bus. See also the comment in the destructor of DBusThreadManagerImpl. |
| 62 class DBusClientBundle { | 63 class DBusClientBundle { |
| 63 public: | 64 public: |
| 64 DBusClientBundle() { | 65 enum DBusClientType { |
| 66 Unknown = 0, | |
| 67 Bluetooth = 1 << 1, | |
| 68 BluetoothLowEnergy = 1 << 2, | |
|
satorux1
2014/08/07 20:00:05
Per http://www.chromium.org/developers/coding-styl
zel
2014/08/07 21:40:44
Done.
| |
| 69 Cras = 1 << 3, | |
| 70 CrosDisks = 1 << 4, | |
| 71 Cryptohome = 1 << 5, | |
| 72 DebugDaemon = 1 << 6, | |
| 73 EasyUnlock = 1 << 7, | |
| 74 LorgnetteManager = 1 << 8, | |
| 75 Shill = 1 << 9, | |
| 76 GsmSMS = 1 << 10, | |
| 77 ImageBurner = 1 << 11, | |
| 78 Introspectable = 1 << 12, | |
| 79 ModemMessaging = 1 << 13, | |
| 80 Nfc = 1 << 14, | |
| 81 PermissionBroker = 1 << 15, | |
| 82 PowerManager = 1 << 16, | |
| 83 PowerPolicy = 1 << 17, | |
| 84 SessionManager = 1 << 18, | |
| 85 SMS = 1 << 19, | |
| 86 SystemClock = 1 << 20, | |
| 87 UpdateEngine = 1 << 21, | |
| 88 All = 0xFFFFFFFF, | |
| 89 }; | |
| 90 | |
| 91 explicit DBusClientBundle(int client_mask) { | |
| 65 const DBusClientImplementationType type = REAL_DBUS_CLIENT_IMPLEMENTATION; | 92 const DBusClientImplementationType type = REAL_DBUS_CLIENT_IMPLEMENTATION; |
| 66 | 93 |
| 67 bluetooth_adapter_client_.reset(BluetoothAdapterClient::Create()); | 94 if (client_mask & Bluetooth) { |
| 68 bluetooth_agent_manager_client_.reset( | 95 bluetooth_adapter_client_.reset(BluetoothAdapterClient::Create()); |
| 69 BluetoothAgentManagerClient::Create()); | 96 bluetooth_agent_manager_client_.reset( |
| 70 bluetooth_device_client_.reset(BluetoothDeviceClient::Create()); | 97 BluetoothAgentManagerClient::Create()); |
| 71 bluetooth_gatt_characteristic_client_.reset( | 98 bluetooth_device_client_.reset(BluetoothDeviceClient::Create()); |
| 72 BluetoothGattCharacteristicClient::Create()); | 99 bluetooth_input_client_.reset(BluetoothInputClient::Create()); |
| 73 bluetooth_gatt_descriptor_client_.reset( | 100 bluetooth_profile_manager_client_.reset( |
| 74 BluetoothGattDescriptorClient::Create()); | 101 BluetoothProfileManagerClient::Create()); |
| 75 bluetooth_gatt_manager_client_.reset(BluetoothGattManagerClient::Create()); | 102 } |
| 76 bluetooth_gatt_service_client_.reset(BluetoothGattServiceClient::Create()); | 103 |
| 77 bluetooth_input_client_.reset(BluetoothInputClient::Create()); | 104 if (client_mask & BluetoothLowEnergy) { |
| 78 bluetooth_profile_manager_client_.reset( | 105 bluetooth_gatt_characteristic_client_.reset( |
| 79 BluetoothProfileManagerClient::Create()); | 106 BluetoothGattCharacteristicClient::Create()); |
| 80 cras_audio_client_.reset(CrasAudioClient::Create()); | 107 bluetooth_gatt_descriptor_client_.reset( |
| 81 cros_disks_client_.reset(CrosDisksClient::Create(type)); | 108 BluetoothGattDescriptorClient::Create()); |
| 109 bluetooth_gatt_manager_client_.reset( | |
| 110 BluetoothGattManagerClient::Create()); | |
| 111 bluetooth_gatt_service_client_.reset( | |
| 112 BluetoothGattServiceClient::Create()); | |
| 113 } | |
| 114 | |
| 115 if (client_mask & Cras) | |
| 116 cras_audio_client_.reset(CrasAudioClient::Create()); | |
| 117 | |
| 118 if (client_mask & CrosDisks) | |
| 119 cros_disks_client_.reset(CrosDisksClient::Create(type)); | |
| 120 | |
| 121 if (client_mask & Cryptohome) | |
| 82 cryptohome_client_.reset(CryptohomeClient::Create()); | 122 cryptohome_client_.reset(CryptohomeClient::Create()); |
| 123 | |
| 124 if (client_mask & DebugDaemon) | |
| 83 debug_daemon_client_.reset(DebugDaemonClient::Create()); | 125 debug_daemon_client_.reset(DebugDaemonClient::Create()); |
| 84 easy_unlock_client_.reset(EasyUnlockClient::Create()); | 126 |
| 85 lorgnette_manager_client_.reset(LorgnetteManagerClient::Create()); | 127 if (client_mask & EasyUnlock) |
| 86 shill_manager_client_.reset(ShillManagerClient::Create()); | 128 easy_unlock_client_.reset(EasyUnlockClient::Create()); |
| 87 shill_device_client_.reset(ShillDeviceClient::Create()); | 129 |
| 88 shill_ipconfig_client_.reset(ShillIPConfigClient::Create()); | 130 if (client_mask & LorgnetteManager) |
| 89 shill_service_client_.reset(ShillServiceClient::Create()); | 131 lorgnette_manager_client_.reset(LorgnetteManagerClient::Create()); |
| 90 shill_profile_client_.reset(ShillProfileClient::Create()); | 132 |
| 91 gsm_sms_client_.reset(GsmSMSClient::Create()); | 133 if (client_mask & Shill) { |
| 92 image_burner_client_.reset(ImageBurnerClient::Create()); | 134 shill_manager_client_.reset(ShillManagerClient::Create()); |
| 93 introspectable_client_.reset(IntrospectableClient::Create()); | 135 shill_device_client_.reset(ShillDeviceClient::Create()); |
| 94 modem_messaging_client_.reset(ModemMessagingClient::Create()); | 136 shill_ipconfig_client_.reset(ShillIPConfigClient::Create()); |
| 137 shill_service_client_.reset(ShillServiceClient::Create()); | |
| 138 shill_profile_client_.reset(ShillProfileClient::Create()); | |
| 139 } | |
| 140 | |
| 141 if (client_mask & GsmSMS) | |
| 142 gsm_sms_client_.reset(GsmSMSClient::Create()); | |
| 143 | |
| 144 if (client_mask & ImageBurner) | |
| 145 image_burner_client_.reset(ImageBurnerClient::Create()); | |
| 146 | |
| 147 if (client_mask & Introspectable) | |
| 148 introspectable_client_.reset(IntrospectableClient::Create()); | |
| 149 | |
| 150 if (client_mask & ModemMessaging) | |
| 151 modem_messaging_client_.reset(ModemMessagingClient::Create()); | |
| 152 | |
| 95 // Create the NFC clients in the correct order based on their dependencies. | 153 // Create the NFC clients in the correct order based on their dependencies. |
| 96 nfc_manager_client_.reset(NfcManagerClient::Create()); | 154 if (client_mask & Nfc) { |
| 97 nfc_adapter_client_.reset( | 155 nfc_manager_client_.reset(NfcManagerClient::Create()); |
| 98 NfcAdapterClient::Create(nfc_manager_client_.get())); | 156 nfc_adapter_client_.reset( |
| 99 nfc_device_client_.reset( | 157 NfcAdapterClient::Create(nfc_manager_client_.get())); |
| 100 NfcDeviceClient::Create(nfc_adapter_client_.get())); | 158 nfc_device_client_.reset( |
| 101 nfc_tag_client_.reset(NfcTagClient::Create(nfc_adapter_client_.get())); | 159 NfcDeviceClient::Create(nfc_adapter_client_.get())); |
| 102 nfc_record_client_.reset(NfcRecordClient::Create(nfc_device_client_.get(), | 160 nfc_tag_client_.reset(NfcTagClient::Create(nfc_adapter_client_.get())); |
| 103 nfc_tag_client_.get())); | 161 nfc_record_client_.reset(NfcRecordClient::Create(nfc_device_client_.get(), |
| 104 permission_broker_client_.reset(PermissionBrokerClient::Create()); | 162 nfc_tag_client_.get())); |
| 105 power_manager_client_.reset(PowerManagerClient::Create(type)); | 163 } |
| 106 session_manager_client_.reset(SessionManagerClient::Create(type)); | 164 |
| 107 sms_client_.reset(SMSClient::Create()); | 165 if (client_mask & PermissionBroker) |
| 108 system_clock_client_.reset(SystemClockClient::Create()); | 166 permission_broker_client_.reset(PermissionBrokerClient::Create()); |
| 109 update_engine_client_.reset(UpdateEngineClient::Create(type)); | 167 |
| 168 if (client_mask & PowerManager) | |
| 169 power_manager_client_.reset(PowerManagerClient::Create(type)); | |
| 170 | |
| 171 if (client_mask & SessionManager) | |
| 172 session_manager_client_.reset(SessionManagerClient::Create(type)); | |
| 173 | |
| 174 if (client_mask & SMS) | |
| 175 sms_client_.reset(SMSClient::Create()); | |
| 176 | |
| 177 if (client_mask & SystemClock) | |
| 178 system_clock_client_.reset(SystemClockClient::Create()); | |
| 179 | |
| 180 if (client_mask & UpdateEngine) | |
| 181 update_engine_client_.reset(UpdateEngineClient::Create(type)); | |
| 110 } | 182 } |
| 111 | 183 |
| 112 BluetoothAdapterClient* bluetooth_adapter_client() { | 184 BluetoothAdapterClient* bluetooth_adapter_client() { |
| 113 return bluetooth_adapter_client_.get(); | 185 return bluetooth_adapter_client_.get(); |
| 114 } | 186 } |
| 115 BluetoothAgentManagerClient* bluetooth_agent_manager_client() { | 187 BluetoothAgentManagerClient* bluetooth_agent_manager_client() { |
| 116 return bluetooth_agent_manager_client_.get(); | 188 return bluetooth_agent_manager_client_.get(); |
| 117 } | 189 } |
| 118 BluetoothDeviceClient* bluetooth_device_client() { | 190 BluetoothDeviceClient* bluetooth_device_client() { |
| 119 return bluetooth_device_client_.get(); | 191 return bluetooth_device_client_.get(); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 scoped_ptr<SessionManagerClient> session_manager_client_; | 326 scoped_ptr<SessionManagerClient> session_manager_client_; |
| 255 scoped_ptr<SMSClient> sms_client_; | 327 scoped_ptr<SMSClient> sms_client_; |
| 256 scoped_ptr<UpdateEngineClient> update_engine_client_; | 328 scoped_ptr<UpdateEngineClient> update_engine_client_; |
| 257 | 329 |
| 258 DISALLOW_COPY_AND_ASSIGN(DBusClientBundle); | 330 DISALLOW_COPY_AND_ASSIGN(DBusClientBundle); |
| 259 }; | 331 }; |
| 260 | 332 |
| 261 // The DBusThreadManager implementation used in production. | 333 // The DBusThreadManager implementation used in production. |
| 262 class DBusThreadManagerImpl : public DBusThreadManager { | 334 class DBusThreadManagerImpl : public DBusThreadManager { |
| 263 public: | 335 public: |
| 264 DBusThreadManagerImpl() { | 336 explicit DBusThreadManagerImpl(int client_mask) : client_mask_(client_mask) { |
|
satorux1
2014/08/07 20:00:05
please document |client_mask|
| |
| 265 // Create the D-Bus thread. | 337 // Create the D-Bus thread. |
| 266 base::Thread::Options thread_options; | 338 base::Thread::Options thread_options; |
| 267 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; | 339 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 268 dbus_thread_.reset(new base::Thread("D-Bus thread")); | 340 dbus_thread_.reset(new base::Thread("D-Bus thread")); |
| 269 dbus_thread_->StartWithOptions(thread_options); | 341 dbus_thread_->StartWithOptions(thread_options); |
| 270 | 342 |
| 271 // Create the connection to the system bus. | 343 // Create the connection to the system bus. |
| 272 dbus::Bus::Options system_bus_options; | 344 dbus::Bus::Options system_bus_options; |
| 273 system_bus_options.bus_type = dbus::Bus::SYSTEM; | 345 system_bus_options.bus_type = dbus::Bus::SYSTEM; |
| 274 system_bus_options.connection_type = dbus::Bus::PRIVATE; | 346 system_bus_options.connection_type = dbus::Bus::PRIVATE; |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 455 } | 527 } |
| 456 | 528 |
| 457 virtual PowerPolicyController* GetPowerPolicyController() OVERRIDE { | 529 virtual PowerPolicyController* GetPowerPolicyController() OVERRIDE { |
| 458 return power_policy_controller_.get(); | 530 return power_policy_controller_.get(); |
| 459 } | 531 } |
| 460 | 532 |
| 461 private: | 533 private: |
| 462 // Constructs all clients and stores them in the respective *_client_ member | 534 // Constructs all clients and stores them in the respective *_client_ member |
| 463 // variable. | 535 // variable. |
| 464 void CreateDefaultClients() { | 536 void CreateDefaultClients() { |
| 465 client_bundle_.reset(new DBusClientBundle); | 537 client_bundle_.reset(new DBusClientBundle(client_mask_)); |
| 466 power_policy_controller_.reset(new PowerPolicyController); | 538 power_policy_controller_.reset(new PowerPolicyController); |
| 467 } | 539 } |
| 468 | 540 |
| 469 // Note: Keep this before other members so they can call AddObserver() in | 541 // Note: Keep this before other members so they can call AddObserver() in |
| 470 // their c'tors. | 542 // their c'tors. |
| 471 ObserverList<DBusThreadManagerObserver> observers_; | 543 ObserverList<DBusThreadManagerObserver> observers_; |
| 472 | 544 |
| 473 scoped_ptr<base::Thread> dbus_thread_; | 545 scoped_ptr<base::Thread> dbus_thread_; |
| 474 scoped_refptr<dbus::Bus> system_bus_; | 546 scoped_refptr<dbus::Bus> system_bus_; |
| 475 scoped_ptr<DBusClientBundle> client_bundle_; | 547 scoped_ptr<DBusClientBundle> client_bundle_; |
| 476 scoped_ptr<PowerPolicyController> power_policy_controller_; | 548 scoped_ptr<PowerPolicyController> power_policy_controller_; |
| 549 int client_mask_; | |
| 477 | 550 |
| 478 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerImpl); | 551 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerImpl); |
| 479 }; | 552 }; |
| 480 | 553 |
| 554 class MixedDBusThreadManager : public DBusThreadManager { | |
|
satorux1
2014/08/07 20:00:05
Class comment is missing.
zel
2014/08/07 21:40:44
Done.
| |
| 555 public: | |
| 556 explicit MixedDBusThreadManager(const std::string& unstub_list) { | |
| 557 ParseUnstubList(unstub_list); | |
| 558 real_thread_manager_.reset( | |
| 559 new DBusThreadManagerImpl(unstub_mask_)); | |
| 560 FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager; | |
| 561 fake_dbus_thread_manager->SetFakeClients(); | |
| 562 fake_thread_manager_.reset(fake_dbus_thread_manager); | |
| 563 } | |
| 564 | |
| 565 virtual ~MixedDBusThreadManager() { | |
| 566 } | |
| 567 | |
| 568 private: | |
| 569 static DBusClientBundle::DBusClientType GetDBusClientType( | |
|
satorux1
2014/08/07 20:00:05
function comment is missing.
zel
2014/08/07 21:40:44
Done.
| |
| 570 const std::string& client_type); | |
| 571 | |
| 572 void ParseUnstubList(const std::string& unstub_list) { | |
|
satorux1
2014/08/07 20:00:05
function comment is missing.
zel
2014/08/07 21:40:45
Done.
| |
| 573 unstub_mask_ = 0; | |
| 574 std::vector<std::string> unstub_components; | |
| 575 base::SplitString(unstub_list, ',', &unstub_components); | |
| 576 for (std::vector<std::string>::const_iterator iter = | |
| 577 unstub_components.begin(); | |
| 578 iter != unstub_components.end(); ++iter) { | |
| 579 DBusClientBundle::DBusClientType client = GetDBusClientType(*iter); | |
| 580 if (client != DBusClientBundle::Unknown) { | |
| 581 LOG(WARNING) << "Unstubbing dbus client for " << *iter; | |
| 582 unstub_mask_ |= client; | |
|
satorux1
2014/08/07 20:00:05
instead of modifying unstub_mask_ directly, return
zel
2014/08/07 23:16:17
Done.
| |
| 583 } | |
| 584 } | |
| 585 | |
| 586 // We should have something parsed correctly here. | |
| 587 if (unstub_mask_ == 0) { | |
| 588 LOG(FATAL) << "Switch values for --" | |
| 589 << chromeos::switches::kDbusUnstubClients | |
| 590 << " cannot be parsed: " | |
| 591 << unstub_list; | |
| 592 } | |
| 593 } | |
| 594 | |
| 595 // DBusThreadManager overrides. | |
| 596 virtual void AddObserver(DBusThreadManagerObserver* observer) OVERRIDE { | |
| 597 real_thread_manager_->AddObserver(observer); | |
| 598 } | |
| 599 | |
| 600 virtual void RemoveObserver(DBusThreadManagerObserver* observer) OVERRIDE { | |
| 601 real_thread_manager_->RemoveObserver(observer); | |
| 602 } | |
| 603 | |
| 604 virtual dbus::Bus* GetSystemBus() OVERRIDE { | |
| 605 return real_thread_manager_->GetSystemBus(); | |
| 606 } | |
| 607 | |
| 608 virtual BluetoothAdapterClient* GetBluetoothAdapterClient() OVERRIDE { | |
| 609 return GetThreadManager( | |
| 610 DBusClientBundle::Bluetooth)->GetBluetoothAdapterClient(); | |
| 611 } | |
| 612 | |
| 613 virtual BluetoothAgentManagerClient* | |
| 614 GetBluetoothAgentManagerClient() OVERRIDE { | |
| 615 return GetThreadManager( | |
| 616 DBusClientBundle::Bluetooth)->GetBluetoothAgentManagerClient(); | |
| 617 } | |
| 618 | |
| 619 virtual BluetoothDeviceClient* GetBluetoothDeviceClient() OVERRIDE { | |
| 620 return GetThreadManager( | |
| 621 DBusClientBundle::Bluetooth)->GetBluetoothDeviceClient(); | |
| 622 } | |
| 623 | |
| 624 virtual BluetoothGattCharacteristicClient* | |
| 625 GetBluetoothGattCharacteristicClient() OVERRIDE { | |
| 626 return GetThreadManager( | |
| 627 DBusClientBundle::Bluetooth)->GetBluetoothGattCharacteristicClient(); | |
| 628 } | |
| 629 | |
| 630 virtual BluetoothGattDescriptorClient* | |
| 631 GetBluetoothGattDescriptorClient() OVERRIDE { | |
| 632 return GetThreadManager(DBusClientBundle::BluetoothLowEnergy)-> | |
| 633 GetBluetoothGattDescriptorClient(); | |
| 634 } | |
| 635 | |
| 636 virtual BluetoothGattManagerClient* GetBluetoothGattManagerClient() OVERRIDE { | |
| 637 return GetThreadManager( | |
| 638 DBusClientBundle::BluetoothLowEnergy)->GetBluetoothGattManagerClient(); | |
| 639 } | |
| 640 | |
| 641 virtual BluetoothGattServiceClient* GetBluetoothGattServiceClient() OVERRIDE { | |
| 642 return GetThreadManager( | |
| 643 DBusClientBundle::BluetoothLowEnergy)->GetBluetoothGattServiceClient(); | |
| 644 } | |
| 645 | |
| 646 virtual BluetoothInputClient* GetBluetoothInputClient() OVERRIDE { | |
| 647 return GetThreadManager( | |
| 648 DBusClientBundle::Bluetooth)->GetBluetoothInputClient(); | |
| 649 } | |
| 650 | |
| 651 virtual BluetoothProfileManagerClient* | |
| 652 GetBluetoothProfileManagerClient() OVERRIDE { | |
| 653 return GetThreadManager( | |
| 654 DBusClientBundle::Bluetooth)->GetBluetoothProfileManagerClient(); | |
| 655 } | |
| 656 | |
| 657 virtual CrasAudioClient* GetCrasAudioClient() OVERRIDE { | |
| 658 return GetThreadManager( | |
| 659 DBusClientBundle::Cras)->GetCrasAudioClient(); | |
| 660 } | |
| 661 | |
| 662 virtual CrosDisksClient* GetCrosDisksClient() OVERRIDE { | |
| 663 return GetThreadManager(DBusClientBundle::CrosDisks)->GetCrosDisksClient(); | |
| 664 } | |
| 665 | |
| 666 virtual CryptohomeClient* GetCryptohomeClient() OVERRIDE { | |
| 667 return GetThreadManager( | |
| 668 DBusClientBundle::Cryptohome)->GetCryptohomeClient(); | |
| 669 } | |
| 670 | |
| 671 virtual DebugDaemonClient* GetDebugDaemonClient() OVERRIDE { | |
| 672 return GetThreadManager( | |
| 673 DBusClientBundle::DebugDaemon)->GetDebugDaemonClient(); | |
| 674 } | |
| 675 | |
| 676 virtual EasyUnlockClient* GetEasyUnlockClient() OVERRIDE { | |
| 677 return GetThreadManager( | |
| 678 DBusClientBundle::EasyUnlock)->GetEasyUnlockClient(); | |
| 679 } | |
| 680 | |
| 681 virtual LorgnetteManagerClient* GetLorgnetteManagerClient() OVERRIDE { | |
| 682 return GetThreadManager( | |
| 683 DBusClientBundle::LorgnetteManager)->GetLorgnetteManagerClient(); | |
| 684 } | |
| 685 | |
| 686 virtual ShillDeviceClient* GetShillDeviceClient() OVERRIDE { | |
| 687 return GetThreadManager(DBusClientBundle::Shill)->GetShillDeviceClient(); | |
| 688 } | |
| 689 | |
| 690 virtual ShillIPConfigClient* GetShillIPConfigClient() OVERRIDE { | |
| 691 return GetThreadManager(DBusClientBundle::Shill)->GetShillIPConfigClient(); | |
| 692 } | |
| 693 | |
| 694 virtual ShillManagerClient* GetShillManagerClient() OVERRIDE { | |
| 695 return GetThreadManager(DBusClientBundle::Shill)->GetShillManagerClient(); | |
| 696 } | |
| 697 | |
| 698 virtual ShillProfileClient* GetShillProfileClient() OVERRIDE { | |
| 699 return GetThreadManager(DBusClientBundle::Shill)->GetShillProfileClient(); | |
| 700 } | |
| 701 | |
| 702 virtual ShillServiceClient* GetShillServiceClient() OVERRIDE { | |
| 703 return GetThreadManager(DBusClientBundle::Shill)->GetShillServiceClient(); | |
| 704 } | |
| 705 | |
| 706 virtual GsmSMSClient* GetGsmSMSClient() OVERRIDE { | |
| 707 return GetThreadManager(DBusClientBundle::GsmSMS)->GetGsmSMSClient(); | |
| 708 } | |
| 709 | |
| 710 virtual ImageBurnerClient* GetImageBurnerClient() OVERRIDE { | |
| 711 return GetThreadManager( | |
| 712 DBusClientBundle::ImageBurner)->GetImageBurnerClient(); | |
| 713 } | |
| 714 | |
| 715 virtual IntrospectableClient* GetIntrospectableClient() OVERRIDE { | |
| 716 return GetThreadManager( | |
| 717 DBusClientBundle::ImageBurner)->GetIntrospectableClient(); | |
| 718 } | |
| 719 | |
| 720 virtual ModemMessagingClient* GetModemMessagingClient() OVERRIDE { | |
| 721 return GetThreadManager( | |
| 722 DBusClientBundle::ModemMessaging)->GetModemMessagingClient(); | |
| 723 } | |
| 724 | |
| 725 virtual NfcAdapterClient* GetNfcAdapterClient() OVERRIDE { | |
| 726 return GetThreadManager(DBusClientBundle::Nfc)->GetNfcAdapterClient(); | |
| 727 } | |
| 728 | |
| 729 virtual NfcDeviceClient* GetNfcDeviceClient() OVERRIDE { | |
| 730 return GetThreadManager(DBusClientBundle::Nfc)->GetNfcDeviceClient(); | |
| 731 } | |
| 732 | |
| 733 virtual NfcManagerClient* GetNfcManagerClient() OVERRIDE { | |
| 734 return GetThreadManager(DBusClientBundle::Nfc)->GetNfcManagerClient(); | |
| 735 } | |
| 736 | |
| 737 virtual NfcRecordClient* GetNfcRecordClient() OVERRIDE { | |
| 738 return GetThreadManager(DBusClientBundle::Nfc)->GetNfcRecordClient(); | |
| 739 } | |
| 740 | |
| 741 virtual NfcTagClient* GetNfcTagClient() OVERRIDE { | |
| 742 return GetThreadManager(DBusClientBundle::Nfc)->GetNfcTagClient(); | |
| 743 } | |
| 744 | |
| 745 virtual PermissionBrokerClient* GetPermissionBrokerClient() OVERRIDE { | |
| 746 return GetThreadManager( | |
| 747 DBusClientBundle::PermissionBroker)->GetPermissionBrokerClient(); | |
| 748 } | |
| 749 | |
| 750 virtual PowerManagerClient* GetPowerManagerClient() OVERRIDE { | |
| 751 return GetThreadManager( | |
| 752 DBusClientBundle::PowerManager)->GetPowerManagerClient(); | |
| 753 } | |
| 754 | |
| 755 virtual PowerPolicyController* GetPowerPolicyController() OVERRIDE { | |
| 756 return GetThreadManager( | |
| 757 DBusClientBundle::PowerPolicy)->GetPowerPolicyController(); | |
| 758 } | |
| 759 | |
| 760 virtual SessionManagerClient* GetSessionManagerClient() OVERRIDE { | |
| 761 return GetThreadManager( | |
| 762 DBusClientBundle::SessionManager)->GetSessionManagerClient(); | |
| 763 } | |
| 764 | |
| 765 virtual SMSClient* GetSMSClient() OVERRIDE { | |
| 766 return GetThreadManager(DBusClientBundle::SMS)->GetSMSClient(); | |
| 767 } | |
| 768 | |
| 769 virtual SystemClockClient* GetSystemClockClient() OVERRIDE { | |
| 770 return GetThreadManager( | |
| 771 DBusClientBundle::SystemClock)->GetSystemClockClient(); | |
| 772 } | |
| 773 | |
| 774 virtual UpdateEngineClient* GetUpdateEngineClient() OVERRIDE { | |
| 775 return GetThreadManager( | |
| 776 DBusClientBundle::UpdateEngine)->GetUpdateEngineClient(); | |
| 777 } | |
| 778 | |
| 779 private: | |
| 780 DBusThreadManager* GetThreadManager(DBusClientBundle::DBusClientType client) { | |
| 781 if (unstub_mask_ & client) | |
| 782 return real_thread_manager_.get(); | |
| 783 | |
| 784 return fake_thread_manager_.get(); | |
| 785 } | |
| 786 | |
| 787 scoped_ptr<DBusThreadManager> fake_thread_manager_; | |
| 788 scoped_ptr<DBusThreadManager> real_thread_manager_; | |
| 789 int unstub_mask_; | |
| 790 | |
| 791 DISALLOW_COPY_AND_ASSIGN(MixedDBusThreadManager); | |
| 792 }; | |
| 793 | |
| 794 // Command line switch mapping for --dbus-unstub-clients. | |
| 795 struct { | |
| 796 const char* param_name; | |
| 797 DBusClientBundle::DBusClientType client_type; | |
| 798 } client_type_map[] = { | |
| 799 { "bluetooth", DBusClientBundle::Bluetooth }, | |
| 800 { "bluetoothlowenergy", DBusClientBundle::BluetoothLowEnergy }, | |
| 801 { "cras", DBusClientBundle::Cras }, | |
| 802 { "crosdisks", DBusClientBundle::CrosDisks }, | |
| 803 { "cryptohome", DBusClientBundle::Cryptohome }, | |
| 804 { "debugdaemon", DBusClientBundle::DebugDaemon }, | |
| 805 { "easyunlock", DBusClientBundle::EasyUnlock }, | |
| 806 { "lorgnettemanager", DBusClientBundle::LorgnetteManager }, | |
| 807 { "shill", DBusClientBundle::Shill }, | |
| 808 { "gsmsms", DBusClientBundle::GsmSMS }, | |
| 809 { "imageburner", DBusClientBundle::ImageBurner }, | |
| 810 { "introspectable", DBusClientBundle::Introspectable }, | |
| 811 { "modemmessaging", DBusClientBundle::ModemMessaging }, | |
| 812 { "nfc", DBusClientBundle::Nfc }, | |
| 813 { "permissionbroker", DBusClientBundle::PermissionBroker }, | |
| 814 { "powermanager", DBusClientBundle::PowerManager }, | |
| 815 { "powerpolicy", DBusClientBundle::PowerPolicy }, | |
| 816 { "sessionmanager", DBusClientBundle::SessionManager }, | |
| 817 { "sms", DBusClientBundle::SMS }, | |
| 818 { "systemclock", DBusClientBundle::SystemClock }, | |
| 819 { "updateengine", DBusClientBundle::UpdateEngine }, | |
| 820 }; | |
| 821 | |
|
stevenjb
2014/08/07 20:20:31
This class is large enough that we should really p
zel
2014/08/07 21:40:44
so does DBusClientBundle... done.
| |
| 822 // static | |
| 823 DBusClientBundle::DBusClientType | |
| 824 MixedDBusThreadManager::GetDBusClientType(const std::string& client_type) { | |
|
stevenjb
2014/08/07 20:20:31
This looks like it could just be a local helper fu
| |
| 825 for (size_t i = 0; i < arraysize(client_type_map); i++) { | |
| 826 if (LowerCaseEqualsASCII(client_type, client_type_map[i].param_name)) | |
| 827 return client_type_map[i].client_type; | |
| 828 } | |
| 829 return DBusClientBundle::Unknown; | |
| 830 } | |
| 831 | |
| 832 | |
| 481 // static | 833 // static |
| 482 void DBusThreadManager::Initialize() { | 834 void DBusThreadManager::Initialize() { |
| 483 // If we initialize DBusThreadManager twice we may also be shutting it down | 835 // If we initialize DBusThreadManager twice we may also be shutting it down |
| 484 // early; do not allow that. | 836 // early; do not allow that. |
| 485 CHECK(g_dbus_thread_manager == NULL); | 837 CHECK(g_dbus_thread_manager == NULL); |
| 486 | 838 |
| 487 if (g_dbus_thread_manager_for_testing) { | 839 if (g_dbus_thread_manager_for_testing) { |
| 488 g_dbus_thread_manager = g_dbus_thread_manager_for_testing; | 840 g_dbus_thread_manager = g_dbus_thread_manager_for_testing; |
| 489 InitializeClients(); | 841 InitializeClients(); |
| 490 VLOG(1) << "DBusThreadManager initialized with test implementation"; | 842 VLOG(1) << "DBusThreadManager initialized with test implementation"; |
| 491 return; | 843 return; |
| 492 } | 844 } |
| 493 | 845 |
| 846 bool use_dbus_stub = !base::SysInfo::IsRunningOnChromeOS() || | |
| 847 CommandLine::ForCurrentProcess()->HasSwitch( | |
| 848 chromeos::switches::kDbusStub); | |
| 849 bool force_bluetooth_client = CommandLine::ForCurrentProcess()->HasSwitch( | |
|
satorux1
2014/08/07 20:00:05
force_bluetooth_client -> unstub_clients ?
zel
2014/08/07 21:40:44
Done.
| |
| 850 chromeos::switches::kDbusUnstubClients); | |
| 494 // Determine whether we use stub or real client implementations. | 851 // Determine whether we use stub or real client implementations. |
| 495 if (!base::SysInfo::IsRunningOnChromeOS() || | 852 if (!use_dbus_stub || force_bluetooth_client) { |
| 496 CommandLine::ForCurrentProcess()->HasSwitch( | 853 if (!use_dbus_stub) { |
|
satorux1
2014/08/07 20:00:05
slightly easier to read with:
if (unstub_clients)
zel
2014/08/07 21:40:44
Done.
| |
| 497 chromeos::switches::kDbusStub)) { | 854 g_dbus_thread_manager = new DBusThreadManagerImpl(DBusClientBundle::All); |
| 855 InitializeClients(); | |
| 856 VLOG(1) << "DBusThreadManager initialized for Chrome OS"; | |
| 857 } else { | |
| 858 InitializeWithPartialStub( | |
| 859 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 860 chromeos::switches::kDbusUnstubClients)); | |
| 861 } | |
| 862 } else { | |
| 498 InitializeWithStub(); | 863 InitializeWithStub(); |
| 499 } else { | |
| 500 g_dbus_thread_manager = new DBusThreadManagerImpl; | |
| 501 InitializeClients(); | |
| 502 VLOG(1) << "DBusThreadManager initialized for Chrome OS"; | |
| 503 } | 864 } |
| 504 } | 865 } |
| 505 | 866 |
| 506 // static | 867 // static |
| 507 void DBusThreadManager::SetInstanceForTesting( | 868 void DBusThreadManager::SetInstanceForTesting( |
| 508 DBusThreadManager* dbus_thread_manager) { | 869 DBusThreadManager* dbus_thread_manager) { |
| 509 CHECK(!g_dbus_thread_manager); | 870 CHECK(!g_dbus_thread_manager); |
| 510 CHECK(!g_dbus_thread_manager_for_testing); | 871 CHECK(!g_dbus_thread_manager_for_testing); |
| 511 g_dbus_thread_manager_for_testing = dbus_thread_manager; | 872 g_dbus_thread_manager_for_testing = dbus_thread_manager; |
| 512 } | 873 } |
| 513 | 874 |
| 514 // static | 875 // static |
| 515 void DBusThreadManager::InitializeForTesting( | 876 void DBusThreadManager::InitializeForTesting( |
| 516 DBusThreadManager* dbus_thread_manager) { | 877 DBusThreadManager* dbus_thread_manager) { |
| 517 SetInstanceForTesting(dbus_thread_manager); | 878 SetInstanceForTesting(dbus_thread_manager); |
| 518 Initialize(); | 879 Initialize(); |
| 519 } | 880 } |
| 520 | 881 |
| 521 // static | 882 // static |
| 883 void DBusThreadManager::InitializeWithPartialStub( | |
| 884 const std::string& unstub_clients) { | |
| 885 // If we initialize DBusThreadManager twice we may also be shutting it down | |
| 886 // early; do not allow that. | |
| 887 CHECK(g_dbus_thread_manager == NULL); | |
| 888 | |
| 889 VLOG(1) << "DBusThreadManager initialized for mixed runtime environment"; | |
| 890 g_dbus_thread_manager = new MixedDBusThreadManager(unstub_clients); | |
| 891 InitializeClients(); | |
| 892 } | |
| 893 | |
| 894 // static | |
| 522 void DBusThreadManager::InitializeWithStub() { | 895 void DBusThreadManager::InitializeWithStub() { |
| 523 // If we initialize DBusThreadManager twice we may also be shutting it down | 896 // If we initialize DBusThreadManager twice we may also be shutting it down |
| 524 // early; do not allow that. | 897 // early; do not allow that. |
| 525 CHECK(g_dbus_thread_manager == NULL); | 898 CHECK(g_dbus_thread_manager == NULL); |
| 526 FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager; | 899 FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager; |
| 527 fake_dbus_thread_manager->SetFakeClients(); | 900 fake_dbus_thread_manager->SetFakeClients(); |
| 528 g_dbus_thread_manager = fake_dbus_thread_manager; | 901 g_dbus_thread_manager = fake_dbus_thread_manager; |
| 529 InitializeClients(); | 902 InitializeClients(); |
| 530 fake_dbus_thread_manager->SetupDefaultEnvironment(); | 903 fake_dbus_thread_manager->SetupDefaultEnvironment(); |
| 531 VLOG(1) << "DBusThreadManager initialized with stub implementation"; | 904 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(); | 1002 g_dbus_thread_manager->GetSystemBus()->GetManagedObjects(); |
| 630 } | 1003 } |
| 631 | 1004 |
| 632 // static | 1005 // static |
| 633 void DBusThreadManager::InitClient(DBusClient* client) { | 1006 void DBusThreadManager::InitClient(DBusClient* client) { |
| 634 if (client) | 1007 if (client) |
| 635 client->Init(g_dbus_thread_manager->GetSystemBus()); | 1008 client->Init(g_dbus_thread_manager->GetSystemBus()); |
| 636 } | 1009 } |
| 637 | 1010 |
| 638 } // namespace chromeos | 1011 } // namespace chromeos |
| OLD | NEW |