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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/sys_info.h" | 11 #include "base/sys_info.h" |
12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
13 #include "chromeos/chromeos_switches.h" | 13 #include "chromeos/chromeos_switches.h" |
14 #include "chromeos/dbus/arc_obb_mounter_client.h" | 14 #include "chromeos/dbus/arc_obb_mounter_client.h" |
15 #include "chromeos/dbus/cras_audio_client.h" | 15 #include "chromeos/dbus/cras_audio_client.h" |
16 #include "chromeos/dbus/cros_disks_client.h" | 16 #include "chromeos/dbus/cros_disks_client.h" |
17 #include "chromeos/dbus/cryptohome_client.h" | 17 #include "chromeos/dbus/cryptohome_client.h" |
18 #include "chromeos/dbus/dbus_client.h" | 18 #include "chromeos/dbus/dbus_client.h" |
| 19 #include "chromeos/dbus/dbus_client_bundle.h" |
19 #include "chromeos/dbus/debug_daemon_client.h" | 20 #include "chromeos/dbus/debug_daemon_client.h" |
20 #include "chromeos/dbus/easy_unlock_client.h" | 21 #include "chromeos/dbus/easy_unlock_client.h" |
21 #include "chromeos/dbus/gsm_sms_client.h" | 22 #include "chromeos/dbus/gsm_sms_client.h" |
22 #include "chromeos/dbus/image_burner_client.h" | 23 #include "chromeos/dbus/image_burner_client.h" |
23 #include "chromeos/dbus/lorgnette_manager_client.h" | 24 #include "chromeos/dbus/lorgnette_manager_client.h" |
24 #include "chromeos/dbus/modem_messaging_client.h" | 25 #include "chromeos/dbus/modem_messaging_client.h" |
25 #include "chromeos/dbus/permission_broker_client.h" | 26 #include "chromeos/dbus/permission_broker_client.h" |
26 #include "chromeos/dbus/power_manager_client.h" | 27 #include "chromeos/dbus/power_manager_client.h" |
27 #include "chromeos/dbus/session_manager_client.h" | 28 #include "chromeos/dbus/session_manager_client.h" |
28 #include "chromeos/dbus/shill_device_client.h" | 29 #include "chromeos/dbus/shill_device_client.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 GetShillServiceClient()->Init(GetSystemBus()); | 213 GetShillServiceClient()->Init(GetSystemBus()); |
213 GetShillProfileClient()->Init(GetSystemBus()); | 214 GetShillProfileClient()->Init(GetSystemBus()); |
214 GetShillThirdPartyVpnDriverClient()->Init(GetSystemBus()); | 215 GetShillThirdPartyVpnDriverClient()->Init(GetSystemBus()); |
215 GetSMSClient()->Init(GetSystemBus()); | 216 GetSMSClient()->Init(GetSystemBus()); |
216 GetSystemClockClient()->Init(GetSystemBus()); | 217 GetSystemClockClient()->Init(GetSystemBus()); |
217 GetUpdateEngineClient()->Init(GetSystemBus()); | 218 GetUpdateEngineClient()->Init(GetSystemBus()); |
218 | 219 |
219 client_bundle_->SetupDefaultEnvironment(); | 220 client_bundle_->SetupDefaultEnvironment(); |
220 } | 221 } |
221 | 222 |
222 bool DBusThreadManager::IsUsingStub(DBusClientBundle::DBusClientType client) { | 223 bool DBusThreadManager::IsUsingFake(DBusClientType client) { |
223 return client_bundle_->IsUsingStub(client); | 224 return !client_bundle_->IsUsingReal(client); |
224 } | 225 } |
225 | 226 |
226 // static | 227 // static |
227 void DBusThreadManager::Initialize() { | 228 void DBusThreadManager::Initialize() { |
228 // If we initialize DBusThreadManager twice we may also be shutting it down | 229 // If we initialize DBusThreadManager twice we may also be shutting it down |
229 // early; do not allow that. | 230 // early; do not allow that. |
230 if (g_using_dbus_thread_manager_for_testing) | 231 if (g_using_dbus_thread_manager_for_testing) |
231 return; | 232 return; |
232 | 233 |
233 CHECK(!g_dbus_thread_manager); | 234 CHECK(!g_dbus_thread_manager); |
234 bool use_dbus_stub = !base::SysInfo::IsRunningOnChromeOS() || | 235 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
235 base::CommandLine::ForCurrentProcess()->HasSwitch( | 236 bool use_fakes = !base::SysInfo::IsRunningOnChromeOS() || |
236 chromeos::switches::kDbusStub); | 237 command_line->HasSwitch(chromeos::switches::kDbusStub); |
237 bool force_unstub_clients = base::CommandLine::ForCurrentProcess()->HasSwitch( | 238 // TODO(jamescook): Delete this after M56 branches. |
238 chromeos::switches::kDbusUnstubClients); | 239 if (command_line->HasSwitch(chromeos::switches::kDbusUnstubClients)) |
239 // Determine whether we use stub or real client implementations. | 240 LOG(FATAL) << "Use --dbus-real-clients instead of --dbus-unstub-clients."; |
240 if (force_unstub_clients) { | 241 bool force_real_clients = |
241 InitializeWithPartialStub( | 242 command_line->HasSwitch(chromeos::switches::kDbusRealClients); |
242 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 243 // Determine whether we use fake or real client implementations. |
243 chromeos::switches::kDbusUnstubClients)); | 244 if (force_real_clients) { |
244 } else if (use_dbus_stub) { | 245 InitializeWithPartialFakes(command_line->GetSwitchValueASCII( |
245 InitializeWithStubs(); | 246 chromeos::switches::kDbusRealClients)); |
| 247 } else if (use_fakes) { |
| 248 InitializeWithFakeClients(); |
246 } else { | 249 } else { |
247 InitializeWithRealClients(); | 250 InitializeWithRealClients(); |
248 } | 251 } |
249 } | 252 } |
250 | 253 |
251 // static | 254 // static |
252 std::unique_ptr<DBusThreadManagerSetter> | 255 std::unique_ptr<DBusThreadManagerSetter> |
253 DBusThreadManager::GetSetterForTesting() { | 256 DBusThreadManager::GetSetterForTesting() { |
254 if (!g_using_dbus_thread_manager_for_testing) { | 257 if (!g_using_dbus_thread_manager_for_testing) { |
255 g_using_dbus_thread_manager_for_testing = true; | 258 g_using_dbus_thread_manager_for_testing = true; |
256 InitializeWithStubs(); | 259 InitializeWithFakeClients(); |
257 } | 260 } |
258 | 261 |
259 return base::WrapUnique(new DBusThreadManagerSetter()); | 262 return base::WrapUnique(new DBusThreadManagerSetter()); |
260 } | 263 } |
261 | 264 |
262 // static | 265 // static |
263 void DBusThreadManager::CreateGlobalInstance( | 266 void DBusThreadManager::CreateGlobalInstance( |
264 DBusClientBundle::DBusClientTypeMask unstub_client_mask) { | 267 DBusClientTypeMask real_client_mask) { |
265 CHECK(!g_dbus_thread_manager); | 268 CHECK(!g_dbus_thread_manager); |
266 g_dbus_thread_manager = new DBusThreadManager( | 269 g_dbus_thread_manager = new DBusThreadManager( |
267 base::MakeUnique<DBusClientBundle>(unstub_client_mask)); | 270 base::MakeUnique<DBusClientBundle>(real_client_mask)); |
268 g_dbus_thread_manager->InitializeClients(); | 271 g_dbus_thread_manager->InitializeClients(); |
269 } | 272 } |
270 | 273 |
271 // static | 274 // static |
272 void DBusThreadManager::InitializeWithRealClients() { | 275 void DBusThreadManager::InitializeWithRealClients() { |
273 CreateGlobalInstance(~static_cast<DBusClientBundle::DBusClientTypeMask>(0)); | 276 CreateGlobalInstance(static_cast<DBusClientTypeMask>(DBusClientType::ALL)); |
274 VLOG(1) << "DBusThreadManager initialized for Chrome OS"; | 277 VLOG(1) << "DBusThreadManager initialized for Chrome OS"; |
275 } | 278 } |
276 | 279 |
277 // static | 280 // static |
278 void DBusThreadManager::InitializeWithStubs() { | 281 void DBusThreadManager::InitializeWithFakeClients() { |
279 CreateGlobalInstance(0 /* unstub_client_mask */); | 282 CreateGlobalInstance(static_cast<DBusClientTypeMask>(DBusClientType::NONE)); |
280 VLOG(1) << "DBusThreadManager created for testing"; | 283 VLOG(1) << "DBusThreadManager created for testing"; |
281 } | 284 } |
282 | 285 |
283 // static | 286 // static |
284 void DBusThreadManager::InitializeWithPartialStub( | 287 void DBusThreadManager::InitializeWithPartialFakes( |
285 const std::string& unstub_clients) { | 288 const std::string& force_real_clients) { |
286 DBusClientBundle::DBusClientTypeMask unstub_client_mask = | 289 DBusClientTypeMask real_client_mask = |
287 DBusClientBundle::ParseUnstubList(unstub_clients); | 290 ParseDBusRealClientsList(force_real_clients); |
288 // We should have something parsed correctly here. | 291 // We should have something parsed correctly here. |
289 LOG_IF(FATAL, unstub_client_mask == 0) | 292 LOG_IF(FATAL, real_client_mask == 0) |
290 << "Switch values for --" << chromeos::switches::kDbusUnstubClients | 293 << "Switch values for --" << chromeos::switches::kDbusRealClients |
291 << " cannot be parsed: " << unstub_clients; | 294 << " cannot be parsed: " << real_client_mask; |
292 VLOG(1) << "DBusThreadManager initialized for mixed runtime environment"; | 295 VLOG(1) << "DBusThreadManager initialized for mixed runtime environment"; |
293 CreateGlobalInstance(unstub_client_mask); | 296 CreateGlobalInstance(real_client_mask); |
294 } | 297 } |
295 | 298 |
296 // static | 299 // static |
297 bool DBusThreadManager::IsInitialized() { | 300 bool DBusThreadManager::IsInitialized() { |
298 return g_dbus_thread_manager != NULL; | 301 return g_dbus_thread_manager != NULL; |
299 } | 302 } |
300 | 303 |
301 // static | 304 // static |
302 void DBusThreadManager::Shutdown() { | 305 void DBusThreadManager::Shutdown() { |
303 // Ensure that we only shutdown DBusThreadManager once. | 306 // Ensure that we only shutdown DBusThreadManager once. |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 std::move(client); | 443 std::move(client); |
441 } | 444 } |
442 | 445 |
443 void DBusThreadManagerSetter::SetUpdateEngineClient( | 446 void DBusThreadManagerSetter::SetUpdateEngineClient( |
444 std::unique_ptr<UpdateEngineClient> client) { | 447 std::unique_ptr<UpdateEngineClient> client) { |
445 DBusThreadManager::Get()->client_bundle_->update_engine_client_ = | 448 DBusThreadManager::Get()->client_bundle_->update_engine_client_ = |
446 std::move(client); | 449 std::move(client); |
447 } | 450 } |
448 | 451 |
449 } // namespace chromeos | 452 } // namespace chromeos |
OLD | NEW |