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

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

Issue 12381002: Improve network stub behavior (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: s/res/enabled Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « chromeos/chromeos_switches.cc ('k') | chromeos/dbus/shill_device_client_stub.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <map> 7 #include <map>
8 8
9 #include "base/chromeos/chromeos_version.h" 9 #include "base/chromeos/chromeos_version.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "dbus/dbus_statistics.h" 47 #include "dbus/dbus_statistics.h"
48 48
49 namespace chromeos { 49 namespace chromeos {
50 50
51 static DBusThreadManager* g_dbus_thread_manager = NULL; 51 static DBusThreadManager* g_dbus_thread_manager = NULL;
52 static bool g_dbus_thread_manager_set_for_testing = false; 52 static bool g_dbus_thread_manager_set_for_testing = false;
53 53
54 // The DBusThreadManager implementation used in production. 54 // The DBusThreadManager implementation used in production.
55 class DBusThreadManagerImpl : public DBusThreadManager { 55 class DBusThreadManagerImpl : public DBusThreadManager {
56 public: 56 public:
57 explicit DBusThreadManagerImpl(DBusClientImplementationType client_type) { 57 explicit DBusThreadManagerImpl(DBusClientImplementationType client_type)
58 : client_type_(client_type),
59 client_type_override_(client_type) {
58 // If --dbus-stub was requested, pass STUB to specific components; 60 // If --dbus-stub was requested, pass STUB to specific components;
59 // Many components like login are not useful with a stub implementation. 61 // Many components like login are not useful with a stub implementation.
60 DBusClientImplementationType client_type_maybe_stub = client_type;
61 if (CommandLine::ForCurrentProcess()->HasSwitch( 62 if (CommandLine::ForCurrentProcess()->HasSwitch(
62 chromeos::switches::kDbusStub)) 63 chromeos::switches::kDbusStub)) {
63 client_type_maybe_stub = STUB_DBUS_CLIENT_IMPLEMENTATION; 64 client_type_override_ = STUB_DBUS_CLIENT_IMPLEMENTATION;
65 }
64 66
65 // Create the D-Bus thread. 67 // Create the D-Bus thread.
66 base::Thread::Options thread_options; 68 base::Thread::Options thread_options;
67 thread_options.message_loop_type = MessageLoop::TYPE_IO; 69 thread_options.message_loop_type = MessageLoop::TYPE_IO;
68 dbus_thread_.reset(new base::Thread("D-Bus thread")); 70 dbus_thread_.reset(new base::Thread("D-Bus thread"));
69 dbus_thread_->StartWithOptions(thread_options); 71 dbus_thread_->StartWithOptions(thread_options);
70 72
71 // Create the connection to the system bus. 73 // Create the connection to the system bus.
72 dbus::Bus::Options system_bus_options; 74 dbus::Bus::Options system_bus_options;
73 system_bus_options.bus_type = dbus::Bus::SYSTEM; 75 system_bus_options.bus_type = dbus::Bus::SYSTEM;
74 system_bus_options.connection_type = dbus::Bus::PRIVATE; 76 system_bus_options.connection_type = dbus::Bus::PRIVATE;
75 system_bus_options.dbus_task_runner = dbus_thread_->message_loop_proxy(); 77 system_bus_options.dbus_task_runner = dbus_thread_->message_loop_proxy();
76 system_bus_ = new dbus::Bus(system_bus_options); 78 system_bus_ = new dbus::Bus(system_bus_options);
79 }
77 80
81 // InitializeClients gets called after g_dbus_thread_manager is set.
82 // NOTE: Clients that access other clients in their constructor must be
83 // construced in the correct order.
84 void InitializeClients() {
78 bluetooth_manager_client_.reset(BluetoothManagerClient::Create( 85 bluetooth_manager_client_.reset(BluetoothManagerClient::Create(
79 client_type, system_bus_.get())); 86 client_type_, system_bus_.get()));
80 bluetooth_adapter_client_.reset(BluetoothAdapterClient::Create( 87 bluetooth_adapter_client_.reset(BluetoothAdapterClient::Create(
81 client_type, system_bus_.get(), bluetooth_manager_client_.get())); 88 client_type_, system_bus_.get(), bluetooth_manager_client_.get()));
82 bluetooth_device_client_.reset(BluetoothDeviceClient::Create( 89 bluetooth_device_client_.reset(BluetoothDeviceClient::Create(
83 client_type, system_bus_.get(), bluetooth_adapter_client_.get())); 90 client_type_, system_bus_.get(), bluetooth_adapter_client_.get()));
84 bluetooth_input_client_.reset(BluetoothInputClient::Create( 91 bluetooth_input_client_.reset(BluetoothInputClient::Create(
85 client_type, system_bus_.get(), bluetooth_adapter_client_.get())); 92 client_type_, system_bus_.get(), bluetooth_adapter_client_.get()));
86 bluetooth_node_client_.reset(BluetoothNodeClient::Create( 93 bluetooth_node_client_.reset(BluetoothNodeClient::Create(
87 client_type, system_bus_.get(), bluetooth_device_client_.get())); 94 client_type_, system_bus_.get(), bluetooth_device_client_.get()));
88 bluetooth_out_of_band_client_.reset(BluetoothOutOfBandClient::Create( 95 bluetooth_out_of_band_client_.reset(BluetoothOutOfBandClient::Create(
89 client_type, system_bus_.get())); 96 client_type_, system_bus_.get()));
90 cros_disks_client_.reset( 97 cros_disks_client_.reset(
91 CrosDisksClient::Create(client_type, system_bus_.get())); 98 CrosDisksClient::Create(client_type_, system_bus_.get()));
92 cryptohome_client_.reset( 99 cryptohome_client_.reset(
93 CryptohomeClient::Create(client_type, system_bus_.get())); 100 CryptohomeClient::Create(client_type_, system_bus_.get()));
94 debug_daemon_client_.reset( 101 debug_daemon_client_.reset(
95 DebugDaemonClient::Create(client_type, system_bus_.get())); 102 DebugDaemonClient::Create(client_type_, system_bus_.get()));
103
104 shill_manager_client_.reset(
105 ShillManagerClient::Create(client_type_override_, system_bus_.get()));
96 shill_device_client_.reset( 106 shill_device_client_.reset(
97 ShillDeviceClient::Create(client_type, system_bus_.get())); 107 ShillDeviceClient::Create(client_type_override_, system_bus_.get()));
98 shill_ipconfig_client_.reset( 108 shill_ipconfig_client_.reset(
99 ShillIPConfigClient::Create(client_type, system_bus_.get())); 109 ShillIPConfigClient::Create(client_type_override_, system_bus_.get()));
100 shill_manager_client_.reset(
101 ShillManagerClient::Create(client_type, system_bus_.get()));
102 shill_profile_client_.reset( 110 shill_profile_client_.reset(
103 ShillProfileClient::Create(client_type, system_bus_.get())); 111 ShillProfileClient::Create(client_type_override_, system_bus_.get()));
104 shill_service_client_.reset( 112 shill_service_client_.reset(
105 ShillServiceClient::Create(client_type, system_bus_.get())); 113 ShillServiceClient::Create(client_type_override_, system_bus_.get()));
106 gsm_sms_client_.reset( 114 gsm_sms_client_.reset(
107 GsmSMSClient::Create(client_type, system_bus_.get())); 115 GsmSMSClient::Create(client_type_override_, system_bus_.get()));
108 image_burner_client_.reset(ImageBurnerClient::Create(client_type, 116
117 image_burner_client_.reset(ImageBurnerClient::Create(client_type_,
109 system_bus_.get())); 118 system_bus_.get()));
110 introspectable_client_.reset( 119 introspectable_client_.reset(
111 IntrospectableClient::Create(client_type, system_bus_.get())); 120 IntrospectableClient::Create(client_type_, system_bus_.get()));
112 modem_messaging_client_.reset( 121 modem_messaging_client_.reset(
113 ModemMessagingClient::Create(client_type, system_bus_.get())); 122 ModemMessagingClient::Create(client_type_, system_bus_.get()));
114 permission_broker_client_.reset( 123 permission_broker_client_.reset(
115 PermissionBrokerClient::Create(client_type, system_bus_.get())); 124 PermissionBrokerClient::Create(client_type_, system_bus_.get()));
116 power_manager_client_.reset( 125 power_manager_client_.reset(
117 PowerManagerClient::Create(client_type_maybe_stub, system_bus_.get())); 126 PowerManagerClient::Create(client_type_override_, system_bus_.get()));
118 session_manager_client_.reset( 127 session_manager_client_.reset(
119 SessionManagerClient::Create(client_type, system_bus_.get())); 128 SessionManagerClient::Create(client_type_, system_bus_.get()));
120 sms_client_.reset( 129 sms_client_.reset(
121 SMSClient::Create(client_type, system_bus_.get())); 130 SMSClient::Create(client_type_, system_bus_.get()));
122 update_engine_client_.reset( 131 update_engine_client_.reset(
123 UpdateEngineClient::Create(client_type, system_bus_.get())); 132 UpdateEngineClient::Create(client_type_, system_bus_.get()));
124 133
125 // PowerPolicyController is dependent on PowerManagerClient, so 134 // PowerPolicyController is dependent on PowerManagerClient, so
126 // initialize it after the main list of clients. 135 // initialize it after the main list of clients.
127 power_policy_controller_.reset( 136 power_policy_controller_.reset(
128 new PowerPolicyController(this, power_manager_client_.get())); 137 new PowerPolicyController(this, power_manager_client_.get()));
129 } 138 }
130 139
131 virtual ~DBusThreadManagerImpl() { 140 virtual ~DBusThreadManagerImpl() {
132 FOR_EACH_OBSERVER(DBusThreadManagerObserver, observers_, 141 FOR_EACH_OBSERVER(DBusThreadManagerObserver, observers_,
133 OnDBusThreadManagerDestroying(this)); 142 OnDBusThreadManagerDestroying(this));
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 return; 348 return;
340 } 349 }
341 delete ibus_engine_services_[object_path]; 350 delete ibus_engine_services_[object_path];
342 ibus_engine_services_.erase(object_path); 351 ibus_engine_services_.erase(object_path);
343 } 352 }
344 353
345 virtual IBusPanelService* GetIBusPanelService() OVERRIDE { 354 virtual IBusPanelService* GetIBusPanelService() OVERRIDE {
346 return ibus_panel_service_.get(); 355 return ibus_panel_service_.get();
347 } 356 }
348 357
358 DBusClientImplementationType client_type_;
359 DBusClientImplementationType client_type_override_;
360
349 // Note: Keep this before other members so they can call AddObserver() in 361 // Note: Keep this before other members so they can call AddObserver() in
350 // their c'tors. 362 // their c'tors.
351 ObserverList<DBusThreadManagerObserver> observers_; 363 ObserverList<DBusThreadManagerObserver> observers_;
352 364
353 scoped_ptr<base::Thread> dbus_thread_; 365 scoped_ptr<base::Thread> dbus_thread_;
354 scoped_refptr<dbus::Bus> system_bus_; 366 scoped_refptr<dbus::Bus> system_bus_;
355 scoped_refptr<dbus::Bus> ibus_bus_; 367 scoped_refptr<dbus::Bus> ibus_bus_;
356 scoped_ptr<BluetoothAdapterClient> bluetooth_adapter_client_; 368 scoped_ptr<BluetoothAdapterClient> bluetooth_adapter_client_;
357 scoped_ptr<BluetoothDeviceClient> bluetooth_device_client_; 369 scoped_ptr<BluetoothDeviceClient> bluetooth_device_client_;
358 scoped_ptr<BluetoothInputClient> bluetooth_input_client_; 370 scoped_ptr<BluetoothInputClient> bluetooth_input_client_;
(...skipping 30 matching lines...) Expand all
389 401
390 // static 402 // static
391 void DBusThreadManager::Initialize() { 403 void DBusThreadManager::Initialize() {
392 // Ignore Initialize() if we set a test DBusThreadManager. 404 // Ignore Initialize() if we set a test DBusThreadManager.
393 if (g_dbus_thread_manager_set_for_testing) 405 if (g_dbus_thread_manager_set_for_testing)
394 return; 406 return;
395 // If we initialize DBusThreadManager twice we may also be shutting it down 407 // If we initialize DBusThreadManager twice we may also be shutting it down
396 // early; do not allow that. 408 // early; do not allow that.
397 CHECK(g_dbus_thread_manager == NULL); 409 CHECK(g_dbus_thread_manager == NULL);
398 // Determine whether we use stub or real client implementations. 410 // Determine whether we use stub or real client implementations.
411 DBusThreadManagerImpl* dbus_thread_manager_impl;
399 if (base::chromeos::IsRunningOnChromeOS()) { 412 if (base::chromeos::IsRunningOnChromeOS()) {
400 g_dbus_thread_manager = 413 dbus_thread_manager_impl =
401 new DBusThreadManagerImpl(REAL_DBUS_CLIENT_IMPLEMENTATION); 414 new DBusThreadManagerImpl(REAL_DBUS_CLIENT_IMPLEMENTATION);
402 VLOG(1) << "DBusThreadManager initialized for ChromeOS"; 415 VLOG(1) << "DBusThreadManager initialized for ChromeOS";
403 } else { 416 } else {
404 g_dbus_thread_manager = 417 dbus_thread_manager_impl =
405 new DBusThreadManagerImpl(STUB_DBUS_CLIENT_IMPLEMENTATION); 418 new DBusThreadManagerImpl(STUB_DBUS_CLIENT_IMPLEMENTATION);
406 VLOG(1) << "DBusThreadManager initialized with Stub"; 419 VLOG(1) << "DBusThreadManager initialized with Stub";
407 } 420 }
421 g_dbus_thread_manager = dbus_thread_manager_impl;
422 dbus_thread_manager_impl->InitializeClients();
408 } 423 }
409 424
410 // static 425 // static
411 void DBusThreadManager::InitializeForTesting( 426 void DBusThreadManager::InitializeForTesting(
412 DBusThreadManager* dbus_thread_manager) { 427 DBusThreadManager* dbus_thread_manager) {
413 // If we initialize DBusThreadManager twice we may also be shutting it down 428 // If we initialize DBusThreadManager twice we may also be shutting it down
414 // early; do not allow that. 429 // early; do not allow that.
415 CHECK(g_dbus_thread_manager == NULL); 430 CHECK(g_dbus_thread_manager == NULL);
416 CHECK(dbus_thread_manager); 431 CHECK(dbus_thread_manager);
417 g_dbus_thread_manager = dbus_thread_manager; 432 g_dbus_thread_manager = dbus_thread_manager;
418 g_dbus_thread_manager_set_for_testing = true; 433 g_dbus_thread_manager_set_for_testing = true;
419 VLOG(1) << "DBusThreadManager initialized with test implementation"; 434 VLOG(1) << "DBusThreadManager initialized with test implementation";
420 } 435 }
421 436
422 // static 437 // static
423 void DBusThreadManager::InitializeWithStub() { 438 void DBusThreadManager::InitializeWithStub() {
424 // If we initialize DBusThreadManager twice we may also be shutting it down 439 // If we initialize DBusThreadManager twice we may also be shutting it down
425 // early; do not allow that. 440 // early; do not allow that.
426 CHECK(g_dbus_thread_manager == NULL); 441 CHECK(g_dbus_thread_manager == NULL);
427 g_dbus_thread_manager = 442 DBusThreadManagerImpl* dbus_thread_manager_impl =
428 new DBusThreadManagerImpl(STUB_DBUS_CLIENT_IMPLEMENTATION); 443 new DBusThreadManagerImpl(STUB_DBUS_CLIENT_IMPLEMENTATION);
444 g_dbus_thread_manager = dbus_thread_manager_impl;
445 dbus_thread_manager_impl->InitializeClients();
429 VLOG(1) << "DBusThreadManager initialized with stub implementation"; 446 VLOG(1) << "DBusThreadManager initialized with stub implementation";
430 } 447 }
431 448
432 // static 449 // static
433 bool DBusThreadManager::IsInitialized() { 450 bool DBusThreadManager::IsInitialized() {
434 return g_dbus_thread_manager != NULL; 451 return g_dbus_thread_manager != NULL;
435 } 452 }
436 453
437 // static 454 // static
438 void DBusThreadManager::Shutdown() { 455 void DBusThreadManager::Shutdown() {
(...skipping 14 matching lines...) Expand all
453 } 470 }
454 471
455 // static 472 // static
456 DBusThreadManager* DBusThreadManager::Get() { 473 DBusThreadManager* DBusThreadManager::Get() {
457 CHECK(g_dbus_thread_manager) 474 CHECK(g_dbus_thread_manager)
458 << "DBusThreadManager::Get() called before Initialize()"; 475 << "DBusThreadManager::Get() called before Initialize()";
459 return g_dbus_thread_manager; 476 return g_dbus_thread_manager;
460 } 477 }
461 478
462 } // namespace chromeos 479 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/chromeos_switches.cc ('k') | chromeos/dbus/shill_device_client_stub.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698