| 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/dbus_clients_browser.h" |
| 20 #include "chromeos/dbus/dbus_clients_common.h" |
| 20 #include "chromeos/dbus/debug_daemon_client.h" | 21 #include "chromeos/dbus/debug_daemon_client.h" |
| 21 #include "chromeos/dbus/easy_unlock_client.h" | 22 #include "chromeos/dbus/easy_unlock_client.h" |
| 22 #include "chromeos/dbus/gsm_sms_client.h" | 23 #include "chromeos/dbus/gsm_sms_client.h" |
| 23 #include "chromeos/dbus/image_burner_client.h" | 24 #include "chromeos/dbus/image_burner_client.h" |
| 24 #include "chromeos/dbus/lorgnette_manager_client.h" | 25 #include "chromeos/dbus/lorgnette_manager_client.h" |
| 25 #include "chromeos/dbus/modem_messaging_client.h" | 26 #include "chromeos/dbus/modem_messaging_client.h" |
| 26 #include "chromeos/dbus/permission_broker_client.h" | 27 #include "chromeos/dbus/permission_broker_client.h" |
| 27 #include "chromeos/dbus/power_manager_client.h" | 28 #include "chromeos/dbus/power_manager_client.h" |
| 28 #include "chromeos/dbus/session_manager_client.h" | 29 #include "chromeos/dbus/session_manager_client.h" |
| 29 #include "chromeos/dbus/shill_device_client.h" | 30 #include "chromeos/dbus/shill_device_client.h" |
| 30 #include "chromeos/dbus/shill_ipconfig_client.h" | 31 #include "chromeos/dbus/shill_ipconfig_client.h" |
| 31 #include "chromeos/dbus/shill_manager_client.h" | 32 #include "chromeos/dbus/shill_manager_client.h" |
| 32 #include "chromeos/dbus/shill_profile_client.h" | 33 #include "chromeos/dbus/shill_profile_client.h" |
| 33 #include "chromeos/dbus/shill_service_client.h" | 34 #include "chromeos/dbus/shill_service_client.h" |
| 34 #include "chromeos/dbus/shill_third_party_vpn_driver_client.h" | 35 #include "chromeos/dbus/shill_third_party_vpn_driver_client.h" |
| 35 #include "chromeos/dbus/sms_client.h" | 36 #include "chromeos/dbus/sms_client.h" |
| 36 #include "chromeos/dbus/system_clock_client.h" | 37 #include "chromeos/dbus/system_clock_client.h" |
| 37 #include "chromeos/dbus/update_engine_client.h" | 38 #include "chromeos/dbus/update_engine_client.h" |
| 38 #include "dbus/bus.h" | 39 #include "dbus/bus.h" |
| 39 #include "dbus/dbus_statistics.h" | 40 #include "dbus/dbus_statistics.h" |
| 40 | 41 |
| 41 namespace chromeos { | 42 namespace chromeos { |
| 42 | 43 |
| 43 static DBusThreadManager* g_dbus_thread_manager = NULL; | 44 static DBusThreadManager* g_dbus_thread_manager = NULL; |
| 44 static bool g_using_dbus_thread_manager_for_testing = false; | 45 static bool g_using_dbus_thread_manager_for_testing = false; |
| 45 | 46 |
| 46 DBusThreadManager::DBusThreadManager( | 47 DBusThreadManager::DBusThreadManager(ProcessMask process_mask, |
| 47 std::unique_ptr<DBusClientBundle> client_bundle) | 48 DBusClientTypeMask real_client_mask) |
| 48 : client_bundle_(std::move(client_bundle)) { | 49 : clients_common_(new DBusClientsCommon(real_client_mask)) { |
| 50 if (process_mask & PROCESS_BROWSER) |
| 51 clients_browser_.reset(new DBusClientsBrowser(real_client_mask)); |
| 52 // NOTE: When there are clients only used by ash, create them here. |
| 53 |
| 49 dbus::statistics::Initialize(); | 54 dbus::statistics::Initialize(); |
| 50 | 55 |
| 51 if (client_bundle_->IsUsingAnyRealClient()) { | 56 if (real_client_mask != 0) { |
| 52 // At least one real DBusClient is used. | 57 // At least one real DBusClient is used. |
| 53 // Create the D-Bus thread. | 58 // Create the D-Bus thread. |
| 54 base::Thread::Options thread_options; | 59 base::Thread::Options thread_options; |
| 55 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; | 60 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 56 dbus_thread_.reset(new base::Thread("D-Bus thread")); | 61 dbus_thread_.reset(new base::Thread("D-Bus thread")); |
| 57 dbus_thread_->StartWithOptions(thread_options); | 62 dbus_thread_->StartWithOptions(thread_options); |
| 58 | 63 |
| 59 // Create the connection to the system bus. | 64 // Create the connection to the system bus. |
| 60 dbus::Bus::Options system_bus_options; | 65 dbus::Bus::Options system_bus_options; |
| 61 system_bus_options.bus_type = dbus::Bus::SYSTEM; | 66 system_bus_options.bus_type = dbus::Bus::SYSTEM; |
| 62 system_bus_options.connection_type = dbus::Bus::PRIVATE; | 67 system_bus_options.connection_type = dbus::Bus::PRIVATE; |
| 63 system_bus_options.dbus_task_runner = dbus_thread_->task_runner(); | 68 system_bus_options.dbus_task_runner = dbus_thread_->task_runner(); |
| 64 system_bus_ = new dbus::Bus(system_bus_options); | 69 system_bus_ = new dbus::Bus(system_bus_options); |
| 65 } | 70 } |
| 66 } | 71 } |
| 67 | 72 |
| 68 DBusThreadManager::~DBusThreadManager() { | 73 DBusThreadManager::~DBusThreadManager() { |
| 69 // Delete all D-Bus clients before shutting down the system bus. | 74 // Delete all D-Bus clients before shutting down the system bus. |
| 70 client_bundle_.reset(); | 75 clients_browser_.reset(); |
| 76 clients_common_.reset(); |
| 71 | 77 |
| 72 // Shut down the bus. During the browser shutdown, it's ok to shut down | 78 // Shut down the bus. During the browser shutdown, it's ok to shut down |
| 73 // the bus synchronously. | 79 // the bus synchronously. |
| 74 if (system_bus_.get()) | 80 if (system_bus_.get()) |
| 75 system_bus_->ShutdownOnDBusThreadAndBlock(); | 81 system_bus_->ShutdownOnDBusThreadAndBlock(); |
| 76 | 82 |
| 77 // Stop the D-Bus thread. | 83 // Stop the D-Bus thread. |
| 78 if (dbus_thread_) | 84 if (dbus_thread_) |
| 79 dbus_thread_->Stop(); | 85 dbus_thread_->Stop(); |
| 80 | 86 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 92 } else { | 98 } else { |
| 93 LOG(FATAL) << "~DBusThreadManager() called outside of Shutdown()"; | 99 LOG(FATAL) << "~DBusThreadManager() called outside of Shutdown()"; |
| 94 } | 100 } |
| 95 } | 101 } |
| 96 | 102 |
| 97 dbus::Bus* DBusThreadManager::GetSystemBus() { | 103 dbus::Bus* DBusThreadManager::GetSystemBus() { |
| 98 return system_bus_.get(); | 104 return system_bus_.get(); |
| 99 } | 105 } |
| 100 | 106 |
| 101 ArcObbMounterClient* DBusThreadManager::GetArcObbMounterClient() { | 107 ArcObbMounterClient* DBusThreadManager::GetArcObbMounterClient() { |
| 102 return client_bundle_->arc_obb_mounter_client(); | 108 return clients_browser_ ? clients_browser_->arc_obb_mounter_client_.get() |
| 109 : nullptr; |
| 103 } | 110 } |
| 104 | 111 |
| 105 CrasAudioClient* DBusThreadManager::GetCrasAudioClient() { | 112 CrasAudioClient* DBusThreadManager::GetCrasAudioClient() { |
| 106 return client_bundle_->cras_audio_client(); | 113 return clients_common_->cras_audio_client_.get(); |
| 107 } | 114 } |
| 108 | 115 |
| 109 CrosDisksClient* DBusThreadManager::GetCrosDisksClient() { | 116 CrosDisksClient* DBusThreadManager::GetCrosDisksClient() { |
| 110 return client_bundle_->cros_disks_client(); | 117 return clients_browser_ ? clients_browser_->cros_disks_client_.get() |
| 118 : nullptr; |
| 111 } | 119 } |
| 112 | 120 |
| 113 CryptohomeClient* DBusThreadManager::GetCryptohomeClient() { | 121 CryptohomeClient* DBusThreadManager::GetCryptohomeClient() { |
| 114 return client_bundle_->cryptohome_client(); | 122 return clients_common_->cryptohome_client_.get(); |
| 115 } | 123 } |
| 116 | 124 |
| 117 DebugDaemonClient* DBusThreadManager::GetDebugDaemonClient() { | 125 DebugDaemonClient* DBusThreadManager::GetDebugDaemonClient() { |
| 118 return client_bundle_->debug_daemon_client(); | 126 return clients_browser_ ? clients_browser_->debug_daemon_client_.get() |
| 127 : nullptr; |
| 119 } | 128 } |
| 120 | 129 |
| 121 EasyUnlockClient* DBusThreadManager::GetEasyUnlockClient() { | 130 EasyUnlockClient* DBusThreadManager::GetEasyUnlockClient() { |
| 122 return client_bundle_->easy_unlock_client(); | 131 return clients_browser_ ? clients_browser_->easy_unlock_client_.get() |
| 132 : nullptr; |
| 123 } | 133 } |
| 124 | 134 |
| 125 LorgnetteManagerClient* | 135 LorgnetteManagerClient* DBusThreadManager::GetLorgnetteManagerClient() { |
| 126 DBusThreadManager::GetLorgnetteManagerClient() { | 136 return clients_browser_ ? clients_browser_->lorgnette_manager_client_.get() |
| 127 return client_bundle_->lorgnette_manager_client(); | 137 : nullptr; |
| 128 } | 138 } |
| 129 | 139 |
| 130 ShillDeviceClient* | 140 ShillDeviceClient* DBusThreadManager::GetShillDeviceClient() { |
| 131 DBusThreadManager::GetShillDeviceClient() { | 141 return clients_common_->shill_device_client_.get(); |
| 132 return client_bundle_->shill_device_client(); | |
| 133 } | 142 } |
| 134 | 143 |
| 135 ShillIPConfigClient* | 144 ShillIPConfigClient* DBusThreadManager::GetShillIPConfigClient() { |
| 136 DBusThreadManager::GetShillIPConfigClient() { | 145 return clients_common_->shill_ipconfig_client_.get(); |
| 137 return client_bundle_->shill_ipconfig_client(); | |
| 138 } | 146 } |
| 139 | 147 |
| 140 ShillManagerClient* | 148 ShillManagerClient* DBusThreadManager::GetShillManagerClient() { |
| 141 DBusThreadManager::GetShillManagerClient() { | 149 return clients_common_->shill_manager_client_.get(); |
| 142 return client_bundle_->shill_manager_client(); | |
| 143 } | 150 } |
| 144 | 151 |
| 145 ShillServiceClient* | 152 ShillServiceClient* DBusThreadManager::GetShillServiceClient() { |
| 146 DBusThreadManager::GetShillServiceClient() { | 153 return clients_common_->shill_service_client_.get(); |
| 147 return client_bundle_->shill_service_client(); | |
| 148 } | 154 } |
| 149 | 155 |
| 150 ShillProfileClient* | 156 ShillProfileClient* DBusThreadManager::GetShillProfileClient() { |
| 151 DBusThreadManager::GetShillProfileClient() { | 157 return clients_common_->shill_profile_client_.get(); |
| 152 return client_bundle_->shill_profile_client(); | |
| 153 } | 158 } |
| 154 | 159 |
| 155 ShillThirdPartyVpnDriverClient* | 160 ShillThirdPartyVpnDriverClient* |
| 156 DBusThreadManager::GetShillThirdPartyVpnDriverClient() { | 161 DBusThreadManager::GetShillThirdPartyVpnDriverClient() { |
| 157 return client_bundle_->shill_third_party_vpn_driver_client(); | 162 return clients_common_->shill_third_party_vpn_driver_client_.get(); |
| 158 } | 163 } |
| 159 | 164 |
| 160 GsmSMSClient* DBusThreadManager::GetGsmSMSClient() { | 165 GsmSMSClient* DBusThreadManager::GetGsmSMSClient() { |
| 161 return client_bundle_->gsm_sms_client(); | 166 return clients_common_->gsm_sms_client_.get(); |
| 162 } | 167 } |
| 163 | 168 |
| 164 ImageBurnerClient* DBusThreadManager::GetImageBurnerClient() { | 169 ImageBurnerClient* DBusThreadManager::GetImageBurnerClient() { |
| 165 return client_bundle_->image_burner_client(); | 170 return clients_browser_ ? clients_browser_->image_burner_client_.get() |
| 171 : nullptr; |
| 166 } | 172 } |
| 167 | 173 |
| 168 ModemMessagingClient* DBusThreadManager::GetModemMessagingClient() { | 174 ModemMessagingClient* DBusThreadManager::GetModemMessagingClient() { |
| 169 return client_bundle_->modem_messaging_client(); | 175 return clients_common_->modem_messaging_client_.get(); |
| 170 } | 176 } |
| 171 | 177 |
| 172 PermissionBrokerClient* DBusThreadManager::GetPermissionBrokerClient() { | 178 PermissionBrokerClient* DBusThreadManager::GetPermissionBrokerClient() { |
| 173 return client_bundle_->permission_broker_client(); | 179 return clients_common_->permission_broker_client_.get(); |
| 174 } | 180 } |
| 175 | 181 |
| 176 PowerManagerClient* DBusThreadManager::GetPowerManagerClient() { | 182 PowerManagerClient* DBusThreadManager::GetPowerManagerClient() { |
| 177 return client_bundle_->power_manager_client(); | 183 return clients_common_->power_manager_client_.get(); |
| 178 } | 184 } |
| 179 | 185 |
| 180 SessionManagerClient* DBusThreadManager::GetSessionManagerClient() { | 186 SessionManagerClient* DBusThreadManager::GetSessionManagerClient() { |
| 181 return client_bundle_->session_manager_client(); | 187 return clients_common_->session_manager_client_.get(); |
| 182 } | 188 } |
| 183 | 189 |
| 184 SMSClient* DBusThreadManager::GetSMSClient() { | 190 SMSClient* DBusThreadManager::GetSMSClient() { |
| 185 return client_bundle_->sms_client(); | 191 return clients_common_->sms_client_.get(); |
| 186 } | 192 } |
| 187 | 193 |
| 188 SystemClockClient* DBusThreadManager::GetSystemClockClient() { | 194 SystemClockClient* DBusThreadManager::GetSystemClockClient() { |
| 189 return client_bundle_->system_clock_client(); | 195 return clients_common_->system_clock_client_.get(); |
| 190 } | 196 } |
| 191 | 197 |
| 192 UpdateEngineClient* DBusThreadManager::GetUpdateEngineClient() { | 198 UpdateEngineClient* DBusThreadManager::GetUpdateEngineClient() { |
| 193 return client_bundle_->update_engine_client(); | 199 return clients_common_->update_engine_client_.get(); |
| 194 } | 200 } |
| 195 | 201 |
| 196 void DBusThreadManager::InitializeClients() { | 202 void DBusThreadManager::InitializeClients() { |
| 197 GetArcObbMounterClient()->Init(GetSystemBus()); | 203 clients_common_->Initialize(GetSystemBus()); |
| 198 GetCrasAudioClient()->Init(GetSystemBus()); | 204 if (clients_browser_) |
| 199 GetCrosDisksClient()->Init(GetSystemBus()); | 205 clients_browser_->Initialize(GetSystemBus()); |
| 200 GetCryptohomeClient()->Init(GetSystemBus()); | |
| 201 GetDebugDaemonClient()->Init(GetSystemBus()); | |
| 202 GetEasyUnlockClient()->Init(GetSystemBus()); | |
| 203 GetGsmSMSClient()->Init(GetSystemBus()); | |
| 204 GetImageBurnerClient()->Init(GetSystemBus()); | |
| 205 GetLorgnetteManagerClient()->Init(GetSystemBus()); | |
| 206 GetModemMessagingClient()->Init(GetSystemBus()); | |
| 207 GetPermissionBrokerClient()->Init(GetSystemBus()); | |
| 208 GetPowerManagerClient()->Init(GetSystemBus()); | |
| 209 GetSessionManagerClient()->Init(GetSystemBus()); | |
| 210 GetShillDeviceClient()->Init(GetSystemBus()); | |
| 211 GetShillIPConfigClient()->Init(GetSystemBus()); | |
| 212 GetShillManagerClient()->Init(GetSystemBus()); | |
| 213 GetShillServiceClient()->Init(GetSystemBus()); | |
| 214 GetShillProfileClient()->Init(GetSystemBus()); | |
| 215 GetShillThirdPartyVpnDriverClient()->Init(GetSystemBus()); | |
| 216 GetSMSClient()->Init(GetSystemBus()); | |
| 217 GetSystemClockClient()->Init(GetSystemBus()); | |
| 218 GetUpdateEngineClient()->Init(GetSystemBus()); | |
| 219 | |
| 220 client_bundle_->SetupDefaultEnvironment(); | |
| 221 } | 206 } |
| 222 | 207 |
| 223 bool DBusThreadManager::IsUsingFake(DBusClientType client) { | 208 bool DBusThreadManager::IsUsingFake(DBusClientType client) { |
| 224 return !client_bundle_->IsUsingReal(client); | 209 return !clients_common_->IsUsingReal(client); |
| 225 } | 210 } |
| 226 | 211 |
| 227 // static | 212 // static |
| 228 void DBusThreadManager::Initialize() { | 213 void DBusThreadManager::Initialize(ProcessMask process_mask) { |
| 229 // If we initialize DBusThreadManager twice we may also be shutting it down | 214 // If we initialize DBusThreadManager twice we may also be shutting it down |
| 230 // early; do not allow that. | 215 // early; do not allow that. |
| 231 if (g_using_dbus_thread_manager_for_testing) | 216 if (g_using_dbus_thread_manager_for_testing) |
| 232 return; | 217 return; |
| 233 | 218 |
| 234 CHECK(!g_dbus_thread_manager); | 219 CHECK(!g_dbus_thread_manager); |
| 235 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 220 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 236 bool use_fakes = !base::SysInfo::IsRunningOnChromeOS() || | 221 bool use_fakes = !base::SysInfo::IsRunningOnChromeOS() || |
| 237 command_line->HasSwitch(chromeos::switches::kDbusStub); | 222 command_line->HasSwitch(chromeos::switches::kDbusStub); |
| 238 // TODO(jamescook): Delete this after M56 branches. | 223 // TODO(jamescook): Delete this after M56 branches. |
| 239 if (command_line->HasSwitch(chromeos::switches::kDbusUnstubClients)) | 224 if (command_line->HasSwitch(chromeos::switches::kDbusUnstubClients)) |
| 240 LOG(FATAL) << "Use --dbus-real-clients instead of --dbus-unstub-clients."; | 225 LOG(FATAL) << "Use --dbus-real-clients instead of --dbus-unstub-clients."; |
| 241 bool force_real_clients = | 226 bool force_real_clients = |
| 242 command_line->HasSwitch(chromeos::switches::kDbusRealClients); | 227 command_line->HasSwitch(chromeos::switches::kDbusRealClients); |
| 243 // Determine whether we use fake or real client implementations. | 228 // Determine whether we use fake or real client implementations. |
| 244 if (force_real_clients) { | 229 if (force_real_clients) { |
| 245 InitializeWithPartialFakes(command_line->GetSwitchValueASCII( | 230 InitializeWithPartialFakes(process_mask, |
| 246 chromeos::switches::kDbusRealClients)); | 231 command_line->GetSwitchValueASCII( |
| 232 chromeos::switches::kDbusRealClients)); |
| 247 } else if (use_fakes) { | 233 } else if (use_fakes) { |
| 248 InitializeWithFakeClients(); | 234 InitializeWithFakeClients(process_mask); |
| 249 } else { | 235 } else { |
| 250 InitializeWithRealClients(); | 236 InitializeWithRealClients(process_mask); |
| 251 } | 237 } |
| 252 } | 238 } |
| 253 | 239 |
| 254 // static | 240 // static |
| 241 void DBusThreadManager::Initialize() { |
| 242 Initialize(PROCESS_ALL); |
| 243 } |
| 244 |
| 245 // static |
| 255 std::unique_ptr<DBusThreadManagerSetter> | 246 std::unique_ptr<DBusThreadManagerSetter> |
| 256 DBusThreadManager::GetSetterForTesting() { | 247 DBusThreadManager::GetSetterForTesting() { |
| 257 if (!g_using_dbus_thread_manager_for_testing) { | 248 if (!g_using_dbus_thread_manager_for_testing) { |
| 258 g_using_dbus_thread_manager_for_testing = true; | 249 g_using_dbus_thread_manager_for_testing = true; |
| 259 InitializeWithFakeClients(); | 250 // TODO(jamescook): Don't initialize clients as a side-effect of using a |
| 251 // test API. For now, assume the caller wants all clients. |
| 252 InitializeWithFakeClients(PROCESS_ALL); |
| 260 } | 253 } |
| 261 | 254 |
| 262 return base::WrapUnique(new DBusThreadManagerSetter()); | 255 return base::WrapUnique(new DBusThreadManagerSetter()); |
| 263 } | 256 } |
| 264 | 257 |
| 265 // static | 258 // static |
| 266 void DBusThreadManager::CreateGlobalInstance( | 259 void DBusThreadManager::CreateGlobalInstance( |
| 260 ProcessMask process_mask, |
| 267 DBusClientTypeMask real_client_mask) { | 261 DBusClientTypeMask real_client_mask) { |
| 268 CHECK(!g_dbus_thread_manager); | 262 CHECK(!g_dbus_thread_manager); |
| 269 g_dbus_thread_manager = new DBusThreadManager( | 263 g_dbus_thread_manager = new DBusThreadManager(process_mask, real_client_mask); |
| 270 base::MakeUnique<DBusClientBundle>(real_client_mask)); | |
| 271 g_dbus_thread_manager->InitializeClients(); | 264 g_dbus_thread_manager->InitializeClients(); |
| 272 } | 265 } |
| 273 | 266 |
| 274 // static | 267 // static |
| 275 void DBusThreadManager::InitializeWithRealClients() { | 268 void DBusThreadManager::InitializeWithRealClients(ProcessMask process_mask) { |
| 276 CreateGlobalInstance(static_cast<DBusClientTypeMask>(DBusClientType::ALL)); | 269 CreateGlobalInstance(process_mask, |
| 270 static_cast<DBusClientTypeMask>(DBusClientType::ALL)); |
| 277 VLOG(1) << "DBusThreadManager initialized for Chrome OS"; | 271 VLOG(1) << "DBusThreadManager initialized for Chrome OS"; |
| 278 } | 272 } |
| 279 | 273 |
| 280 // static | 274 // static |
| 281 void DBusThreadManager::InitializeWithFakeClients() { | 275 void DBusThreadManager::InitializeWithFakeClients(ProcessMask process_mask) { |
| 282 CreateGlobalInstance(static_cast<DBusClientTypeMask>(DBusClientType::NONE)); | 276 CreateGlobalInstance(process_mask, |
| 277 static_cast<DBusClientTypeMask>(DBusClientType::NONE)); |
| 283 VLOG(1) << "DBusThreadManager created for testing"; | 278 VLOG(1) << "DBusThreadManager created for testing"; |
| 284 } | 279 } |
| 285 | 280 |
| 286 // static | 281 // static |
| 287 void DBusThreadManager::InitializeWithPartialFakes( | 282 void DBusThreadManager::InitializeWithPartialFakes( |
| 283 ProcessMask process_mask, |
| 288 const std::string& force_real_clients) { | 284 const std::string& force_real_clients) { |
| 289 DBusClientTypeMask real_client_mask = | 285 DBusClientTypeMask real_client_mask = |
| 290 ParseDBusRealClientsList(force_real_clients); | 286 ParseDBusRealClientsList(force_real_clients); |
| 291 // We should have something parsed correctly here. | 287 // We should have something parsed correctly here. |
| 292 LOG_IF(FATAL, real_client_mask == 0) | 288 LOG_IF(FATAL, real_client_mask == 0) |
| 293 << "Switch values for --" << chromeos::switches::kDbusRealClients | 289 << "Switch values for --" << chromeos::switches::kDbusRealClients |
| 294 << " cannot be parsed: " << real_client_mask; | 290 << " cannot be parsed: " << real_client_mask; |
| 295 VLOG(1) << "DBusThreadManager initialized for mixed runtime environment"; | 291 VLOG(1) << "DBusThreadManager initialized for mixed runtime environment"; |
| 296 CreateGlobalInstance(real_client_mask); | 292 CreateGlobalInstance(process_mask, real_client_mask); |
| 297 } | 293 } |
| 298 | 294 |
| 299 // static | 295 // static |
| 300 bool DBusThreadManager::IsInitialized() { | 296 bool DBusThreadManager::IsInitialized() { |
| 301 return g_dbus_thread_manager != NULL; | 297 return g_dbus_thread_manager != NULL; |
| 302 } | 298 } |
| 303 | 299 |
| 304 // static | 300 // static |
| 305 void DBusThreadManager::Shutdown() { | 301 void DBusThreadManager::Shutdown() { |
| 306 // Ensure that we only shutdown DBusThreadManager once. | 302 // Ensure that we only shutdown DBusThreadManager once. |
| 307 CHECK(g_dbus_thread_manager); | 303 CHECK(g_dbus_thread_manager); |
| 308 DBusThreadManager* dbus_thread_manager = g_dbus_thread_manager; | 304 DBusThreadManager* dbus_thread_manager = g_dbus_thread_manager; |
| 309 g_dbus_thread_manager = NULL; | 305 g_dbus_thread_manager = NULL; |
| 310 g_using_dbus_thread_manager_for_testing = false; | 306 g_using_dbus_thread_manager_for_testing = false; |
| 311 delete dbus_thread_manager; | 307 delete dbus_thread_manager; |
| 312 VLOG(1) << "DBusThreadManager Shutdown completed"; | 308 VLOG(1) << "DBusThreadManager Shutdown completed"; |
| 313 } | 309 } |
| 314 | 310 |
| 315 // static | 311 // static |
| 316 DBusThreadManager* DBusThreadManager::Get() { | 312 DBusThreadManager* DBusThreadManager::Get() { |
| 317 CHECK(g_dbus_thread_manager) | 313 CHECK(g_dbus_thread_manager) |
| 318 << "DBusThreadManager::Get() called before Initialize()"; | 314 << "DBusThreadManager::Get() called before Initialize()"; |
| 319 return g_dbus_thread_manager; | 315 return g_dbus_thread_manager; |
| 320 } | 316 } |
| 321 | 317 |
| 322 DBusThreadManagerSetter::DBusThreadManagerSetter() { | 318 DBusThreadManagerSetter::DBusThreadManagerSetter() {} |
| 323 } | |
| 324 | 319 |
| 325 DBusThreadManagerSetter::~DBusThreadManagerSetter() { | 320 DBusThreadManagerSetter::~DBusThreadManagerSetter() {} |
| 326 } | |
| 327 | 321 |
| 328 void DBusThreadManagerSetter::SetCrasAudioClient( | 322 void DBusThreadManagerSetter::SetCrasAudioClient( |
| 329 std::unique_ptr<CrasAudioClient> client) { | 323 std::unique_ptr<CrasAudioClient> client) { |
| 330 DBusThreadManager::Get()->client_bundle_->cras_audio_client_ = | 324 DBusThreadManager::Get()->clients_common_->cras_audio_client_ = |
| 331 std::move(client); | 325 std::move(client); |
| 332 } | 326 } |
| 333 | 327 |
| 334 void DBusThreadManagerSetter::SetCrosDisksClient( | 328 void DBusThreadManagerSetter::SetCrosDisksClient( |
| 335 std::unique_ptr<CrosDisksClient> client) { | 329 std::unique_ptr<CrosDisksClient> client) { |
| 336 DBusThreadManager::Get()->client_bundle_->cros_disks_client_ = | 330 DBusThreadManager::Get()->clients_browser_->cros_disks_client_ = |
| 337 std::move(client); | 331 std::move(client); |
| 338 } | 332 } |
| 339 | 333 |
| 340 void DBusThreadManagerSetter::SetCryptohomeClient( | 334 void DBusThreadManagerSetter::SetCryptohomeClient( |
| 341 std::unique_ptr<CryptohomeClient> client) { | 335 std::unique_ptr<CryptohomeClient> client) { |
| 342 DBusThreadManager::Get()->client_bundle_->cryptohome_client_ = | 336 DBusThreadManager::Get()->clients_common_->cryptohome_client_ = |
| 343 std::move(client); | 337 std::move(client); |
| 344 } | 338 } |
| 345 | 339 |
| 346 void DBusThreadManagerSetter::SetDebugDaemonClient( | 340 void DBusThreadManagerSetter::SetDebugDaemonClient( |
| 347 std::unique_ptr<DebugDaemonClient> client) { | 341 std::unique_ptr<DebugDaemonClient> client) { |
| 348 DBusThreadManager::Get()->client_bundle_->debug_daemon_client_ = | 342 DBusThreadManager::Get()->clients_browser_->debug_daemon_client_ = |
| 349 std::move(client); | |
| 350 } | |
| 351 | |
| 352 void DBusThreadManagerSetter::SetEasyUnlockClient( | |
| 353 std::unique_ptr<EasyUnlockClient> client) { | |
| 354 DBusThreadManager::Get()->client_bundle_->easy_unlock_client_ = | |
| 355 std::move(client); | |
| 356 } | |
| 357 | |
| 358 void DBusThreadManagerSetter::SetLorgnetteManagerClient( | |
| 359 std::unique_ptr<LorgnetteManagerClient> client) { | |
| 360 DBusThreadManager::Get()->client_bundle_->lorgnette_manager_client_ = | |
| 361 std::move(client); | 343 std::move(client); |
| 362 } | 344 } |
| 363 | 345 |
| 364 void DBusThreadManagerSetter::SetShillDeviceClient( | 346 void DBusThreadManagerSetter::SetShillDeviceClient( |
| 365 std::unique_ptr<ShillDeviceClient> client) { | 347 std::unique_ptr<ShillDeviceClient> client) { |
| 366 DBusThreadManager::Get()->client_bundle_->shill_device_client_ = | 348 DBusThreadManager::Get()->clients_common_->shill_device_client_ = |
| 367 std::move(client); | 349 std::move(client); |
| 368 } | 350 } |
| 369 | 351 |
| 370 void DBusThreadManagerSetter::SetShillIPConfigClient( | 352 void DBusThreadManagerSetter::SetShillIPConfigClient( |
| 371 std::unique_ptr<ShillIPConfigClient> client) { | 353 std::unique_ptr<ShillIPConfigClient> client) { |
| 372 DBusThreadManager::Get()->client_bundle_->shill_ipconfig_client_ = | 354 DBusThreadManager::Get()->clients_common_->shill_ipconfig_client_ = |
| 373 std::move(client); | 355 std::move(client); |
| 374 } | 356 } |
| 375 | 357 |
| 376 void DBusThreadManagerSetter::SetShillManagerClient( | 358 void DBusThreadManagerSetter::SetShillManagerClient( |
| 377 std::unique_ptr<ShillManagerClient> client) { | 359 std::unique_ptr<ShillManagerClient> client) { |
| 378 DBusThreadManager::Get()->client_bundle_->shill_manager_client_ = | 360 DBusThreadManager::Get()->clients_common_->shill_manager_client_ = |
| 379 std::move(client); | 361 std::move(client); |
| 380 } | 362 } |
| 381 | 363 |
| 382 void DBusThreadManagerSetter::SetShillServiceClient( | 364 void DBusThreadManagerSetter::SetShillServiceClient( |
| 383 std::unique_ptr<ShillServiceClient> client) { | 365 std::unique_ptr<ShillServiceClient> client) { |
| 384 DBusThreadManager::Get()->client_bundle_->shill_service_client_ = | 366 DBusThreadManager::Get()->clients_common_->shill_service_client_ = |
| 385 std::move(client); | 367 std::move(client); |
| 386 } | 368 } |
| 387 | 369 |
| 388 void DBusThreadManagerSetter::SetShillProfileClient( | 370 void DBusThreadManagerSetter::SetShillProfileClient( |
| 389 std::unique_ptr<ShillProfileClient> client) { | 371 std::unique_ptr<ShillProfileClient> client) { |
| 390 DBusThreadManager::Get()->client_bundle_->shill_profile_client_ = | 372 DBusThreadManager::Get()->clients_common_->shill_profile_client_ = |
| 391 std::move(client); | 373 std::move(client); |
| 392 } | 374 } |
| 393 | 375 |
| 394 void DBusThreadManagerSetter::SetShillThirdPartyVpnDriverClient( | 376 void DBusThreadManagerSetter::SetShillThirdPartyVpnDriverClient( |
| 395 std::unique_ptr<ShillThirdPartyVpnDriverClient> client) { | 377 std::unique_ptr<ShillThirdPartyVpnDriverClient> client) { |
| 396 DBusThreadManager::Get() | 378 DBusThreadManager::Get() |
| 397 ->client_bundle_->shill_third_party_vpn_driver_client_ = | 379 ->clients_common_->shill_third_party_vpn_driver_client_ = |
| 398 std::move(client); | 380 std::move(client); |
| 399 } | 381 } |
| 400 | 382 |
| 401 void DBusThreadManagerSetter::SetGsmSMSClient( | |
| 402 std::unique_ptr<GsmSMSClient> client) { | |
| 403 DBusThreadManager::Get()->client_bundle_->gsm_sms_client_ = std::move(client); | |
| 404 } | |
| 405 | |
| 406 void DBusThreadManagerSetter::SetImageBurnerClient( | 383 void DBusThreadManagerSetter::SetImageBurnerClient( |
| 407 std::unique_ptr<ImageBurnerClient> client) { | 384 std::unique_ptr<ImageBurnerClient> client) { |
| 408 DBusThreadManager::Get()->client_bundle_->image_burner_client_ = | 385 DBusThreadManager::Get()->clients_browser_->image_burner_client_ = |
| 409 std::move(client); | |
| 410 } | |
| 411 | |
| 412 void DBusThreadManagerSetter::SetModemMessagingClient( | |
| 413 std::unique_ptr<ModemMessagingClient> client) { | |
| 414 DBusThreadManager::Get()->client_bundle_->modem_messaging_client_ = | |
| 415 std::move(client); | 386 std::move(client); |
| 416 } | 387 } |
| 417 | 388 |
| 418 void DBusThreadManagerSetter::SetPermissionBrokerClient( | 389 void DBusThreadManagerSetter::SetPermissionBrokerClient( |
| 419 std::unique_ptr<PermissionBrokerClient> client) { | 390 std::unique_ptr<PermissionBrokerClient> client) { |
| 420 DBusThreadManager::Get()->client_bundle_->permission_broker_client_ = | 391 DBusThreadManager::Get()->clients_common_->permission_broker_client_ = |
| 421 std::move(client); | 392 std::move(client); |
| 422 } | 393 } |
| 423 | 394 |
| 424 void DBusThreadManagerSetter::SetPowerManagerClient( | 395 void DBusThreadManagerSetter::SetPowerManagerClient( |
| 425 std::unique_ptr<PowerManagerClient> client) { | 396 std::unique_ptr<PowerManagerClient> client) { |
| 426 DBusThreadManager::Get()->client_bundle_->power_manager_client_ = | 397 DBusThreadManager::Get()->clients_common_->power_manager_client_ = |
| 427 std::move(client); | 398 std::move(client); |
| 428 } | 399 } |
| 429 | 400 |
| 430 void DBusThreadManagerSetter::SetSessionManagerClient( | 401 void DBusThreadManagerSetter::SetSessionManagerClient( |
| 431 std::unique_ptr<SessionManagerClient> client) { | 402 std::unique_ptr<SessionManagerClient> client) { |
| 432 DBusThreadManager::Get()->client_bundle_->session_manager_client_ = | 403 DBusThreadManager::Get()->clients_common_->session_manager_client_ = |
| 433 std::move(client); | |
| 434 } | |
| 435 | |
| 436 void DBusThreadManagerSetter::SetSMSClient(std::unique_ptr<SMSClient> client) { | |
| 437 DBusThreadManager::Get()->client_bundle_->sms_client_ = std::move(client); | |
| 438 } | |
| 439 | |
| 440 void DBusThreadManagerSetter::SetSystemClockClient( | |
| 441 std::unique_ptr<SystemClockClient> client) { | |
| 442 DBusThreadManager::Get()->client_bundle_->system_clock_client_ = | |
| 443 std::move(client); | 404 std::move(client); |
| 444 } | 405 } |
| 445 | 406 |
| 446 void DBusThreadManagerSetter::SetUpdateEngineClient( | 407 void DBusThreadManagerSetter::SetUpdateEngineClient( |
| 447 std::unique_ptr<UpdateEngineClient> client) { | 408 std::unique_ptr<UpdateEngineClient> client) { |
| 448 DBusThreadManager::Get()->client_bundle_->update_engine_client_ = | 409 DBusThreadManager::Get()->clients_common_->update_engine_client_ = |
| 449 std::move(client); | 410 std::move(client); |
| 450 } | 411 } |
| 451 | 412 |
| 452 } // namespace chromeos | 413 } // namespace chromeos |
| OLD | NEW |