OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 5 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
9 #include "chrome/browser/chromeos/dbus/bluetooth_adapter_client.h" | 9 #include "chrome/browser/chromeos/dbus/bluetooth_adapter_client.h" |
10 #include "chrome/browser/chromeos/dbus/bluetooth_manager_client.h" | 10 #include "chrome/browser/chromeos/dbus/bluetooth_manager_client.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 // Create the connection to the system bus. | 30 // Create the connection to the system bus. |
31 dbus::Bus::Options system_bus_options; | 31 dbus::Bus::Options system_bus_options; |
32 system_bus_options.bus_type = dbus::Bus::SYSTEM; | 32 system_bus_options.bus_type = dbus::Bus::SYSTEM; |
33 system_bus_options.connection_type = dbus::Bus::PRIVATE; | 33 system_bus_options.connection_type = dbus::Bus::PRIVATE; |
34 system_bus_options.dbus_thread_message_loop_proxy = | 34 system_bus_options.dbus_thread_message_loop_proxy = |
35 dbus_thread_->message_loop_proxy(); | 35 dbus_thread_->message_loop_proxy(); |
36 system_bus_ = new dbus::Bus(system_bus_options); | 36 system_bus_ = new dbus::Bus(system_bus_options); |
37 | 37 |
38 // Create and start the cros D-Bus service. | 38 // Create and start the cros D-Bus service. |
39 cros_dbus_service_ = CrosDBusService::Create(system_bus_.get()); | 39 cros_dbus_service_.reset(CrosDBusService::Create(system_bus_.get())); |
40 cros_dbus_service_->Start(); | 40 cros_dbus_service_->Start(); |
41 | 41 |
42 // Start monitoring sensors if needed. | 42 // Start monitoring sensors if needed. |
43 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 43 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
44 if (command_line.HasSwitch(switches::kEnableSensors)) { | 44 if (command_line.HasSwitch(switches::kEnableSensors)) { |
45 sensors_source_.reset(new SensorsSource); | 45 sensors_source_.reset(new SensorsSource); |
46 sensors_source_->Init(system_bus_.get()); | 46 sensors_source_->Init(system_bus_.get()); |
47 } | 47 } |
48 | 48 |
49 // Create bluetooth clients if bluetooth is enabled. | 49 // Create bluetooth clients if bluetooth is enabled. |
(...skipping 14 matching lines...) Expand all Loading... |
64 SpeechSynthesizerClient::Create(system_bus_.get())); | 64 SpeechSynthesizerClient::Create(system_bus_.get())); |
65 } | 65 } |
66 | 66 |
67 DBusThreadManager::~DBusThreadManager() { | 67 DBusThreadManager::~DBusThreadManager() { |
68 // Shut down the bus. During the browser shutdown, it's ok to shut down | 68 // Shut down the bus. During the browser shutdown, it's ok to shut down |
69 // the bus synchronously. | 69 // the bus synchronously. |
70 system_bus_->ShutdownOnDBusThreadAndBlock(); | 70 system_bus_->ShutdownOnDBusThreadAndBlock(); |
71 | 71 |
72 // Stop the D-Bus thread. | 72 // Stop the D-Bus thread. |
73 dbus_thread_->Stop(); | 73 dbus_thread_->Stop(); |
74 | |
75 // D-Bus clients should be deleted after the D-Bus thread is stopped. | |
76 // See "CALLBACKS IN D-BUS CLIENTS" in the header file for why. | |
77 delete cros_dbus_service_; | |
78 } | 74 } |
79 | 75 |
80 void DBusThreadManager::Initialize() { | 76 void DBusThreadManager::Initialize() { |
81 if (g_dbus_thread_manager) { | 77 if (g_dbus_thread_manager) { |
82 // This can happen in tests. | 78 // This can happen in tests. |
83 LOG(WARNING) << "DBusThreadManager::Initialize() was already called"; | 79 LOG(WARNING) << "DBusThreadManager::Initialize() was already called"; |
84 return; | 80 return; |
85 } | 81 } |
86 g_dbus_thread_manager = new DBusThreadManager; | 82 g_dbus_thread_manager = new DBusThreadManager; |
87 VLOG(1) << "DBusThreadManager initialized"; | 83 VLOG(1) << "DBusThreadManager initialized"; |
(...skipping 15 matching lines...) Expand all Loading... |
103 << "DBusThreadManager::Get() called before Initialize()"; | 99 << "DBusThreadManager::Get() called before Initialize()"; |
104 return g_dbus_thread_manager; | 100 return g_dbus_thread_manager; |
105 } | 101 } |
106 | 102 |
107 void DBusThreadManager::set_session_manager_client_for_testing( | 103 void DBusThreadManager::set_session_manager_client_for_testing( |
108 SessionManagerClient* session_manager_client) { | 104 SessionManagerClient* session_manager_client) { |
109 session_manager_client_.reset(session_manager_client); | 105 session_manager_client_.reset(session_manager_client); |
110 } | 106 } |
111 | 107 |
112 } // namespace chromeos | 108 } // namespace chromeos |
OLD | NEW |