| 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" | |
| 9 #include "base/sys_info.h" | 8 #include "base/sys_info.h" |
| 10 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
| 11 #include "chromeos/chromeos_switches.h" | 10 #include "chromeos/chromeos_switches.h" |
| 12 #include "chromeos/dbus/bluetooth_adapter_client.h" | 11 #include "chromeos/dbus/bluetooth_adapter_client.h" |
| 13 #include "chromeos/dbus/bluetooth_agent_manager_client.h" | 12 #include "chromeos/dbus/bluetooth_agent_manager_client.h" |
| 14 #include "chromeos/dbus/bluetooth_device_client.h" | 13 #include "chromeos/dbus/bluetooth_device_client.h" |
| 15 #include "chromeos/dbus/bluetooth_gatt_characteristic_client.h" | 14 #include "chromeos/dbus/bluetooth_gatt_characteristic_client.h" |
| 16 #include "chromeos/dbus/bluetooth_gatt_descriptor_client.h" | 15 #include "chromeos/dbus/bluetooth_gatt_descriptor_client.h" |
| 17 #include "chromeos/dbus/bluetooth_gatt_manager_client.h" | 16 #include "chromeos/dbus/bluetooth_gatt_manager_client.h" |
| 18 #include "chromeos/dbus/bluetooth_gatt_service_client.h" | 17 #include "chromeos/dbus/bluetooth_gatt_service_client.h" |
| 19 #include "chromeos/dbus/bluetooth_input_client.h" | 18 #include "chromeos/dbus/bluetooth_input_client.h" |
| 20 #include "chromeos/dbus/bluetooth_profile_manager_client.h" | 19 #include "chromeos/dbus/bluetooth_profile_manager_client.h" |
| 21 #include "chromeos/dbus/cras_audio_client.h" | 20 #include "chromeos/dbus/cras_audio_client.h" |
| 22 #include "chromeos/dbus/cros_disks_client.h" | 21 #include "chromeos/dbus/cros_disks_client.h" |
| 23 #include "chromeos/dbus/cryptohome_client.h" | 22 #include "chromeos/dbus/cryptohome_client.h" |
| 24 #include "chromeos/dbus/dbus_client.h" | 23 #include "chromeos/dbus/dbus_client.h" |
| 25 #include "chromeos/dbus/dbus_thread_manager_observer.h" | |
| 26 #include "chromeos/dbus/debug_daemon_client.h" | 24 #include "chromeos/dbus/debug_daemon_client.h" |
| 27 #include "chromeos/dbus/easy_unlock_client.h" | 25 #include "chromeos/dbus/easy_unlock_client.h" |
| 28 #include "chromeos/dbus/fake_dbus_thread_manager.h" | 26 #include "chromeos/dbus/fake_dbus_thread_manager.h" |
| 29 #include "chromeos/dbus/gsm_sms_client.h" | 27 #include "chromeos/dbus/gsm_sms_client.h" |
| 30 #include "chromeos/dbus/image_burner_client.h" | 28 #include "chromeos/dbus/image_burner_client.h" |
| 31 #include "chromeos/dbus/introspectable_client.h" | 29 #include "chromeos/dbus/introspectable_client.h" |
| 32 #include "chromeos/dbus/lorgnette_manager_client.h" | 30 #include "chromeos/dbus/lorgnette_manager_client.h" |
| 33 #include "chromeos/dbus/modem_messaging_client.h" | 31 #include "chromeos/dbus/modem_messaging_client.h" |
| 34 #include "chromeos/dbus/nfc_adapter_client.h" | 32 #include "chromeos/dbus/nfc_adapter_client.h" |
| 35 #include "chromeos/dbus/nfc_device_client.h" | 33 #include "chromeos/dbus/nfc_device_client.h" |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 dbus::Bus::Options system_bus_options; | 270 dbus::Bus::Options system_bus_options; |
| 273 system_bus_options.bus_type = dbus::Bus::SYSTEM; | 271 system_bus_options.bus_type = dbus::Bus::SYSTEM; |
| 274 system_bus_options.connection_type = dbus::Bus::PRIVATE; | 272 system_bus_options.connection_type = dbus::Bus::PRIVATE; |
| 275 system_bus_options.dbus_task_runner = dbus_thread_->message_loop_proxy(); | 273 system_bus_options.dbus_task_runner = dbus_thread_->message_loop_proxy(); |
| 276 system_bus_ = new dbus::Bus(system_bus_options); | 274 system_bus_ = new dbus::Bus(system_bus_options); |
| 277 | 275 |
| 278 CreateDefaultClients(); | 276 CreateDefaultClients(); |
| 279 } | 277 } |
| 280 | 278 |
| 281 virtual ~DBusThreadManagerImpl() { | 279 virtual ~DBusThreadManagerImpl() { |
| 282 FOR_EACH_OBSERVER(DBusThreadManagerObserver, observers_, | |
| 283 OnDBusThreadManagerDestroying(this)); | |
| 284 | |
| 285 // PowerPolicyController's destructor depends on PowerManagerClient. | 280 // PowerPolicyController's destructor depends on PowerManagerClient. |
| 286 power_policy_controller_.reset(); | 281 power_policy_controller_.reset(); |
| 287 | 282 |
| 288 // Delete all D-Bus clients before shutting down the system bus. | 283 // Delete all D-Bus clients before shutting down the system bus. |
| 289 client_bundle_.reset(); | 284 client_bundle_.reset(); |
| 290 | 285 |
| 291 // Shut down the bus. During the browser shutdown, it's ok to shut down | 286 // Shut down the bus. During the browser shutdown, it's ok to shut down |
| 292 // the bus synchronously. | 287 // the bus synchronously. |
| 293 system_bus_->ShutdownOnDBusThreadAndBlock(); | 288 system_bus_->ShutdownOnDBusThreadAndBlock(); |
| 294 | 289 |
| 295 // Stop the D-Bus thread. | 290 // Stop the D-Bus thread. |
| 296 dbus_thread_->Stop(); | 291 dbus_thread_->Stop(); |
| 297 } | 292 } |
| 298 | 293 |
| 299 // DBusThreadManager overrides: | 294 // DBusThreadManager overrides: |
| 300 virtual void AddObserver(DBusThreadManagerObserver* observer) OVERRIDE { | |
| 301 DCHECK(observer); | |
| 302 observers_.AddObserver(observer); | |
| 303 } | |
| 304 | |
| 305 virtual void RemoveObserver(DBusThreadManagerObserver* observer) OVERRIDE { | |
| 306 DCHECK(observer); | |
| 307 observers_.RemoveObserver(observer); | |
| 308 } | |
| 309 | |
| 310 virtual dbus::Bus* GetSystemBus() OVERRIDE { | 295 virtual dbus::Bus* GetSystemBus() OVERRIDE { |
| 311 return system_bus_.get(); | 296 return system_bus_.get(); |
| 312 } | 297 } |
| 313 | 298 |
| 314 virtual BluetoothAdapterClient* GetBluetoothAdapterClient() OVERRIDE { | 299 virtual BluetoothAdapterClient* GetBluetoothAdapterClient() OVERRIDE { |
| 315 return client_bundle_->bluetooth_adapter_client(); | 300 return client_bundle_->bluetooth_adapter_client(); |
| 316 } | 301 } |
| 317 | 302 |
| 318 virtual BluetoothAgentManagerClient* GetBluetoothAgentManagerClient() | 303 virtual BluetoothAgentManagerClient* GetBluetoothAgentManagerClient() |
| 319 OVERRIDE { | 304 OVERRIDE { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 } | 444 } |
| 460 | 445 |
| 461 private: | 446 private: |
| 462 // Constructs all clients and stores them in the respective *_client_ member | 447 // Constructs all clients and stores them in the respective *_client_ member |
| 463 // variable. | 448 // variable. |
| 464 void CreateDefaultClients() { | 449 void CreateDefaultClients() { |
| 465 client_bundle_.reset(new DBusClientBundle); | 450 client_bundle_.reset(new DBusClientBundle); |
| 466 power_policy_controller_.reset(new PowerPolicyController); | 451 power_policy_controller_.reset(new PowerPolicyController); |
| 467 } | 452 } |
| 468 | 453 |
| 469 // Note: Keep this before other members so they can call AddObserver() in | |
| 470 // their c'tors. | |
| 471 ObserverList<DBusThreadManagerObserver> observers_; | |
| 472 | |
| 473 scoped_ptr<base::Thread> dbus_thread_; | 454 scoped_ptr<base::Thread> dbus_thread_; |
| 474 scoped_refptr<dbus::Bus> system_bus_; | 455 scoped_refptr<dbus::Bus> system_bus_; |
| 475 scoped_ptr<DBusClientBundle> client_bundle_; | 456 scoped_ptr<DBusClientBundle> client_bundle_; |
| 476 scoped_ptr<PowerPolicyController> power_policy_controller_; | 457 scoped_ptr<PowerPolicyController> power_policy_controller_; |
| 477 | 458 |
| 478 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerImpl); | 459 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerImpl); |
| 479 }; | 460 }; |
| 480 | 461 |
| 481 // static | 462 // static |
| 482 void DBusThreadManager::Initialize() { | 463 void DBusThreadManager::Initialize() { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 g_dbus_thread_manager->GetSystemBus()->GetManagedObjects(); | 610 g_dbus_thread_manager->GetSystemBus()->GetManagedObjects(); |
| 630 } | 611 } |
| 631 | 612 |
| 632 // static | 613 // static |
| 633 void DBusThreadManager::InitClient(DBusClient* client) { | 614 void DBusThreadManager::InitClient(DBusClient* client) { |
| 634 if (client) | 615 if (client) |
| 635 client->Init(g_dbus_thread_manager->GetSystemBus()); | 616 client->Init(g_dbus_thread_manager->GetSystemBus()); |
| 636 } | 617 } |
| 637 | 618 |
| 638 } // namespace chromeos | 619 } // namespace chromeos |
| OLD | NEW |