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

Side by Side Diff: chromeos/dbus/dbus_thread_manager.cc

Issue 2319783002: mash: Allow a subset of D-Bus clients to be created in DBusThreadManager (Closed)
Patch Set: cleanup Created 4 years, 3 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
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
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 // This must be called after the list of clients so they've each had a 241 // This must be called after the list of clients so they've each had a
220 // chance to register with their object g_dbus_thread_managers. 242 // chance to register with their object g_dbus_thread_managers.
221 if (GetSystemBus()) 243 if (GetSystemBus())
222 GetSystemBus()->GetManagedObjects(); 244 GetSystemBus()->GetManagedObjects();
223 245
224 client_bundle_->SetupDefaultEnvironment(); 246 client_bundle_->SetupDefaultEnvironment();
225 } 247 }
226 248
227 bool DBusThreadManager::IsUsingStub(DBusClientBundle::DBusClientType client) { 249 bool DBusThreadManager::IsUsingFake(DBusClientBundle::DBusClientType client) {
228 return client_bundle_->IsUsingStub(client); 250 return client_bundle_->IsUsingFake(client);
229 } 251 }
230 252
231 // static 253 // static
232 void DBusThreadManager::Initialize() { 254 void DBusThreadManager::Initialize() {
255 Initialize(DBusClientBundle::ALL_CLIENTS);
256 }
257
258 // static
259 void DBusThreadManager::Initialize(DBusClientTypeMask clients) {
233 // If we initialize DBusThreadManager twice we may also be shutting it down 260 // If we initialize DBusThreadManager twice we may also be shutting it down
234 // early; do not allow that. 261 // early; do not allow that.
235 if (g_using_dbus_thread_manager_for_testing) 262 if (g_using_dbus_thread_manager_for_testing)
236 return; 263 return;
237 264
238 CHECK(!g_dbus_thread_manager); 265 CHECK(!g_dbus_thread_manager);
239 bool use_dbus_stub = !base::SysInfo::IsRunningOnChromeOS() || 266 bool use_dbus_stub = !base::SysInfo::IsRunningOnChromeOS() ||
240 base::CommandLine::ForCurrentProcess()->HasSwitch( 267 base::CommandLine::ForCurrentProcess()->HasSwitch(
241 chromeos::switches::kDbusStub); 268 chromeos::switches::kDbusStub);
242 bool force_unstub_clients = base::CommandLine::ForCurrentProcess()->HasSwitch( 269 bool force_unstub_clients = base::CommandLine::ForCurrentProcess()->HasSwitch(
243 chromeos::switches::kDbusUnstubClients); 270 chromeos::switches::kDbusUnstubClients);
244 // Determine whether we use stub or real client implementations. 271 // Determine whether we use stub or real client implementations.
245 if (force_unstub_clients) { 272 if (force_unstub_clients) {
246 InitializeWithPartialStub( 273 InitializeWithPartialFakes(
247 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 274 clients, base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
248 chromeos::switches::kDbusUnstubClients)); 275 chromeos::switches::kDbusUnstubClients));
249 } else if (use_dbus_stub) { 276 } else if (use_dbus_stub) {
250 InitializeWithStubs(); 277 InitializeWithFakeClients(clients);
251 } else { 278 } else {
252 InitializeWithRealClients(); 279 InitializeWithRealClients(clients);
253 } 280 }
254 } 281 }
255 282
256 // static 283 // static
257 std::unique_ptr<DBusThreadManagerSetter> 284 std::unique_ptr<DBusThreadManagerSetter>
258 DBusThreadManager::GetSetterForTesting() { 285 DBusThreadManager::GetSetterForTesting() {
259 if (!g_using_dbus_thread_manager_for_testing) { 286 if (!g_using_dbus_thread_manager_for_testing) {
260 g_using_dbus_thread_manager_for_testing = true; 287 g_using_dbus_thread_manager_for_testing = true;
261 InitializeWithStubs(); 288 InitializeWithFakeClients(DBusClientBundle::ALL_CLIENTS);
262 } 289 }
263 290
264 return base::WrapUnique(new DBusThreadManagerSetter()); 291 return base::WrapUnique(new DBusThreadManagerSetter());
265 } 292 }
266 293
267 // static 294 // static
268 void DBusThreadManager::CreateGlobalInstance( 295 void DBusThreadManager::CreateGlobalInstance(DBusClientTypeMask real_clients,
269 DBusClientBundle::DBusClientTypeMask unstub_client_mask) { 296 DBusClientTypeMask fake_clients) {
270 CHECK(!g_dbus_thread_manager); 297 CHECK(!g_dbus_thread_manager);
271 g_dbus_thread_manager = new DBusThreadManager( 298 g_dbus_thread_manager = new DBusThreadManager(
272 base::MakeUnique<DBusClientBundle>(unstub_client_mask)); 299 base::MakeUnique<DBusClientBundle>(real_clients, fake_clients));
273 g_dbus_thread_manager->InitializeClients(); 300 g_dbus_thread_manager->InitializeClients();
274 } 301 }
275 302
276 // static 303 // static
277 void DBusThreadManager::InitializeWithRealClients() { 304 void DBusThreadManager::InitializeWithRealClients(
278 CreateGlobalInstance(~static_cast<DBusClientBundle::DBusClientTypeMask>(0)); 305 DBusClientTypeMask real_clients) {
306 const DBusClientTypeMask fake_clients = DBusClientBundle::NO_CLIENT;
307 CreateGlobalInstance(real_clients, fake_clients);
279 VLOG(1) << "DBusThreadManager initialized for Chrome OS"; 308 VLOG(1) << "DBusThreadManager initialized for Chrome OS";
280 } 309 }
281 310
282 // static 311 // static
283 void DBusThreadManager::InitializeWithStubs() { 312 void DBusThreadManager::InitializeWithFakeClients(
284 CreateGlobalInstance(0 /* unstub_client_mask */); 313 DBusClientTypeMask fake_clients) {
314 const DBusClientTypeMask real_clients = DBusClientBundle::NO_CLIENT;
315 CreateGlobalInstance(real_clients, fake_clients);
285 VLOG(1) << "DBusThreadManager created for testing"; 316 VLOG(1) << "DBusThreadManager created for testing";
286 } 317 }
287 318
288 // static 319 // static
289 void DBusThreadManager::InitializeWithPartialStub( 320 void DBusThreadManager::InitializeWithPartialFakes(
290 const std::string& unstub_clients) { 321 DBusClientTypeMask clients,
291 DBusClientBundle::DBusClientTypeMask unstub_client_mask = 322 const std::string& force_real_clients_list) {
292 DBusClientBundle::ParseUnstubList(unstub_clients); 323 DBusClientTypeMask real_clients =
324 DBusClientBundle::ParseUnstubList(force_real_clients_list);
293 // We should have something parsed correctly here. 325 // We should have something parsed correctly here.
294 LOG_IF(FATAL, unstub_client_mask == 0) 326 LOG_IF(FATAL, real_clients == 0) << "Switch values for --"
295 << "Switch values for --" << chromeos::switches::kDbusUnstubClients 327 << chromeos::switches::kDbusUnstubClients
296 << " cannot be parsed: " << unstub_clients; 328 << " cannot be parsed: " << real_clients;
297 VLOG(1) << "DBusThreadManager initialized for mixed runtime environment"; 329 VLOG(1) << "DBusThreadManager initialized for mixed runtime environment";
298 CreateGlobalInstance(unstub_client_mask); 330 DBusClientTypeMask fake_clients = clients & ~real_clients;
331 CreateGlobalInstance(fake_clients, real_clients);
Daniel Erat 2016/09/07 20:31:59 the parameters here are swapped
James Cook 2016/09/07 20:58:12 Argh. Good catch. Done. I tried to add a test for
299 } 332 }
300 333
301 // static 334 // static
302 bool DBusThreadManager::IsInitialized() { 335 bool DBusThreadManager::IsInitialized() {
303 return g_dbus_thread_manager != NULL; 336 return g_dbus_thread_manager != NULL;
304 } 337 }
305 338
306 // static 339 // static
307 void DBusThreadManager::Shutdown() { 340 void DBusThreadManager::Shutdown() {
308 // Ensure that we only shutdown DBusThreadManager once. 341 // Ensure that we only shutdown DBusThreadManager once.
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 std::move(client); 478 std::move(client);
446 } 479 }
447 480
448 void DBusThreadManagerSetter::SetUpdateEngineClient( 481 void DBusThreadManagerSetter::SetUpdateEngineClient(
449 std::unique_ptr<UpdateEngineClient> client) { 482 std::unique_ptr<UpdateEngineClient> client) {
450 DBusThreadManager::Get()->client_bundle_->update_engine_client_ = 483 DBusThreadManager::Get()->client_bundle_->update_engine_client_ =
451 std::move(client); 484 std::move(client);
452 } 485 }
453 486
454 } // namespace chromeos 487 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698