Home | History | Annotate | Download | only in dbus
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chromeos/dbus/dbus_thread_manager.h"
      6 
      7 #include <map>
      8 
      9 #include "base/command_line.h"
     10 #include "base/observer_list.h"
     11 #include "base/sys_info.h"
     12 #include "base/threading/thread.h"
     13 #include "chromeos/chromeos_switches.h"
     14 #include "chromeos/dbus/bluetooth_adapter_client.h"
     15 #include "chromeos/dbus/bluetooth_agent_manager_client.h"
     16 #include "chromeos/dbus/bluetooth_device_client.h"
     17 #include "chromeos/dbus/bluetooth_input_client.h"
     18 #include "chromeos/dbus/bluetooth_profile_manager_client.h"
     19 #include "chromeos/dbus/cras_audio_client.h"
     20 #include "chromeos/dbus/cros_disks_client.h"
     21 #include "chromeos/dbus/cryptohome_client.h"
     22 #include "chromeos/dbus/dbus_client.h"
     23 #include "chromeos/dbus/dbus_thread_manager_observer.h"
     24 #include "chromeos/dbus/debug_daemon_client.h"
     25 #include "chromeos/dbus/fake_dbus_thread_manager.h"
     26 #include "chromeos/dbus/gsm_sms_client.h"
     27 #include "chromeos/dbus/image_burner_client.h"
     28 #include "chromeos/dbus/introspectable_client.h"
     29 #include "chromeos/dbus/modem_messaging_client.h"
     30 #include "chromeos/dbus/nfc_adapter_client.h"
     31 #include "chromeos/dbus/nfc_device_client.h"
     32 #include "chromeos/dbus/nfc_manager_client.h"
     33 #include "chromeos/dbus/nfc_record_client.h"
     34 #include "chromeos/dbus/nfc_tag_client.h"
     35 #include "chromeos/dbus/permission_broker_client.h"
     36 #include "chromeos/dbus/power_manager_client.h"
     37 #include "chromeos/dbus/power_policy_controller.h"
     38 #include "chromeos/dbus/session_manager_client.h"
     39 #include "chromeos/dbus/shill_device_client.h"
     40 #include "chromeos/dbus/shill_ipconfig_client.h"
     41 #include "chromeos/dbus/shill_manager_client.h"
     42 #include "chromeos/dbus/shill_profile_client.h"
     43 #include "chromeos/dbus/shill_service_client.h"
     44 #include "chromeos/dbus/shill_stub_helper.h"
     45 #include "chromeos/dbus/sms_client.h"
     46 #include "chromeos/dbus/system_clock_client.h"
     47 #include "chromeos/dbus/update_engine_client.h"
     48 #include "dbus/bus.h"
     49 #include "dbus/dbus_statistics.h"
     50 
     51 namespace chromeos {
     52 
     53 static DBusThreadManager* g_dbus_thread_manager = NULL;
     54 static DBusThreadManager* g_dbus_thread_manager_for_testing = NULL;
     55 
     56 // The bundle of all D-Bus clients used in DBusThreadManagerImpl. The bundle
     57 // is used to delete them at once in the right order before shutting down the
     58 // system bus. See also the comment in the destructor of DBusThreadManagerImpl.
     59 class DBusClientBundle {
     60  public:
     61   DBusClientBundle() {
     62     DBusClientImplementationType client_type = REAL_DBUS_CLIENT_IMPLEMENTATION;
     63     DBusClientImplementationType client_type_override = client_type;
     64     // If --dbus-stub was requested, pass STUB to specific components;
     65     // Many components like login are not useful with a stub implementation.
     66     if (CommandLine::ForCurrentProcess()->HasSwitch(
     67             chromeos::switches::kDbusStub)) {
     68       client_type_override = STUB_DBUS_CLIENT_IMPLEMENTATION;
     69     }
     70 
     71     bluetooth_adapter_client_.reset(BluetoothAdapterClient::Create());
     72     bluetooth_agent_manager_client_.reset(
     73         BluetoothAgentManagerClient::Create());
     74     bluetooth_device_client_.reset(BluetoothDeviceClient::Create());
     75     bluetooth_input_client_.reset(BluetoothInputClient::Create());
     76     bluetooth_profile_manager_client_.reset(
     77         BluetoothProfileManagerClient::Create());
     78     cras_audio_client_.reset(CrasAudioClient::Create());
     79     cros_disks_client_.reset(CrosDisksClient::Create(client_type));
     80     cryptohome_client_.reset(CryptohomeClient::Create());
     81     debug_daemon_client_.reset(DebugDaemonClient::Create());
     82     shill_manager_client_.reset(ShillManagerClient::Create());
     83     shill_device_client_.reset(ShillDeviceClient::Create());
     84     shill_ipconfig_client_.reset(ShillIPConfigClient::Create());
     85     shill_service_client_.reset(ShillServiceClient::Create());
     86     shill_profile_client_.reset(ShillProfileClient::Create());
     87     gsm_sms_client_.reset(GsmSMSClient::Create());
     88     image_burner_client_.reset(ImageBurnerClient::Create());
     89     introspectable_client_.reset(IntrospectableClient::Create());
     90     modem_messaging_client_.reset(ModemMessagingClient::Create());
     91     // Create the NFC clients in the correct order based on their dependencies.
     92     nfc_manager_client_.reset(NfcManagerClient::Create());
     93     nfc_adapter_client_.reset(
     94         NfcAdapterClient::Create(nfc_manager_client_.get()));
     95     nfc_device_client_.reset(
     96         NfcDeviceClient::Create(nfc_adapter_client_.get()));
     97     nfc_tag_client_.reset(NfcTagClient::Create(nfc_adapter_client_.get()));
     98     nfc_record_client_.reset(NfcRecordClient::Create(nfc_device_client_.get(),
     99                                                     nfc_tag_client_.get()));
    100     permission_broker_client_.reset(PermissionBrokerClient::Create());
    101     power_manager_client_.reset(
    102         PowerManagerClient::Create(client_type_override));
    103     session_manager_client_.reset(SessionManagerClient::Create(client_type));
    104     sms_client_.reset(SMSClient::Create());
    105     system_clock_client_.reset(SystemClockClient::Create());
    106     update_engine_client_.reset(UpdateEngineClient::Create(client_type));
    107   }
    108 
    109   BluetoothAdapterClient* bluetooth_adapter_client() {
    110     return bluetooth_adapter_client_.get();
    111   }
    112   BluetoothAgentManagerClient* bluetooth_agent_manager_client() {
    113     return bluetooth_agent_manager_client_.get();
    114   }
    115   BluetoothDeviceClient* bluetooth_device_client() {
    116     return bluetooth_device_client_.get();
    117   }
    118   BluetoothInputClient* bluetooth_input_client() {
    119     return bluetooth_input_client_.get();
    120   }
    121   BluetoothProfileManagerClient* bluetooth_profile_manager_client() {
    122     return bluetooth_profile_manager_client_.get();
    123   }
    124   CrasAudioClient* cras_audio_client() {
    125     return cras_audio_client_.get();
    126   }
    127   CrosDisksClient* cros_disks_client() {
    128     return cros_disks_client_.get();
    129   }
    130   CryptohomeClient* cryptohome_client() {
    131     return cryptohome_client_.get();
    132   }
    133   DebugDaemonClient* debug_daemon_client() {
    134     return debug_daemon_client_.get();
    135   }
    136   ShillDeviceClient* shill_device_client() {
    137     return shill_device_client_.get();
    138   }
    139   ShillIPConfigClient* shill_ipconfig_client() {
    140     return shill_ipconfig_client_.get();
    141   }
    142   ShillManagerClient* shill_manager_client() {
    143     return shill_manager_client_.get();
    144   }
    145   ShillServiceClient* shill_service_client() {
    146     return shill_service_client_.get();
    147   }
    148   ShillProfileClient* shill_profile_client() {
    149     return shill_profile_client_.get();
    150   }
    151   GsmSMSClient* gsm_sms_client() {
    152     return gsm_sms_client_.get();
    153   }
    154   ImageBurnerClient* image_burner_client() {
    155     return image_burner_client_.get();
    156   }
    157   IntrospectableClient* introspectable_client() {
    158     return introspectable_client_.get();
    159   }
    160   ModemMessagingClient* modem_messaging_client() {
    161     return modem_messaging_client_.get();
    162   }
    163   NfcManagerClient* nfc_manager_client() {
    164     return nfc_manager_client_.get();
    165   }
    166   NfcAdapterClient* nfc_adapter_client() {
    167     return nfc_adapter_client_.get();
    168   }
    169   NfcDeviceClient* nfc_device_client() {
    170     return nfc_device_client_.get();
    171   }
    172   NfcTagClient* nfc_tag_client() {
    173     return nfc_tag_client_.get();
    174   }
    175   NfcRecordClient* nfc_record_client() {
    176     return nfc_record_client_.get();
    177   }
    178   PermissionBrokerClient* permission_broker_client() {
    179     return permission_broker_client_.get();
    180   }
    181   SystemClockClient* system_clock_client() {
    182     return system_clock_client_.get();
    183   }
    184   PowerManagerClient* power_manager_client() {
    185     return power_manager_client_.get();
    186   }
    187   SessionManagerClient* session_manager_client() {
    188     return session_manager_client_.get();
    189   }
    190   SMSClient* sms_client() {
    191     return sms_client_.get();
    192   }
    193   UpdateEngineClient* update_engine_client() {
    194     return update_engine_client_.get();
    195   }
    196 
    197  private:
    198   scoped_ptr<BluetoothAdapterClient> bluetooth_adapter_client_;
    199   scoped_ptr<BluetoothAgentManagerClient> bluetooth_agent_manager_client_;
    200   scoped_ptr<BluetoothDeviceClient> bluetooth_device_client_;
    201   scoped_ptr<BluetoothInputClient> bluetooth_input_client_;
    202   scoped_ptr<BluetoothProfileManagerClient> bluetooth_profile_manager_client_;
    203   scoped_ptr<CrasAudioClient> cras_audio_client_;
    204   scoped_ptr<CrosDisksClient> cros_disks_client_;
    205   scoped_ptr<CryptohomeClient> cryptohome_client_;
    206   scoped_ptr<DebugDaemonClient> debug_daemon_client_;
    207   scoped_ptr<ShillDeviceClient> shill_device_client_;
    208   scoped_ptr<ShillIPConfigClient> shill_ipconfig_client_;
    209   scoped_ptr<ShillManagerClient> shill_manager_client_;
    210   scoped_ptr<ShillServiceClient> shill_service_client_;
    211   scoped_ptr<ShillProfileClient> shill_profile_client_;
    212   scoped_ptr<GsmSMSClient> gsm_sms_client_;
    213   scoped_ptr<ImageBurnerClient> image_burner_client_;
    214   scoped_ptr<IntrospectableClient> introspectable_client_;
    215   scoped_ptr<ModemMessagingClient> modem_messaging_client_;
    216   // The declaration order for NFC client objects is important. See
    217   // DBusThreadManager::CreateDefaultClients for the dependencies.
    218   scoped_ptr<NfcManagerClient> nfc_manager_client_;
    219   scoped_ptr<NfcAdapterClient> nfc_adapter_client_;
    220   scoped_ptr<NfcDeviceClient> nfc_device_client_;
    221   scoped_ptr<NfcTagClient> nfc_tag_client_;
    222   scoped_ptr<NfcRecordClient> nfc_record_client_;
    223   scoped_ptr<PermissionBrokerClient> permission_broker_client_;
    224   scoped_ptr<SystemClockClient> system_clock_client_;
    225   scoped_ptr<PowerManagerClient> power_manager_client_;
    226   scoped_ptr<SessionManagerClient> session_manager_client_;
    227   scoped_ptr<SMSClient> sms_client_;
    228   scoped_ptr<UpdateEngineClient> update_engine_client_;
    229 
    230   DISALLOW_COPY_AND_ASSIGN(DBusClientBundle);
    231 };
    232 
    233 // The DBusThreadManager implementation used in production.
    234 class DBusThreadManagerImpl : public DBusThreadManager {
    235  public:
    236   explicit DBusThreadManagerImpl() {
    237     // Create the D-Bus thread.
    238     base::Thread::Options thread_options;
    239     thread_options.message_loop_type = base::MessageLoop::TYPE_IO;
    240     dbus_thread_.reset(new base::Thread("D-Bus thread"));
    241     dbus_thread_->StartWithOptions(thread_options);
    242 
    243     // Create the connection to the system bus.
    244     dbus::Bus::Options system_bus_options;
    245     system_bus_options.bus_type = dbus::Bus::SYSTEM;
    246     system_bus_options.connection_type = dbus::Bus::PRIVATE;
    247     system_bus_options.dbus_task_runner = dbus_thread_->message_loop_proxy();
    248     system_bus_ = new dbus::Bus(system_bus_options);
    249 
    250     CreateDefaultClients();
    251   }
    252 
    253   virtual ~DBusThreadManagerImpl() {
    254     FOR_EACH_OBSERVER(DBusThreadManagerObserver, observers_,
    255                       OnDBusThreadManagerDestroying(this));
    256 
    257     // PowerPolicyController's destructor depends on PowerManagerClient.
    258     power_policy_controller_.reset();
    259 
    260     // Delete all D-Bus clients before shutting down the system bus.
    261     client_bundle_.reset();
    262 
    263     // Shut down the bus. During the browser shutdown, it's ok to shut down
    264     // the bus synchronously.
    265     system_bus_->ShutdownOnDBusThreadAndBlock();
    266 
    267     // Stop the D-Bus thread.
    268     dbus_thread_->Stop();
    269   }
    270 
    271   // DBusThreadManager overrides:
    272   virtual void AddObserver(DBusThreadManagerObserver* observer) OVERRIDE {
    273     DCHECK(observer);
    274     observers_.AddObserver(observer);
    275   }
    276 
    277   virtual void RemoveObserver(DBusThreadManagerObserver* observer) OVERRIDE {
    278     DCHECK(observer);
    279     observers_.RemoveObserver(observer);
    280   }
    281 
    282   virtual dbus::Bus* GetSystemBus() OVERRIDE {
    283     return system_bus_.get();
    284   }
    285 
    286   virtual BluetoothAdapterClient* GetBluetoothAdapterClient() OVERRIDE {
    287     return client_bundle_->bluetooth_adapter_client();
    288   }
    289 
    290   virtual BluetoothAgentManagerClient* GetBluetoothAgentManagerClient()
    291       OVERRIDE {
    292     return client_bundle_->bluetooth_agent_manager_client();
    293   }
    294 
    295   virtual BluetoothDeviceClient* GetBluetoothDeviceClient() OVERRIDE {
    296     return client_bundle_->bluetooth_device_client();
    297   }
    298 
    299   virtual BluetoothInputClient* GetBluetoothInputClient() OVERRIDE {
    300     return client_bundle_->bluetooth_input_client();
    301   }
    302 
    303   virtual BluetoothProfileManagerClient* GetBluetoothProfileManagerClient()
    304       OVERRIDE {
    305     return client_bundle_->bluetooth_profile_manager_client();
    306   }
    307 
    308   virtual CrasAudioClient* GetCrasAudioClient() OVERRIDE {
    309     return client_bundle_->cras_audio_client();
    310   }
    311 
    312   virtual CrosDisksClient* GetCrosDisksClient() OVERRIDE {
    313     return client_bundle_->cros_disks_client();
    314   }
    315 
    316   virtual CryptohomeClient* GetCryptohomeClient() OVERRIDE {
    317     return client_bundle_->cryptohome_client();
    318   }
    319 
    320   virtual DebugDaemonClient* GetDebugDaemonClient() OVERRIDE {
    321     return client_bundle_->debug_daemon_client();
    322   }
    323 
    324   virtual ShillDeviceClient* GetShillDeviceClient() OVERRIDE {
    325     return client_bundle_->shill_device_client();
    326   }
    327 
    328   virtual ShillIPConfigClient* GetShillIPConfigClient() OVERRIDE {
    329     return client_bundle_->shill_ipconfig_client();
    330   }
    331 
    332   virtual ShillManagerClient* GetShillManagerClient() OVERRIDE {
    333     return client_bundle_->shill_manager_client();
    334   }
    335 
    336   virtual ShillServiceClient* GetShillServiceClient() OVERRIDE {
    337     return client_bundle_->shill_service_client();
    338   }
    339 
    340   virtual ShillProfileClient* GetShillProfileClient() OVERRIDE {
    341     return client_bundle_->shill_profile_client();
    342   }
    343 
    344   virtual GsmSMSClient* GetGsmSMSClient() OVERRIDE {
    345     return client_bundle_->gsm_sms_client();
    346   }
    347 
    348   virtual ImageBurnerClient* GetImageBurnerClient() OVERRIDE {
    349     return client_bundle_->image_burner_client();
    350   }
    351 
    352   virtual IntrospectableClient* GetIntrospectableClient() OVERRIDE {
    353     return client_bundle_->introspectable_client();
    354   }
    355 
    356   virtual ModemMessagingClient* GetModemMessagingClient() OVERRIDE {
    357     return client_bundle_->modem_messaging_client();
    358   }
    359 
    360   virtual NfcAdapterClient* GetNfcAdapterClient() OVERRIDE {
    361     return client_bundle_->nfc_adapter_client();
    362   }
    363 
    364   virtual NfcDeviceClient* GetNfcDeviceClient() OVERRIDE {
    365     return client_bundle_->nfc_device_client();
    366   }
    367 
    368   virtual NfcManagerClient* GetNfcManagerClient() OVERRIDE {
    369     return client_bundle_->nfc_manager_client();
    370   }
    371 
    372   virtual NfcRecordClient* GetNfcRecordClient() OVERRIDE {
    373     return client_bundle_->nfc_record_client();
    374   }
    375 
    376   virtual NfcTagClient* GetNfcTagClient() OVERRIDE {
    377     return client_bundle_->nfc_tag_client();
    378   }
    379 
    380   virtual PermissionBrokerClient* GetPermissionBrokerClient() OVERRIDE {
    381     return client_bundle_->permission_broker_client();
    382   }
    383 
    384   virtual PowerManagerClient* GetPowerManagerClient() OVERRIDE {
    385     return client_bundle_->power_manager_client();
    386   }
    387 
    388   virtual SessionManagerClient* GetSessionManagerClient() OVERRIDE {
    389     return client_bundle_->session_manager_client();
    390   }
    391 
    392   virtual SMSClient* GetSMSClient() OVERRIDE {
    393     return client_bundle_->sms_client();
    394   }
    395 
    396   virtual SystemClockClient* GetSystemClockClient() OVERRIDE {
    397     return client_bundle_->system_clock_client();
    398   }
    399 
    400   virtual UpdateEngineClient* GetUpdateEngineClient() OVERRIDE {
    401     return client_bundle_->update_engine_client();
    402   }
    403 
    404   virtual PowerPolicyController* GetPowerPolicyController() OVERRIDE {
    405     return power_policy_controller_.get();
    406   }
    407 
    408  private:
    409   // Constructs all clients and stores them in the respective *_client_ member
    410   // variable.
    411   void CreateDefaultClients() {
    412     client_bundle_.reset(new DBusClientBundle);
    413     power_policy_controller_.reset(new PowerPolicyController);
    414   }
    415 
    416   // Note: Keep this before other members so they can call AddObserver() in
    417   // their c'tors.
    418   ObserverList<DBusThreadManagerObserver> observers_;
    419 
    420   scoped_ptr<base::Thread> dbus_thread_;
    421   scoped_refptr<dbus::Bus> system_bus_;
    422   scoped_ptr<DBusClientBundle> client_bundle_;
    423   scoped_ptr<PowerPolicyController> power_policy_controller_;
    424 };
    425 
    426 // static
    427 void DBusThreadManager::Initialize() {
    428   // If we initialize DBusThreadManager twice we may also be shutting it down
    429   // early; do not allow that.
    430   CHECK(g_dbus_thread_manager == NULL);
    431 
    432   if (g_dbus_thread_manager_for_testing) {
    433     g_dbus_thread_manager = g_dbus_thread_manager_for_testing;
    434     InitializeClients();
    435     VLOG(1) << "DBusThreadManager initialized with test implementation";
    436     return;
    437   }
    438   // Determine whether we use stub or real client implementations.
    439   if (base::SysInfo::IsRunningOnChromeOS()) {
    440     g_dbus_thread_manager = new DBusThreadManagerImpl;
    441     InitializeClients();
    442     VLOG(1) << "DBusThreadManager initialized for ChromeOS";
    443   } else {
    444     InitializeWithStub();
    445   }
    446 }
    447 
    448 // static
    449 void DBusThreadManager::SetInstanceForTesting(
    450     DBusThreadManager* dbus_thread_manager) {
    451   CHECK(!g_dbus_thread_manager);
    452   CHECK(!g_dbus_thread_manager_for_testing);
    453   g_dbus_thread_manager_for_testing = dbus_thread_manager;
    454 }
    455 
    456 // static
    457 void DBusThreadManager::InitializeForTesting(
    458     DBusThreadManager* dbus_thread_manager) {
    459   SetInstanceForTesting(dbus_thread_manager);
    460   Initialize();
    461 }
    462 
    463 // static
    464 void DBusThreadManager::InitializeWithStub() {
    465   // If we initialize DBusThreadManager twice we may also be shutting it down
    466   // early; do not allow that.
    467   CHECK(g_dbus_thread_manager == NULL);
    468   FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager;
    469   fake_dbus_thread_manager->SetFakeClients();
    470   g_dbus_thread_manager = fake_dbus_thread_manager;
    471   InitializeClients();
    472   shill_stub_helper::SetupDefaultEnvironment();
    473   VLOG(1) << "DBusThreadManager initialized with stub implementation";
    474 }
    475 
    476 // static
    477 bool DBusThreadManager::IsInitialized() {
    478   return g_dbus_thread_manager != NULL;
    479 }
    480 
    481 // static
    482 void DBusThreadManager::Shutdown() {
    483   // If we called InitializeForTesting, this may get called more than once.
    484   // Ensure that we only shutdown DBusThreadManager once.
    485   CHECK(g_dbus_thread_manager || g_dbus_thread_manager_for_testing);
    486   DBusThreadManager* dbus_thread_manager = g_dbus_thread_manager;
    487   g_dbus_thread_manager = NULL;
    488   g_dbus_thread_manager_for_testing = NULL;
    489   delete dbus_thread_manager;
    490   VLOG(1) << "DBusThreadManager Shutdown completed";
    491 }
    492 
    493 DBusThreadManager::DBusThreadManager() {
    494   dbus::statistics::Initialize();
    495 }
    496 
    497 DBusThreadManager::~DBusThreadManager() {
    498   dbus::statistics::Shutdown();
    499   if (g_dbus_thread_manager == NULL)
    500     return;  // Called form Shutdown() or local test instance.
    501   // There should never be both a global instance and a local instance.
    502   CHECK(this == g_dbus_thread_manager);
    503   if (g_dbus_thread_manager_for_testing) {
    504     g_dbus_thread_manager = NULL;
    505     g_dbus_thread_manager_for_testing = NULL;
    506     VLOG(1) << "DBusThreadManager destroyed";
    507   } else {
    508     LOG(FATAL) << "~DBusThreadManager() called outside of Shutdown()";
    509   }
    510 }
    511 
    512 // static
    513 DBusThreadManager* DBusThreadManager::Get() {
    514   CHECK(g_dbus_thread_manager)
    515       << "DBusThreadManager::Get() called before Initialize()";
    516   return g_dbus_thread_manager;
    517 }
    518 
    519 // static
    520 void DBusThreadManager::InitializeClients() {
    521   InitClient(g_dbus_thread_manager->GetBluetoothAdapterClient());
    522   InitClient(g_dbus_thread_manager->GetBluetoothAgentManagerClient());
    523   InitClient(g_dbus_thread_manager->GetBluetoothDeviceClient());
    524   InitClient(g_dbus_thread_manager->GetBluetoothInputClient());
    525   InitClient(g_dbus_thread_manager->GetBluetoothProfileManagerClient());
    526   InitClient(g_dbus_thread_manager->GetCrasAudioClient());
    527   InitClient(g_dbus_thread_manager->GetCrosDisksClient());
    528   InitClient(g_dbus_thread_manager->GetCryptohomeClient());
    529   InitClient(g_dbus_thread_manager->GetDebugDaemonClient());
    530   InitClient(g_dbus_thread_manager->GetGsmSMSClient());
    531   InitClient(g_dbus_thread_manager->GetImageBurnerClient());
    532   InitClient(g_dbus_thread_manager->GetIntrospectableClient());
    533   InitClient(g_dbus_thread_manager->GetModemMessagingClient());
    534   InitClient(g_dbus_thread_manager->GetPermissionBrokerClient());
    535   InitClient(g_dbus_thread_manager->GetPowerManagerClient());
    536   InitClient(g_dbus_thread_manager->GetSessionManagerClient());
    537   InitClient(g_dbus_thread_manager->GetShillDeviceClient());
    538   InitClient(g_dbus_thread_manager->GetShillIPConfigClient());
    539   InitClient(g_dbus_thread_manager->GetShillManagerClient());
    540   InitClient(g_dbus_thread_manager->GetShillServiceClient());
    541   InitClient(g_dbus_thread_manager->GetShillProfileClient());
    542   InitClient(g_dbus_thread_manager->GetSMSClient());
    543   InitClient(g_dbus_thread_manager->GetSystemClockClient());
    544   InitClient(g_dbus_thread_manager->GetUpdateEngineClient());
    545 
    546   // Initialize the NFC clients in the correct order. The order of
    547   // initialization matters due to dependencies that exist between the
    548   // client objects.
    549   InitClient(g_dbus_thread_manager->GetNfcManagerClient());
    550   InitClient(g_dbus_thread_manager->GetNfcAdapterClient());
    551   InitClient(g_dbus_thread_manager->GetNfcDeviceClient());
    552   InitClient(g_dbus_thread_manager->GetNfcTagClient());
    553   InitClient(g_dbus_thread_manager->GetNfcRecordClient());
    554 
    555   // PowerPolicyController is dependent on PowerManagerClient, so
    556   // initialize it after the main list of clients.
    557   if (g_dbus_thread_manager->GetPowerPolicyController()) {
    558     g_dbus_thread_manager->GetPowerPolicyController()->Init(
    559         g_dbus_thread_manager);
    560   }
    561 
    562   // This must be called after the list of clients so they've each had a
    563   // chance to register with their object g_dbus_thread_managers.
    564   if (g_dbus_thread_manager->GetSystemBus())
    565     g_dbus_thread_manager->GetSystemBus()->GetManagedObjects();
    566 }
    567 
    568 // static
    569 void DBusThreadManager::InitClient(DBusClient* client) {
    570   if (client)
    571     client->Init(g_dbus_thread_manager->GetSystemBus());
    572 }
    573 
    574 }  // namespace chromeos
    575