OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 5 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
9 #include "chrome/browser/chromeos/dbus/cros_dbus_service.h" | 9 #include "chrome/browser/chromeos/dbus/cros_dbus_service.h" |
| 10 #include "chrome/browser/chromeos/dbus/session_manager_client.h" |
10 #include "chrome/browser/chromeos/dbus/power_manager_client.h" | 11 #include "chrome/browser/chromeos/dbus/power_manager_client.h" |
11 #include "chrome/browser/chromeos/dbus/sensors_source.h" | 12 #include "chrome/browser/chromeos/dbus/sensors_source.h" |
12 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
13 #include "dbus/bus.h" | 14 #include "dbus/bus.h" |
14 | 15 |
15 namespace chromeos { | 16 namespace chromeos { |
16 | 17 |
17 static DBusThreadManager* g_dbus_thread_manager = NULL; | 18 static DBusThreadManager* g_dbus_thread_manager = NULL; |
18 | 19 |
19 DBusThreadManager::DBusThreadManager() { | 20 DBusThreadManager::DBusThreadManager() { |
(...skipping 17 matching lines...) Expand all Loading... |
37 | 38 |
38 // Start monitoring sensors if needed. | 39 // Start monitoring sensors if needed. |
39 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 40 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
40 if (command_line.HasSwitch(switches::kEnableSensors)) { | 41 if (command_line.HasSwitch(switches::kEnableSensors)) { |
41 sensors_source_.reset(new SensorsSource); | 42 sensors_source_.reset(new SensorsSource); |
42 sensors_source_->Init(system_bus_.get()); | 43 sensors_source_->Init(system_bus_.get()); |
43 } | 44 } |
44 | 45 |
45 // Create the power manager client. | 46 // Create the power manager client. |
46 power_manager_client_.reset(PowerManagerClient::Create(system_bus_.get())); | 47 power_manager_client_.reset(PowerManagerClient::Create(system_bus_.get())); |
| 48 // Create the session manager client. |
| 49 session_manager_client_.reset( |
| 50 SessionManagerClient::Create(system_bus_.get())); |
47 } | 51 } |
48 | 52 |
49 DBusThreadManager::~DBusThreadManager() { | 53 DBusThreadManager::~DBusThreadManager() { |
50 // Shut down the bus. During the browser shutdown, it's ok to shut down | 54 // Shut down the bus. During the browser shutdown, it's ok to shut down |
51 // the bus synchronously. | 55 // the bus synchronously. |
52 system_bus_->ShutdownOnDBusThreadAndBlock(); | 56 system_bus_->ShutdownOnDBusThreadAndBlock(); |
53 | 57 |
54 // Stop the D-Bus thread. | 58 // Stop the D-Bus thread. |
55 dbus_thread_->Stop(); | 59 dbus_thread_->Stop(); |
56 | 60 |
57 // D-Bus clients should be deleted after the D-Bus thread is stopped. | 61 // D-Bus clients should be deleted after the D-Bus thread is stopped. |
58 // See "CALLBACKS IN D-BUS CLIENTS" in the header file for why. | 62 // See "CALLBACKS IN D-BUS CLIENTS" in the header file for why. |
59 delete cros_dbus_service_; | 63 delete cros_dbus_service_; |
60 } | 64 } |
61 | 65 |
62 void DBusThreadManager::Initialize() { | 66 void DBusThreadManager::Initialize() { |
63 CHECK(!g_dbus_thread_manager); | 67 if (g_dbus_thread_manager) { |
| 68 // This can happen in tests. |
| 69 LOG(WARNING) << "DBusThreadManager::Initialize() was already called"; |
| 70 return; |
| 71 } |
64 g_dbus_thread_manager = new DBusThreadManager; | 72 g_dbus_thread_manager = new DBusThreadManager; |
65 VLOG(1) << "DBusThreadManager initialized"; | 73 VLOG(1) << "DBusThreadManager initialized"; |
66 } | 74 } |
67 | 75 |
68 void DBusThreadManager::Shutdown() { | 76 void DBusThreadManager::Shutdown() { |
69 if (!g_dbus_thread_manager) { | 77 if (!g_dbus_thread_manager) { |
70 // This can happen in tests. | 78 // This can happen in tests. |
71 LOG(WARNING) << "DBusThreadManager::Shutdown() called with NULL manager"; | 79 LOG(WARNING) << "DBusThreadManager::Shutdown() called with NULL manager"; |
72 return; | 80 return; |
73 } | 81 } |
74 delete g_dbus_thread_manager; | 82 delete g_dbus_thread_manager; |
75 g_dbus_thread_manager = NULL; | 83 g_dbus_thread_manager = NULL; |
76 VLOG(1) << "DBusThreadManager Shutdown completed"; | 84 VLOG(1) << "DBusThreadManager Shutdown completed"; |
77 } | 85 } |
78 | 86 |
79 DBusThreadManager* DBusThreadManager::Get() { | 87 DBusThreadManager* DBusThreadManager::Get() { |
80 CHECK(g_dbus_thread_manager) | 88 CHECK(g_dbus_thread_manager) |
81 << "DBusThreadManager::Get() called before Initialize()"; | 89 << "DBusThreadManager::Get() called before Initialize()"; |
82 return g_dbus_thread_manager; | 90 return g_dbus_thread_manager; |
83 } | 91 } |
84 | 92 |
| 93 void DBusThreadManager::set_session_manager_client_for_testing( |
| 94 SessionManagerClient* session_manager_client) { |
| 95 session_manager_client_.reset(session_manager_client); |
| 96 } |
| 97 |
85 } // namespace chromeos | 98 } // namespace chromeos |
OLD | NEW |