| 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" |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 | 186 |
| 187 SystemClockClient* DBusThreadManager::GetSystemClockClient() { | 187 SystemClockClient* DBusThreadManager::GetSystemClockClient() { |
| 188 return client_bundle_->system_clock_client(); | 188 return client_bundle_->system_clock_client(); |
| 189 } | 189 } |
| 190 | 190 |
| 191 UpdateEngineClient* DBusThreadManager::GetUpdateEngineClient() { | 191 UpdateEngineClient* DBusThreadManager::GetUpdateEngineClient() { |
| 192 return client_bundle_->update_engine_client(); | 192 return client_bundle_->update_engine_client(); |
| 193 } | 193 } |
| 194 | 194 |
| 195 void DBusThreadManager::InitializeClients() { | 195 void DBusThreadManager::InitializeClients() { |
| 196 GetArcObbMounterClient()->Init(GetSystemBus()); | 196 if (GetArcObbMounterClient()) |
| 197 GetCrasAudioClient()->Init(GetSystemBus()); | 197 GetArcObbMounterClient()->Init(GetSystemBus()); |
| 198 GetCrosDisksClient()->Init(GetSystemBus()); | 198 if (GetCrasAudioClient()) |
| 199 GetCryptohomeClient()->Init(GetSystemBus()); | 199 GetCrasAudioClient()->Init(GetSystemBus()); |
| 200 GetDebugDaemonClient()->Init(GetSystemBus()); | 200 if (GetCrosDisksClient()) |
| 201 GetEasyUnlockClient()->Init(GetSystemBus()); | 201 GetCrosDisksClient()->Init(GetSystemBus()); |
| 202 GetGsmSMSClient()->Init(GetSystemBus()); | 202 if (GetCryptohomeClient()) |
| 203 GetImageBurnerClient()->Init(GetSystemBus()); | 203 GetCryptohomeClient()->Init(GetSystemBus()); |
| 204 GetLorgnetteManagerClient()->Init(GetSystemBus()); | 204 if (GetDebugDaemonClient()) |
| 205 GetModemMessagingClient()->Init(GetSystemBus()); | 205 GetDebugDaemonClient()->Init(GetSystemBus()); |
| 206 GetPermissionBrokerClient()->Init(GetSystemBus()); | 206 if (GetEasyUnlockClient()) |
| 207 GetPowerManagerClient()->Init(GetSystemBus()); | 207 GetEasyUnlockClient()->Init(GetSystemBus()); |
| 208 GetSessionManagerClient()->Init(GetSystemBus()); | 208 if (GetGsmSMSClient()) |
| 209 GetShillDeviceClient()->Init(GetSystemBus()); | 209 GetGsmSMSClient()->Init(GetSystemBus()); |
| 210 GetShillIPConfigClient()->Init(GetSystemBus()); | 210 if (GetImageBurnerClient()) |
| 211 GetShillManagerClient()->Init(GetSystemBus()); | 211 GetImageBurnerClient()->Init(GetSystemBus()); |
| 212 GetShillServiceClient()->Init(GetSystemBus()); | 212 if (GetLorgnetteManagerClient()) |
| 213 GetShillProfileClient()->Init(GetSystemBus()); | 213 GetLorgnetteManagerClient()->Init(GetSystemBus()); |
| 214 GetShillThirdPartyVpnDriverClient()->Init(GetSystemBus()); | 214 if (GetModemMessagingClient()) |
| 215 GetSMSClient()->Init(GetSystemBus()); | 215 GetModemMessagingClient()->Init(GetSystemBus()); |
| 216 GetSystemClockClient()->Init(GetSystemBus()); | 216 if (GetPermissionBrokerClient()) |
| 217 GetUpdateEngineClient()->Init(GetSystemBus()); | 217 GetPermissionBrokerClient()->Init(GetSystemBus()); |
| 218 if (GetPowerManagerClient()) |
| 219 GetPowerManagerClient()->Init(GetSystemBus()); |
| 220 if (GetSessionManagerClient()) |
| 221 GetSessionManagerClient()->Init(GetSystemBus()); |
| 222 if (GetShillDeviceClient()) |
| 223 GetShillDeviceClient()->Init(GetSystemBus()); |
| 224 if (GetShillIPConfigClient()) |
| 225 GetShillIPConfigClient()->Init(GetSystemBus()); |
| 226 if (GetShillManagerClient()) |
| 227 GetShillManagerClient()->Init(GetSystemBus()); |
| 228 if (GetShillServiceClient()) |
| 229 GetShillServiceClient()->Init(GetSystemBus()); |
| 230 if (GetShillProfileClient()) |
| 231 GetShillProfileClient()->Init(GetSystemBus()); |
| 232 if (GetShillThirdPartyVpnDriverClient()) |
| 233 GetShillThirdPartyVpnDriverClient()->Init(GetSystemBus()); |
| 234 if (GetSMSClient()) |
| 235 GetSMSClient()->Init(GetSystemBus()); |
| 236 if (GetSystemClockClient()) |
| 237 GetSystemClockClient()->Init(GetSystemBus()); |
| 238 if (GetUpdateEngineClient()) |
| 239 GetUpdateEngineClient()->Init(GetSystemBus()); |
| 218 | 240 |
| 219 client_bundle_->SetupDefaultEnvironment(); | 241 client_bundle_->SetupDefaultEnvironment(); |
| 220 } | 242 } |
| 221 | 243 |
| 222 bool DBusThreadManager::IsUsingStub(DBusClientBundle::DBusClientType client) { | 244 bool DBusThreadManager::IsUsingFake(DBusClientBundle::DBusClientType client) { |
| 223 return client_bundle_->IsUsingStub(client); | 245 return client_bundle_->IsUsingFake(client); |
| 224 } | 246 } |
| 225 | 247 |
| 226 // static | 248 // static |
| 227 void DBusThreadManager::Initialize() { | 249 void DBusThreadManager::Initialize() { |
| 250 Initialize(DBusClientBundle::ALL_CLIENTS); |
| 251 } |
| 252 |
| 253 // static |
| 254 void DBusThreadManager::Initialize(DBusClientTypeMask clients) { |
| 228 // If we initialize DBusThreadManager twice we may also be shutting it down | 255 // If we initialize DBusThreadManager twice we may also be shutting it down |
| 229 // early; do not allow that. | 256 // early; do not allow that. |
| 230 if (g_using_dbus_thread_manager_for_testing) | 257 if (g_using_dbus_thread_manager_for_testing) |
| 231 return; | 258 return; |
| 232 | 259 |
| 233 CHECK(!g_dbus_thread_manager); | 260 CHECK(!g_dbus_thread_manager); |
| 234 bool use_dbus_stub = !base::SysInfo::IsRunningOnChromeOS() || | 261 bool use_dbus_stub = !base::SysInfo::IsRunningOnChromeOS() || |
| 235 base::CommandLine::ForCurrentProcess()->HasSwitch( | 262 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 236 chromeos::switches::kDbusStub); | 263 chromeos::switches::kDbusStub); |
| 237 bool force_unstub_clients = base::CommandLine::ForCurrentProcess()->HasSwitch( | 264 bool force_unstub_clients = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 238 chromeos::switches::kDbusUnstubClients); | 265 chromeos::switches::kDbusUnstubClients); |
| 239 // Determine whether we use stub or real client implementations. | 266 // Determine whether we use stub or real client implementations. |
| 240 if (force_unstub_clients) { | 267 if (force_unstub_clients) { |
| 241 InitializeWithPartialStub( | 268 InitializeWithPartialFakes( |
| 242 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 269 clients, base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 243 chromeos::switches::kDbusUnstubClients)); | 270 chromeos::switches::kDbusUnstubClients)); |
| 244 } else if (use_dbus_stub) { | 271 } else if (use_dbus_stub) { |
| 245 InitializeWithStubs(); | 272 InitializeWithFakeClients(clients); |
| 246 } else { | 273 } else { |
| 247 InitializeWithRealClients(); | 274 InitializeWithRealClients(clients); |
| 248 } | 275 } |
| 249 } | 276 } |
| 250 | 277 |
| 251 // static | 278 // static |
| 252 std::unique_ptr<DBusThreadManagerSetter> | 279 std::unique_ptr<DBusThreadManagerSetter> |
| 253 DBusThreadManager::GetSetterForTesting() { | 280 DBusThreadManager::GetSetterForTesting() { |
| 254 if (!g_using_dbus_thread_manager_for_testing) { | 281 if (!g_using_dbus_thread_manager_for_testing) { |
| 255 g_using_dbus_thread_manager_for_testing = true; | 282 g_using_dbus_thread_manager_for_testing = true; |
| 256 InitializeWithStubs(); | 283 InitializeWithFakeClients(DBusClientBundle::ALL_CLIENTS); |
| 257 } | 284 } |
| 258 | 285 |
| 259 return base::WrapUnique(new DBusThreadManagerSetter()); | 286 return base::WrapUnique(new DBusThreadManagerSetter()); |
| 260 } | 287 } |
| 261 | 288 |
| 262 // static | 289 // static |
| 263 void DBusThreadManager::CreateGlobalInstance( | 290 void DBusThreadManager::CreateGlobalInstance(DBusClientTypeMask real_clients, |
| 264 DBusClientBundle::DBusClientTypeMask unstub_client_mask) { | 291 DBusClientTypeMask fake_clients) { |
| 265 CHECK(!g_dbus_thread_manager); | 292 CHECK(!g_dbus_thread_manager); |
| 266 g_dbus_thread_manager = new DBusThreadManager( | 293 g_dbus_thread_manager = new DBusThreadManager( |
| 267 base::MakeUnique<DBusClientBundle>(unstub_client_mask)); | 294 base::MakeUnique<DBusClientBundle>(real_clients, fake_clients)); |
| 268 g_dbus_thread_manager->InitializeClients(); | 295 g_dbus_thread_manager->InitializeClients(); |
| 269 } | 296 } |
| 270 | 297 |
| 271 // static | 298 // static |
| 272 void DBusThreadManager::InitializeWithRealClients() { | 299 void DBusThreadManager::InitializeWithRealClients( |
| 273 CreateGlobalInstance(~static_cast<DBusClientBundle::DBusClientTypeMask>(0)); | 300 DBusClientTypeMask real_clients) { |
| 301 const DBusClientTypeMask fake_clients = DBusClientBundle::NO_CLIENT; |
| 302 CreateGlobalInstance(real_clients, fake_clients); |
| 274 VLOG(1) << "DBusThreadManager initialized for Chrome OS"; | 303 VLOG(1) << "DBusThreadManager initialized for Chrome OS"; |
| 275 } | 304 } |
| 276 | 305 |
| 277 // static | 306 // static |
| 278 void DBusThreadManager::InitializeWithStubs() { | 307 void DBusThreadManager::InitializeWithFakeClients( |
| 279 CreateGlobalInstance(0 /* unstub_client_mask */); | 308 DBusClientTypeMask fake_clients) { |
| 309 const DBusClientTypeMask real_clients = DBusClientBundle::NO_CLIENT; |
| 310 CreateGlobalInstance(real_clients, fake_clients); |
| 280 VLOG(1) << "DBusThreadManager created for testing"; | 311 VLOG(1) << "DBusThreadManager created for testing"; |
| 281 } | 312 } |
| 282 | 313 |
| 283 // static | 314 // static |
| 284 void DBusThreadManager::InitializeWithPartialStub( | 315 void DBusThreadManager::InitializeWithPartialFakes( |
| 285 const std::string& unstub_clients) { | 316 DBusClientTypeMask clients, |
| 286 DBusClientBundle::DBusClientTypeMask unstub_client_mask = | 317 const std::string& force_real_clients_list) { |
| 287 DBusClientBundle::ParseUnstubList(unstub_clients); | 318 DBusClientTypeMask real_clients = |
| 319 DBusClientBundle::ParseUnstubList(force_real_clients_list); |
| 288 // We should have something parsed correctly here. | 320 // We should have something parsed correctly here. |
| 289 LOG_IF(FATAL, unstub_client_mask == 0) | 321 LOG_IF(FATAL, real_clients == 0) << "Switch values for --" |
| 290 << "Switch values for --" << chromeos::switches::kDbusUnstubClients | 322 << chromeos::switches::kDbusUnstubClients |
| 291 << " cannot be parsed: " << unstub_clients; | 323 << " cannot be parsed: " << real_clients; |
| 292 VLOG(1) << "DBusThreadManager initialized for mixed runtime environment"; | 324 VLOG(1) << "DBusThreadManager initialized for mixed runtime environment"; |
| 293 CreateGlobalInstance(unstub_client_mask); | 325 DBusClientTypeMask fake_clients = clients & ~real_clients; |
| 326 CreateGlobalInstance(real_clients, fake_clients); |
| 294 } | 327 } |
| 295 | 328 |
| 296 // static | 329 // static |
| 297 bool DBusThreadManager::IsInitialized() { | 330 bool DBusThreadManager::IsInitialized() { |
| 298 return g_dbus_thread_manager != NULL; | 331 return g_dbus_thread_manager != NULL; |
| 299 } | 332 } |
| 300 | 333 |
| 301 // static | 334 // static |
| 302 void DBusThreadManager::Shutdown() { | 335 void DBusThreadManager::Shutdown() { |
| 303 // Ensure that we only shutdown DBusThreadManager once. | 336 // Ensure that we only shutdown DBusThreadManager once. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 std::move(client); | 473 std::move(client); |
| 441 } | 474 } |
| 442 | 475 |
| 443 void DBusThreadManagerSetter::SetUpdateEngineClient( | 476 void DBusThreadManagerSetter::SetUpdateEngineClient( |
| 444 std::unique_ptr<UpdateEngineClient> client) { | 477 std::unique_ptr<UpdateEngineClient> client) { |
| 445 DBusThreadManager::Get()->client_bundle_->update_engine_client_ = | 478 DBusThreadManager::Get()->client_bundle_->update_engine_client_ = |
| 446 std::move(client); | 479 std::move(client); |
| 447 } | 480 } |
| 448 | 481 |
| 449 } // namespace chromeos | 482 } // namespace chromeos |
| OLD | NEW |