| 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 bool use_fakes = !base::SysInfo::IsRunningOnChromeOS() || |
| 235 base::CommandLine::ForCurrentProcess()->HasSwitch( | 236 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 236 chromeos::switches::kDbusStub); | 237 chromeos::switches::kDbusStub); |
| 237 bool force_unstub_clients = base::CommandLine::ForCurrentProcess()->HasSwitch( | 238 bool force_unstub_clients = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 238 chromeos::switches::kDbusUnstubClients); | 239 chromeos::switches::kDbusUnstubClients); |
| 239 // Determine whether we use stub or real client implementations. | 240 // Determine whether we use fake or real client implementations. |
| 240 if (force_unstub_clients) { | 241 if (force_unstub_clients) { |
| 241 InitializeWithPartialStub( | 242 InitializeWithPartialFakes( |
| 242 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 243 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 243 chromeos::switches::kDbusUnstubClients)); | 244 chromeos::switches::kDbusUnstubClients)); |
| 244 } else if (use_dbus_stub) { | 245 } else if (use_fakes) { |
| 245 InitializeWithStubs(); | 246 InitializeWithFakeClients(); |
| 246 } else { | 247 } else { |
| 247 InitializeWithRealClients(); | 248 InitializeWithRealClients(); |
| 248 } | 249 } |
| 249 } | 250 } |
| 250 | 251 |
| 251 // static | 252 // static |
| 252 std::unique_ptr<DBusThreadManagerSetter> | 253 std::unique_ptr<DBusThreadManagerSetter> |
| 253 DBusThreadManager::GetSetterForTesting() { | 254 DBusThreadManager::GetSetterForTesting() { |
| 254 if (!g_using_dbus_thread_manager_for_testing) { | 255 if (!g_using_dbus_thread_manager_for_testing) { |
| 255 g_using_dbus_thread_manager_for_testing = true; | 256 g_using_dbus_thread_manager_for_testing = true; |
| 256 InitializeWithStubs(); | 257 InitializeWithFakeClients(); |
| 257 } | 258 } |
| 258 | 259 |
| 259 return base::WrapUnique(new DBusThreadManagerSetter()); | 260 return base::WrapUnique(new DBusThreadManagerSetter()); |
| 260 } | 261 } |
| 261 | 262 |
| 262 // static | 263 // static |
| 263 void DBusThreadManager::CreateGlobalInstance( | 264 void DBusThreadManager::CreateGlobalInstance( |
| 264 DBusClientBundle::DBusClientTypeMask unstub_client_mask) { | 265 DBusClientTypeMask real_client_mask) { |
| 265 CHECK(!g_dbus_thread_manager); | 266 CHECK(!g_dbus_thread_manager); |
| 266 g_dbus_thread_manager = new DBusThreadManager( | 267 g_dbus_thread_manager = new DBusThreadManager( |
| 267 base::MakeUnique<DBusClientBundle>(unstub_client_mask)); | 268 base::MakeUnique<DBusClientBundle>(real_client_mask)); |
| 268 g_dbus_thread_manager->InitializeClients(); | 269 g_dbus_thread_manager->InitializeClients(); |
| 269 } | 270 } |
| 270 | 271 |
| 271 // static | 272 // static |
| 272 void DBusThreadManager::InitializeWithRealClients() { | 273 void DBusThreadManager::InitializeWithRealClients() { |
| 273 CreateGlobalInstance(~static_cast<DBusClientBundle::DBusClientTypeMask>(0)); | 274 CreateGlobalInstance(static_cast<DBusClientTypeMask>(DBusClientType::ALL)); |
| 274 VLOG(1) << "DBusThreadManager initialized for Chrome OS"; | 275 VLOG(1) << "DBusThreadManager initialized for Chrome OS"; |
| 275 } | 276 } |
| 276 | 277 |
| 277 // static | 278 // static |
| 278 void DBusThreadManager::InitializeWithStubs() { | 279 void DBusThreadManager::InitializeWithFakeClients() { |
| 279 CreateGlobalInstance(0 /* unstub_client_mask */); | 280 CreateGlobalInstance(static_cast<DBusClientTypeMask>(DBusClientType::NONE)); |
| 280 VLOG(1) << "DBusThreadManager created for testing"; | 281 VLOG(1) << "DBusThreadManager created for testing"; |
| 281 } | 282 } |
| 282 | 283 |
| 283 // static | 284 // static |
| 284 void DBusThreadManager::InitializeWithPartialStub( | 285 void DBusThreadManager::InitializeWithPartialFakes( |
| 285 const std::string& unstub_clients) { | 286 const std::string& force_real_clients) { |
| 286 DBusClientBundle::DBusClientTypeMask unstub_client_mask = | 287 DBusClientTypeMask real_client_mask = |
| 287 DBusClientBundle::ParseUnstubList(unstub_clients); | 288 ParseDBusUnstubClientsList(force_real_clients); |
| 288 // We should have something parsed correctly here. | 289 // We should have something parsed correctly here. |
| 289 LOG_IF(FATAL, unstub_client_mask == 0) | 290 LOG_IF(FATAL, real_client_mask == 0) |
| 290 << "Switch values for --" << chromeos::switches::kDbusUnstubClients | 291 << "Switch values for --" << chromeos::switches::kDbusUnstubClients |
| 291 << " cannot be parsed: " << unstub_clients; | 292 << " cannot be parsed: " << real_client_mask; |
| 292 VLOG(1) << "DBusThreadManager initialized for mixed runtime environment"; | 293 VLOG(1) << "DBusThreadManager initialized for mixed runtime environment"; |
| 293 CreateGlobalInstance(unstub_client_mask); | 294 CreateGlobalInstance(real_client_mask); |
| 294 } | 295 } |
| 295 | 296 |
| 296 // static | 297 // static |
| 297 bool DBusThreadManager::IsInitialized() { | 298 bool DBusThreadManager::IsInitialized() { |
| 298 return g_dbus_thread_manager != NULL; | 299 return g_dbus_thread_manager != NULL; |
| 299 } | 300 } |
| 300 | 301 |
| 301 // static | 302 // static |
| 302 void DBusThreadManager::Shutdown() { | 303 void DBusThreadManager::Shutdown() { |
| 303 // Ensure that we only shutdown DBusThreadManager once. | 304 // Ensure that we only shutdown DBusThreadManager once. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 std::move(client); | 441 std::move(client); |
| 441 } | 442 } |
| 442 | 443 |
| 443 void DBusThreadManagerSetter::SetUpdateEngineClient( | 444 void DBusThreadManagerSetter::SetUpdateEngineClient( |
| 444 std::unique_ptr<UpdateEngineClient> client) { | 445 std::unique_ptr<UpdateEngineClient> client) { |
| 445 DBusThreadManager::Get()->client_bundle_->update_engine_client_ = | 446 DBusThreadManager::Get()->client_bundle_->update_engine_client_ = |
| 446 std::move(client); | 447 std::move(client); |
| 447 } | 448 } |
| 448 | 449 |
| 449 } // namespace chromeos | 450 } // namespace chromeos |
| OLD | NEW |