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 <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "chromeos/chromeos_export.h" | 14 #include "chromeos/chromeos_export.h" |
15 #include "chromeos/dbus/dbus_client_types.h" | |
16 | 15 |
17 namespace base { | 16 namespace base { |
18 class Thread; | 17 class Thread; |
19 } // namespace base | 18 } // namespace base |
20 | 19 |
21 namespace dbus { | 20 namespace dbus { |
22 class Bus; | 21 class Bus; |
23 class ObjectPath; | 22 class ObjectPath; |
24 } // namespace dbus | 23 } // namespace dbus |
25 | 24 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 // Returns true if DBusThreadManager has been initialized. Call this to | 99 // Returns true if DBusThreadManager has been initialized. Call this to |
101 // avoid initializing + shutting down DBusThreadManager more than once. | 100 // avoid initializing + shutting down DBusThreadManager more than once. |
102 static bool IsInitialized(); | 101 static bool IsInitialized(); |
103 | 102 |
104 // Destroys the global instance. | 103 // Destroys the global instance. |
105 static void Shutdown(); | 104 static void Shutdown(); |
106 | 105 |
107 // Gets the global instance. Initialize() must be called first. | 106 // Gets the global instance. Initialize() must be called first. |
108 static DBusThreadManager* Get(); | 107 static DBusThreadManager* Get(); |
109 | 108 |
110 // Returns true if |client| is faked. | 109 // Returns true if clients are faked. |
111 bool IsUsingFake(DBusClientType client); | 110 bool IsUsingFakes(); |
112 | 111 |
113 // Returns various D-Bus bus instances, owned by DBusThreadManager. | 112 // Returns various D-Bus bus instances, owned by DBusThreadManager. |
114 dbus::Bus* GetSystemBus(); | 113 dbus::Bus* GetSystemBus(); |
115 | 114 |
116 // All returned objects are owned by DBusThreadManager. Do not use these | 115 // All returned objects are owned by DBusThreadManager. Do not use these |
117 // pointers after DBusThreadManager has been shut down. | 116 // pointers after DBusThreadManager has been shut down. |
118 // TODO(jamescook): Replace this with calls to FooClient::Get(). | 117 // TODO(jamescook): Replace this with calls to FooClient::Get(). |
119 // http://crbug.com/647367 | 118 // http://crbug.com/647367 |
120 ArcObbMounterClient* GetArcObbMounterClient(); | 119 ArcObbMounterClient* GetArcObbMounterClient(); |
121 CrasAudioClient* GetCrasAudioClient(); | 120 CrasAudioClient* GetCrasAudioClient(); |
(...skipping 14 matching lines...) Expand all Loading... |
136 ShillServiceClient* GetShillServiceClient(); | 135 ShillServiceClient* GetShillServiceClient(); |
137 ShillProfileClient* GetShillProfileClient(); | 136 ShillProfileClient* GetShillProfileClient(); |
138 ShillThirdPartyVpnDriverClient* GetShillThirdPartyVpnDriverClient(); | 137 ShillThirdPartyVpnDriverClient* GetShillThirdPartyVpnDriverClient(); |
139 SMSClient* GetSMSClient(); | 138 SMSClient* GetSMSClient(); |
140 SystemClockClient* GetSystemClockClient(); | 139 SystemClockClient* GetSystemClockClient(); |
141 UpdateEngineClient* GetUpdateEngineClient(); | 140 UpdateEngineClient* GetUpdateEngineClient(); |
142 | 141 |
143 private: | 142 private: |
144 friend class DBusThreadManagerSetter; | 143 friend class DBusThreadManagerSetter; |
145 | 144 |
146 DBusThreadManager(ProcessMask process_mask, | 145 // Creates dbus clients for all process types in |process_mask|. Creates real |
147 DBusClientTypeMask real_client_mask); | 146 // clients if |use_real_clients| is set, otherwise creates fakes. |
| 147 DBusThreadManager(ProcessMask process_mask, bool use_real_clients); |
148 ~DBusThreadManager(); | 148 ~DBusThreadManager(); |
149 | 149 |
150 // Creates a global instance of DBusThreadManager with the real | |
151 // implementations for all clients that are listed in |real_client_mask| and | |
152 // fake implementations for all clients that are not included. Cannot be | |
153 // called more than once. | |
154 static void CreateGlobalInstance(ProcessMask process_mask, | |
155 DBusClientTypeMask real_client_mask); | |
156 | |
157 // Initialize global thread manager instance with all real dbus client | |
158 // implementations. | |
159 static void InitializeWithRealClients(ProcessMask process_mask); | |
160 | |
161 // Initialize global thread manager instance with fake dbus clients. | |
162 static void InitializeWithFakeClients(ProcessMask process_mask); | |
163 | |
164 // Initialize with fake implementations for only certain clients that are | |
165 // not included in the comma-separated |force_real_clients| list. | |
166 static void InitializeWithPartialFakes(ProcessMask process_mask, | |
167 const std::string& force_real_clients); | |
168 | |
169 // Initializes all currently stored DBusClients with the system bus and | 150 // Initializes all currently stored DBusClients with the system bus and |
170 // performs additional setup. | 151 // performs additional setup. |
171 void InitializeClients(); | 152 void InitializeClients(); |
172 | 153 |
173 std::unique_ptr<base::Thread> dbus_thread_; | 154 std::unique_ptr<base::Thread> dbus_thread_; |
174 scoped_refptr<dbus::Bus> system_bus_; | 155 scoped_refptr<dbus::Bus> system_bus_; |
175 | 156 |
| 157 // Whether to use real or fake dbus clients. |
| 158 const bool use_real_clients_; |
| 159 |
176 // Clients used by multiple processes. | 160 // Clients used by multiple processes. |
177 std::unique_ptr<DBusClientsCommon> clients_common_; | 161 std::unique_ptr<DBusClientsCommon> clients_common_; |
178 | 162 |
179 // Clients used only by the browser process. Null in other processes. | 163 // Clients used only by the browser process. Null in other processes. |
180 std::unique_ptr<DBusClientsBrowser> clients_browser_; | 164 std::unique_ptr<DBusClientsBrowser> clients_browser_; |
181 | 165 |
182 DISALLOW_COPY_AND_ASSIGN(DBusThreadManager); | 166 DISALLOW_COPY_AND_ASSIGN(DBusThreadManager); |
183 }; | 167 }; |
184 | 168 |
185 // TODO(jamescook): Replace these with FooClient::InitializeForTesting(). | 169 // TODO(jamescook): Replace these with FooClient::InitializeForTesting(). |
(...skipping 23 matching lines...) Expand all Loading... |
209 friend class DBusThreadManager; | 193 friend class DBusThreadManager; |
210 | 194 |
211 DBusThreadManagerSetter(); | 195 DBusThreadManagerSetter(); |
212 | 196 |
213 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerSetter); | 197 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerSetter); |
214 }; | 198 }; |
215 | 199 |
216 } // namespace chromeos | 200 } // namespace chromeos |
217 | 201 |
218 #endif // CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ | 202 #endif // CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ |
OLD | NEW |