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 #ifndef CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ | 5 #ifndef CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ |
6 #define CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ | 6 #define CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 // the UI message loop won't post tasks to D-BUS clients during the | 79 // the UI message loop won't post tasks to D-BUS clients during the |
80 // shutdown. However, to be extra cautious, clients should use | 80 // shutdown. However, to be extra cautious, clients should use |
81 // WeakPtrFactory when creating callbacks that run on UI thread. See | 81 // WeakPtrFactory when creating callbacks that run on UI thread. See |
82 // session_manager_client.cc for examples. | 82 // session_manager_client.cc for examples. |
83 // | 83 // |
84 class CHROMEOS_EXPORT DBusThreadManager { | 84 class CHROMEOS_EXPORT DBusThreadManager { |
85 public: | 85 public: |
86 // Sets the global instance. Must be called before any calls to Get(). | 86 // Sets the global instance. Must be called before any calls to Get(). |
87 // We explicitly initialize and shut down the global object, rather than | 87 // We explicitly initialize and shut down the global object, rather than |
88 // making it a Singleton, to ensure clean startup and shutdown. | 88 // making it a Singleton, to ensure clean startup and shutdown. |
89 // This will initialize real or stub DBusClients depending on command-line | |
90 // arguments and whether this process runs in a ChromeOS environment. | |
89 static void Initialize(); | 91 static void Initialize(); |
90 | 92 |
91 // Returns a DBusThreadManagerSetter instance that allows tests to | 93 // Returns a DBusThreadManagerSetter instance that allows tests to |
92 // replace individual D-Bus clients with their own implementations. | 94 // replace individual D-Bus clients with their own implementations. |
93 // Also initializes the main DBusThreadManager for testing if necessary. | 95 // Also initializes the main DBusThreadManager for testing if necessary. |
94 static scoped_ptr<DBusThreadManagerSetter> GetSetterForTesting(); | 96 static scoped_ptr<DBusThreadManagerSetter> GetSetterForTesting(); |
95 | 97 |
96 // Returns true if DBusThreadManager has been initialized. Call this to | 98 // Returns true if DBusThreadManager has been initialized. Call this to |
97 // avoid initializing + shutting down DBusThreadManager more than once. | 99 // avoid initializing + shutting down DBusThreadManager more than once. |
98 static bool IsInitialized(); | 100 static bool IsInitialized(); |
99 | 101 |
100 // Destroys the global instance. | 102 // Destroys the global instance. |
101 static void Shutdown(); | 103 static void Shutdown(); |
102 | 104 |
103 // Gets the global instance. Initialize() must be called first. | 105 // Gets the global instance. Initialize() must be called first. |
104 static DBusThreadManager* Get(); | 106 static DBusThreadManager* Get(); |
105 | 107 |
106 // Returns true if |client| is stubbed. | 108 // Returns true if |client| is stubbed. |
107 static bool IsUsingStub(DBusClientBundle::DBusClientType client); | 109 bool IsUsingStub(DBusClientBundle::DBusClientType client); |
108 | 110 |
109 // Returns various D-Bus bus instances, owned by DBusThreadManager. | 111 // Returns various D-Bus bus instances, owned by DBusThreadManager. |
110 dbus::Bus* GetSystemBus(); | 112 dbus::Bus* GetSystemBus(); |
111 | 113 |
112 // All returned objects are owned by DBusThreadManager. Do not cache these | 114 // All returned objects are owned by DBusThreadManager. Do not cache these |
113 // pointers and use them after DBusThreadManager has been shut down. | 115 // pointers and use them after DBusThreadManager has been shut down. |
114 BluetoothAdapterClient* GetBluetoothAdapterClient(); | 116 BluetoothAdapterClient* GetBluetoothAdapterClient(); |
115 BluetoothAgentManagerClient* GetBluetoothAgentManagerClient(); | 117 BluetoothAgentManagerClient* GetBluetoothAgentManagerClient(); |
116 BluetoothDeviceClient* GetBluetoothDeviceClient(); | 118 BluetoothDeviceClient* GetBluetoothDeviceClient(); |
117 BluetoothGattCharacteristicClient* GetBluetoothGattCharacteristicClient(); | 119 BluetoothGattCharacteristicClient* GetBluetoothGattCharacteristicClient(); |
(...skipping 26 matching lines...) Expand all Loading... | |
144 ShillManagerClient* GetShillManagerClient(); | 146 ShillManagerClient* GetShillManagerClient(); |
145 ShillServiceClient* GetShillServiceClient(); | 147 ShillServiceClient* GetShillServiceClient(); |
146 ShillProfileClient* GetShillProfileClient(); | 148 ShillProfileClient* GetShillProfileClient(); |
147 SMSClient* GetSMSClient(); | 149 SMSClient* GetSMSClient(); |
148 SystemClockClient* GetSystemClockClient(); | 150 SystemClockClient* GetSystemClockClient(); |
149 UpdateEngineClient* GetUpdateEngineClient(); | 151 UpdateEngineClient* GetUpdateEngineClient(); |
150 | 152 |
151 private: | 153 private: |
152 friend class DBusThreadManagerSetter; | 154 friend class DBusThreadManagerSetter; |
153 | 155 |
154 DBusThreadManager(); | 156 // Creates a new DBusThreadManager using the DBusClients set in |
157 // |client_bundle|. | |
158 DBusThreadManager(scoped_ptr<DBusClientBundle> client_bundle); | |
hashimoto
2014/09/11 06:50:45
'explicit' missing?
pneubeck (no reviews)
2014/09/11 08:08:19
hm. wasn't catched by presubmit.
Done.
| |
155 ~DBusThreadManager(); | 159 ~DBusThreadManager(); |
156 | 160 |
157 // Creates a global instance of DBusThreadManager. Can not be called more | 161 // Creates a global instance of DBusThreadManager with the real |
158 // than once. | 162 // implementations for all clients that are listed in |unstub_client_mask| and |
159 static void CreateGlobalInstance(); | 163 // stub implementations for all clients that are not included. Cannot be |
164 // called more than once. | |
165 static void CreateGlobalInstance( | |
166 DBusClientBundle::DBusClientTypeMask unstub_client_mask); | |
160 | 167 |
161 // Initialize global thread manager instance. | 168 // Initialize global thread manager instance with all real dbus client |
162 static void InitializeRegular(); | 169 // implementations. |
170 static void InitializeWithRealClients(); | |
163 | 171 |
164 // Initialize global thread manager instance with stubbed-out dbus clients | 172 // Initialize global thread manager instance with stubbed-out dbus clients |
165 // implementation. | 173 // implementation. |
166 static void InitializeWithStubs(); | 174 static void InitializeWithStubs(); |
167 | 175 |
168 // Initialize with stub implementations for only certain clients that are | 176 // Initialize with stub implementations for only certain clients that are |
169 // not included in comma-separated |unstub_clients| list. | 177 // not included in the comma-separated |unstub_clients| list. |
170 static void InitializeWithPartialStub(const std::string& unstub_clients); | 178 static void InitializeWithPartialStub(const std::string& unstub_clients); |
171 | 179 |
172 // Constructs all clients and stores them in the respective *_client_ member | 180 // Initializes all currently stored DBusClients with the system bus and |
173 // variable. | 181 // creates a stub network environment. |
hashimoto
2014/09/11 06:50:45
This comment is not always true as DBusClientBundl
pneubeck (no reviews)
2014/09/11 08:08:19
Done.
| |
174 void CreateDefaultClients(); | |
175 | |
176 // Constructs all clients and stores them in the respective *_client_ member | |
177 // variable. | |
178 void InitializeClients(); | 182 void InitializeClients(); |
179 | 183 |
180 // Bitmask that defines which dbus clients are not stubbed out. Bitmap flags | |
181 // are defined within DBusClientBundle::DBusClientType enum. | |
182 static DBusClientBundle::DBusClientTypeMask unstub_client_mask_; | |
183 | |
184 scoped_ptr<base::Thread> dbus_thread_; | 184 scoped_ptr<base::Thread> dbus_thread_; |
185 scoped_refptr<dbus::Bus> system_bus_; | 185 scoped_refptr<dbus::Bus> system_bus_; |
186 scoped_ptr<DBusClientBundle> client_bundle_; | 186 scoped_ptr<DBusClientBundle> client_bundle_; |
187 scoped_ptr<PowerPolicyController> power_policy_controller_; | 187 scoped_ptr<PowerPolicyController> power_policy_controller_; |
188 | 188 |
189 DISALLOW_COPY_AND_ASSIGN(DBusThreadManager); | 189 DISALLOW_COPY_AND_ASSIGN(DBusThreadManager); |
190 }; | 190 }; |
191 | 191 |
192 class CHROMEOS_EXPORT DBusThreadManagerSetter { | 192 class CHROMEOS_EXPORT DBusThreadManagerSetter { |
193 public: | 193 public: |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 friend class DBusThreadManager; | 239 friend class DBusThreadManager; |
240 | 240 |
241 DBusThreadManagerSetter(); | 241 DBusThreadManagerSetter(); |
242 | 242 |
243 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerSetter); | 243 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerSetter); |
244 }; | 244 }; |
245 | 245 |
246 } // namespace chromeos | 246 } // namespace chromeos |
247 | 247 |
248 #endif // CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ | 248 #endif // CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ |
OLD | NEW |