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

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

Powered by Google App Engine
This is Rietveld 408576698