Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: chrome/browser/chromeos/dbus/dbus_thread_manager.cc

Issue 9838085: Move files inside chrome/browser/chromeos/dbus to chromeos/dbus (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 "chrome/browser/chromeos/dbus/dbus_thread_manager.h"
6
7 #include "base/chromeos/chromeos_version.h"
8 #include "base/threading/thread.h"
9 #include "chrome/browser/chromeos/dbus/bluetooth_adapter_client.h"
10 #include "chrome/browser/chromeos/dbus/bluetooth_device_client.h"
11 #include "chrome/browser/chromeos/dbus/bluetooth_input_client.h"
12 #include "chrome/browser/chromeos/dbus/bluetooth_manager_client.h"
13 #include "chrome/browser/chromeos/dbus/bluetooth_node_client.h"
14 #include "chrome/browser/chromeos/dbus/cashew_client.h"
15 #include "chrome/browser/chromeos/dbus/dbus_client_implementation_type.h"
16 #include "chrome/browser/chromeos/dbus/cros_disks_client.h"
17 #include "chrome/browser/chromeos/dbus/cryptohome_client.h"
18 #include "chrome/browser/chromeos/dbus/debug_daemon_client.h"
19 #include "chrome/browser/chromeos/dbus/flimflam_ipconfig_client.h"
20 #include "chrome/browser/chromeos/dbus/flimflam_network_client.h"
21 #include "chrome/browser/chromeos/dbus/flimflam_profile_client.h"
22 #include "chrome/browser/chromeos/dbus/image_burner_client.h"
23 #include "chrome/browser/chromeos/dbus/introspectable_client.h"
24 #include "chrome/browser/chromeos/dbus/power_manager_client.h"
25 #include "chrome/browser/chromeos/dbus/session_manager_client.h"
26 #include "chrome/browser/chromeos/dbus/speech_synthesizer_client.h"
27 #include "chrome/browser/chromeos/dbus/update_engine_client.h"
28 #include "dbus/bus.h"
29
30 namespace chromeos {
31
32 static DBusThreadManager* g_dbus_thread_manager = NULL;
33
34 // The DBusThreadManager implementation used in production.
35 class DBusThreadManagerImpl : public DBusThreadManager {
36 public:
37 DBusThreadManagerImpl() {
38 // Create the D-Bus thread.
39 base::Thread::Options thread_options;
40 thread_options.message_loop_type = MessageLoop::TYPE_IO;
41 dbus_thread_.reset(new base::Thread("D-Bus thread"));
42 dbus_thread_->StartWithOptions(thread_options);
43
44 // Create the connection to the system bus.
45 dbus::Bus::Options system_bus_options;
46 system_bus_options.bus_type = dbus::Bus::SYSTEM;
47 system_bus_options.connection_type = dbus::Bus::PRIVATE;
48 system_bus_options.dbus_thread_message_loop_proxy =
49 dbus_thread_->message_loop_proxy();
50 system_bus_ = new dbus::Bus(system_bus_options);
51
52 // Determine whether we use stub or real client implementations.
53 const DBusClientImplementationType client_type =
54 base::chromeos::IsRunningOnChromeOS() ?
55 REAL_DBUS_CLIENT_IMPLEMENTATION : STUB_DBUS_CLIENT_IMPLEMENTATION;
56
57 // Create the bluetooth clients.
58 bluetooth_manager_client_.reset(BluetoothManagerClient::Create(
59 client_type, system_bus_.get()));
60 bluetooth_adapter_client_.reset(BluetoothAdapterClient::Create(
61 client_type, system_bus_.get(), bluetooth_manager_client_.get()));
62 bluetooth_device_client_.reset(BluetoothDeviceClient::Create(
63 client_type, system_bus_.get(), bluetooth_adapter_client_.get()));
64 bluetooth_input_client_.reset(BluetoothInputClient::Create(
65 client_type, system_bus_.get(), bluetooth_adapter_client_.get()));
66 bluetooth_node_client_.reset(BluetoothNodeClient::Create(
67 client_type, system_bus_.get(), bluetooth_device_client_.get()));
68 // Create the Cashew client.
69 cashew_client_.reset(CashewClient::Create(client_type, system_bus_.get()));
70 // Create the cros-disks client.
71 cros_disks_client_.reset(
72 CrosDisksClient::Create(client_type, system_bus_.get()));
73 // Create the Cryptohome client.
74 cryptohome_client_.reset(
75 CryptohomeClient::Create(client_type, system_bus_.get()));
76 // Create the debugdaemon client.
77 debugdaemon_client_.reset(
78 DebugDaemonClient::Create(client_type, system_bus_.get()));
79 // Create the Flimflam IPConfig client.
80 flimflam_ipconfig_client_.reset(
81 FlimflamIPConfigClient::Create(client_type, system_bus_.get()));
82 // Create the Flimflam Network client.
83 flimflam_network_client_.reset(
84 FlimflamNetworkClient::Create(client_type, system_bus_.get()));
85 // Create the Flimflam Profile client.
86 flimflam_profile_client_.reset(
87 FlimflamProfileClient::Create(client_type, system_bus_.get()));
88 // Create the image burner client.
89 image_burner_client_.reset(ImageBurnerClient::Create(client_type,
90 system_bus_.get()));
91 // Create the introspectable object client.
92 introspectable_client_.reset(
93 IntrospectableClient::Create(client_type, system_bus_.get()));
94 // Create the power manager client.
95 power_manager_client_.reset(PowerManagerClient::Create(client_type,
96 system_bus_.get()));
97 // Create the session manager client.
98 session_manager_client_.reset(
99 SessionManagerClient::Create(client_type, system_bus_.get()));
100 // Create the speech synthesizer client.
101 speech_synthesizer_client_.reset(
102 SpeechSynthesizerClient::Create(client_type, system_bus_.get()));
103 // Create the update engine client.
104 update_engine_client_.reset(
105 UpdateEngineClient::Create(client_type, system_bus_.get()));
106 }
107
108 virtual ~DBusThreadManagerImpl() {
109 // Shut down the bus. During the browser shutdown, it's ok to shut down
110 // the bus synchronously.
111 system_bus_->ShutdownOnDBusThreadAndBlock();
112
113 // Stop the D-Bus thread.
114 dbus_thread_->Stop();
115 }
116
117 // DBusThreadManager override.
118 virtual dbus::Bus* GetSystemBus() OVERRIDE {
119 return system_bus_.get();
120 }
121
122 // DBusThreadManager override.
123 virtual BluetoothAdapterClient* GetBluetoothAdapterClient() OVERRIDE {
124 return bluetooth_adapter_client_.get();
125 }
126
127 // DBusThreadManager override.
128 virtual BluetoothDeviceClient* GetBluetoothDeviceClient() OVERRIDE {
129 return bluetooth_device_client_.get();
130 }
131
132 // DBusThreadManager override.
133 virtual BluetoothInputClient* GetBluetoothInputClient() OVERRIDE {
134 return bluetooth_input_client_.get();
135 }
136
137 // DBusThreadManager override.
138 virtual BluetoothManagerClient* GetBluetoothManagerClient() OVERRIDE {
139 return bluetooth_manager_client_.get();
140 }
141
142 // DBusThreadManager override.
143 virtual BluetoothNodeClient* GetBluetoothNodeClient() OVERRIDE {
144 return bluetooth_node_client_.get();
145 }
146
147 // DBusThreadManager override.
148 virtual CashewClient* GetCashewClient() OVERRIDE {
149 return cashew_client_.get();
150 }
151
152 // DBusThreadManager override.
153 virtual CrosDisksClient* GetCrosDisksClient() OVERRIDE {
154 return cros_disks_client_.get();
155 }
156
157 // DBusThreadManager override.
158 virtual CryptohomeClient* GetCryptohomeClient() OVERRIDE {
159 return cryptohome_client_.get();
160 }
161
162 // DBusThreadManager override.
163 virtual DebugDaemonClient* GetDebugDaemonClient() OVERRIDE {
164 return debugdaemon_client_.get();
165 }
166
167 // DBusThreadManager override.
168 virtual FlimflamIPConfigClient* GetFlimflamIPConfigClient() OVERRIDE {
169 return flimflam_ipconfig_client_.get();
170 }
171
172 virtual FlimflamNetworkClient* GetFlimflamNetworkClient() OVERRIDE {
173 return flimflam_network_client_.get();
174 }
175
176 // DBusThreadManager override.
177 virtual FlimflamProfileClient* GetFlimflamProfileClient() OVERRIDE {
178 return flimflam_profile_client_.get();
179 }
180
181 // DBusThreadManager override.
182 virtual ImageBurnerClient* GetImageBurnerClient() OVERRIDE {
183 return image_burner_client_.get();
184 }
185
186 // DBusThreadManager override.
187 virtual IntrospectableClient* GetIntrospectableClient() OVERRIDE {
188 return introspectable_client_.get();
189 }
190
191 // DBusThreadManager override.
192 virtual PowerManagerClient* GetPowerManagerClient() OVERRIDE {
193 return power_manager_client_.get();
194 }
195
196 // DBusThreadManager override.
197 virtual SessionManagerClient* GetSessionManagerClient() OVERRIDE {
198 return session_manager_client_.get();
199 }
200
201 // DBusThreadManager override.
202 virtual SpeechSynthesizerClient* GetSpeechSynthesizerClient() OVERRIDE {
203 return speech_synthesizer_client_.get();
204 }
205
206 // DBusThreadManager override.
207 virtual UpdateEngineClient* GetUpdateEngineClient() OVERRIDE {
208 return update_engine_client_.get();
209 }
210
211 scoped_ptr<base::Thread> dbus_thread_;
212 scoped_refptr<dbus::Bus> system_bus_;
213 scoped_ptr<BluetoothAdapterClient> bluetooth_adapter_client_;
214 scoped_ptr<BluetoothDeviceClient> bluetooth_device_client_;
215 scoped_ptr<BluetoothInputClient> bluetooth_input_client_;
216 scoped_ptr<BluetoothManagerClient> bluetooth_manager_client_;
217 scoped_ptr<BluetoothNodeClient> bluetooth_node_client_;
218 scoped_ptr<CashewClient> cashew_client_;
219 scoped_ptr<CrosDisksClient> cros_disks_client_;
220 scoped_ptr<CryptohomeClient> cryptohome_client_;
221 scoped_ptr<DebugDaemonClient> debugdaemon_client_;
222 scoped_ptr<FlimflamIPConfigClient> flimflam_ipconfig_client_;
223 scoped_ptr<FlimflamNetworkClient> flimflam_network_client_;
224 scoped_ptr<FlimflamProfileClient> flimflam_profile_client_;
225 scoped_ptr<ImageBurnerClient> image_burner_client_;
226 scoped_ptr<IntrospectableClient> introspectable_client_;
227 scoped_ptr<PowerManagerClient> power_manager_client_;
228 scoped_ptr<SessionManagerClient> session_manager_client_;
229 scoped_ptr<SpeechSynthesizerClient> speech_synthesizer_client_;
230 scoped_ptr<UpdateEngineClient> update_engine_client_;
231 };
232
233 // static
234 void DBusThreadManager::Initialize() {
235 if (g_dbus_thread_manager) {
236 LOG(WARNING) << "DBusThreadManager was already initialized";
237 return;
238 }
239 g_dbus_thread_manager = new DBusThreadManagerImpl;
240 VLOG(1) << "DBusThreadManager initialized";
241 }
242
243 // static
244 void DBusThreadManager::InitializeForTesting(
245 DBusThreadManager* dbus_thread_manager) {
246 if (g_dbus_thread_manager) {
247 LOG(WARNING) << "DBusThreadManager was already initialized";
248 return;
249 }
250 g_dbus_thread_manager = dbus_thread_manager;
251 VLOG(1) << "DBusThreadManager initialized";
252 }
253
254 // static
255 void DBusThreadManager::Shutdown() {
256 if (!g_dbus_thread_manager) {
257 // TODO(satorux): Make it a DCHECK() once it's ready.
258 LOG(WARNING) << "DBusThreadManager::Shutdown() called with NULL manager";
259 return;
260 }
261 delete g_dbus_thread_manager;
262 g_dbus_thread_manager = NULL;
263 VLOG(1) << "DBusThreadManager Shutdown completed";
264 }
265
266 DBusThreadManager::DBusThreadManager() {
267 }
268
269 DBusThreadManager::~DBusThreadManager() {
270 }
271
272 // static
273 DBusThreadManager* DBusThreadManager::Get() {
274 CHECK(g_dbus_thread_manager)
275 << "DBusThreadManager::Get() called before Initialize()";
276 return g_dbus_thread_manager;
277 }
278
279 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/dbus/dbus_thread_manager.h ('k') | chrome/browser/chromeos/dbus/debug_daemon_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698