| 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 23 matching lines...) Expand all Loading... |
| 34 #include "chromeos/dbus/shill_service_client.h" | 34 #include "chromeos/dbus/shill_service_client.h" |
| 35 #include "chromeos/dbus/shill_third_party_vpn_driver_client.h" | 35 #include "chromeos/dbus/shill_third_party_vpn_driver_client.h" |
| 36 #include "chromeos/dbus/sms_client.h" | 36 #include "chromeos/dbus/sms_client.h" |
| 37 #include "chromeos/dbus/system_clock_client.h" | 37 #include "chromeos/dbus/system_clock_client.h" |
| 38 #include "chromeos/dbus/update_engine_client.h" | 38 #include "chromeos/dbus/update_engine_client.h" |
| 39 #include "dbus/bus.h" | 39 #include "dbus/bus.h" |
| 40 #include "dbus/dbus_statistics.h" | 40 #include "dbus/dbus_statistics.h" |
| 41 | 41 |
| 42 namespace chromeos { | 42 namespace chromeos { |
| 43 | 43 |
| 44 static DBusThreadManager* g_dbus_thread_manager = NULL; | 44 static DBusThreadManager* g_dbus_thread_manager = nullptr; |
| 45 static bool g_using_dbus_thread_manager_for_testing = false; | 45 static bool g_using_dbus_thread_manager_for_testing = false; |
| 46 | 46 |
| 47 DBusThreadManager::DBusThreadManager(ProcessMask process_mask, | 47 DBusThreadManager::DBusThreadManager(ProcessMask process_mask, |
| 48 bool use_real_clients) | 48 bool use_real_clients) |
| 49 : use_real_clients_(use_real_clients), | 49 : use_real_clients_(use_real_clients), |
| 50 clients_common_(new DBusClientsCommon(use_real_clients)) { | 50 clients_common_(new DBusClientsCommon(use_real_clients)) { |
| 51 if (process_mask & PROCESS_BROWSER) | 51 if (process_mask & PROCESS_BROWSER) |
| 52 clients_browser_.reset(new DBusClientsBrowser(use_real_clients)); | 52 clients_browser_.reset(new DBusClientsBrowser(use_real_clients)); |
| 53 // NOTE: When there are clients only used by ash, create them here. | 53 // NOTE: When there are clients only used by ash, create them here. |
| 54 | 54 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 83 // Stop the D-Bus thread. | 83 // Stop the D-Bus thread. |
| 84 if (dbus_thread_) | 84 if (dbus_thread_) |
| 85 dbus_thread_->Stop(); | 85 dbus_thread_->Stop(); |
| 86 | 86 |
| 87 dbus::statistics::Shutdown(); | 87 dbus::statistics::Shutdown(); |
| 88 | 88 |
| 89 if (!g_dbus_thread_manager) | 89 if (!g_dbus_thread_manager) |
| 90 return; // Called form Shutdown() or local test instance. | 90 return; // Called form Shutdown() or local test instance. |
| 91 | 91 |
| 92 // There should never be both a global instance and a local instance. | 92 // There should never be both a global instance and a local instance. |
| 93 CHECK(this == g_dbus_thread_manager); | 93 CHECK_EQ(this, g_dbus_thread_manager); |
| 94 if (g_using_dbus_thread_manager_for_testing) { | 94 if (g_using_dbus_thread_manager_for_testing) { |
| 95 g_dbus_thread_manager = NULL; | 95 g_dbus_thread_manager = nullptr; |
| 96 g_using_dbus_thread_manager_for_testing = false; | 96 g_using_dbus_thread_manager_for_testing = false; |
| 97 VLOG(1) << "DBusThreadManager destroyed"; | 97 VLOG(1) << "DBusThreadManager destroyed"; |
| 98 } else { | 98 } else { |
| 99 LOG(FATAL) << "~DBusThreadManager() called outside of Shutdown()"; | 99 LOG(FATAL) << "~DBusThreadManager() called outside of Shutdown()"; |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 dbus::Bus* DBusThreadManager::GetSystemBus() { | 103 dbus::Bus* DBusThreadManager::GetSystemBus() { |
| 104 return system_bus_.get(); | 104 return system_bus_.get(); |
| 105 } | 105 } |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 // static | 235 // static |
| 236 void DBusThreadManager::Initialize() { | 236 void DBusThreadManager::Initialize() { |
| 237 Initialize(PROCESS_ALL); | 237 Initialize(PROCESS_ALL); |
| 238 } | 238 } |
| 239 | 239 |
| 240 // static | 240 // static |
| 241 std::unique_ptr<DBusThreadManagerSetter> | 241 std::unique_ptr<DBusThreadManagerSetter> |
| 242 DBusThreadManager::GetSetterForTesting() { | 242 DBusThreadManager::GetSetterForTesting() { |
| 243 if (!g_using_dbus_thread_manager_for_testing) { | 243 if (!g_using_dbus_thread_manager_for_testing) { |
| 244 g_using_dbus_thread_manager_for_testing = true; | 244 g_using_dbus_thread_manager_for_testing = true; |
| 245 CHECK(!g_dbus_thread_manager); |
| 245 // TODO(jamescook): Don't initialize clients as a side-effect of using a | 246 // TODO(jamescook): Don't initialize clients as a side-effect of using a |
| 246 // test API. For now, assume the caller wants all clients. | 247 // test API. For now, assume the caller wants all clients. |
| 247 g_dbus_thread_manager = | 248 g_dbus_thread_manager = |
| 248 new DBusThreadManager(PROCESS_ALL, false /* use_real_clients */); | 249 new DBusThreadManager(PROCESS_ALL, false /* use_real_clients */); |
| 249 g_dbus_thread_manager->InitializeClients(); | 250 g_dbus_thread_manager->InitializeClients(); |
| 250 } | 251 } |
| 251 | 252 |
| 252 return base::WrapUnique(new DBusThreadManagerSetter()); | 253 return base::WrapUnique(new DBusThreadManagerSetter()); |
| 253 } | 254 } |
| 254 | 255 |
| 255 // static | 256 // static |
| 256 bool DBusThreadManager::IsInitialized() { | 257 bool DBusThreadManager::IsInitialized() { |
| 257 return g_dbus_thread_manager != NULL; | 258 return !!g_dbus_thread_manager; |
| 258 } | 259 } |
| 259 | 260 |
| 260 // static | 261 // static |
| 261 void DBusThreadManager::Shutdown() { | 262 void DBusThreadManager::Shutdown() { |
| 262 // Ensure that we only shutdown DBusThreadManager once. | 263 // Ensure that we only shutdown DBusThreadManager once. |
| 263 CHECK(g_dbus_thread_manager); | 264 CHECK(g_dbus_thread_manager); |
| 264 DBusThreadManager* dbus_thread_manager = g_dbus_thread_manager; | 265 DBusThreadManager* dbus_thread_manager = g_dbus_thread_manager; |
| 265 g_dbus_thread_manager = NULL; | 266 g_dbus_thread_manager = nullptr; |
| 266 g_using_dbus_thread_manager_for_testing = false; | 267 g_using_dbus_thread_manager_for_testing = false; |
| 267 delete dbus_thread_manager; | 268 delete dbus_thread_manager; |
| 268 VLOG(1) << "DBusThreadManager Shutdown completed"; | 269 VLOG(1) << "DBusThreadManager Shutdown completed"; |
| 269 } | 270 } |
| 270 | 271 |
| 271 // static | 272 // static |
| 272 DBusThreadManager* DBusThreadManager::Get() { | 273 DBusThreadManager* DBusThreadManager::Get() { |
| 273 CHECK(g_dbus_thread_manager) | 274 CHECK(g_dbus_thread_manager) |
| 274 << "DBusThreadManager::Get() called before Initialize()"; | 275 << "DBusThreadManager::Get() called before Initialize()"; |
| 275 return g_dbus_thread_manager; | 276 return g_dbus_thread_manager; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 std::move(client); | 365 std::move(client); |
| 365 } | 366 } |
| 366 | 367 |
| 367 void DBusThreadManagerSetter::SetUpdateEngineClient( | 368 void DBusThreadManagerSetter::SetUpdateEngineClient( |
| 368 std::unique_ptr<UpdateEngineClient> client) { | 369 std::unique_ptr<UpdateEngineClient> client) { |
| 369 DBusThreadManager::Get()->clients_common_->update_engine_client_ = | 370 DBusThreadManager::Get()->clients_common_->update_engine_client_ = |
| 370 std::move(client); | 371 std::move(client); |
| 371 } | 372 } |
| 372 | 373 |
| 373 } // namespace chromeos | 374 } // namespace chromeos |
| OLD | NEW |