Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chromeos / dbus / dbus_thread_manager.h
blob322ab2804b60aeb04691a640ae1d96db5ea0defb
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
3 // found in the LICENSE file.
5 #ifndef CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_
6 #define CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_
8 #include <string>
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "chromeos/chromeos_export.h"
14 #include "chromeos/dbus/dbus_client_bundle.h"
16 namespace base {
17 class Thread;
18 } // namespace base
20 namespace dbus {
21 class Bus;
22 class ObjectPath;
23 } // namespace dbus
25 namespace chromeos {
27 // Style Note: Clients are sorted by names.
28 class AmplifierClient;
29 class ApManagerClient;
30 class AudioDspClient;
31 class BluetoothAdapterClient;
32 class BluetoothLEAdvertisingManagerClient;
33 class BluetoothAgentManagerClient;
34 class BluetoothDeviceClient;
35 class BluetoothGattCharacteristicClient;
36 class BluetoothGattDescriptorClient;
37 class BluetoothGattManagerClient;
38 class BluetoothGattServiceClient;
39 class BluetoothInputClient;
40 class BluetoothMediaClient;
41 class BluetoothMediaTransportClient;
42 class BluetoothProfileManagerClient;
43 class CrasAudioClient;
44 class CrosDisksClient;
45 class CryptohomeClient;
46 class DBusThreadManagerSetter;
47 class DebugDaemonClient;
48 class EasyUnlockClient;
49 class GsmSMSClient;
50 class ImageBurnerClient;
51 class IntrospectableClient;
52 class LorgnetteManagerClient;
53 class ModemMessagingClient;
54 class NfcAdapterClient;
55 class NfcDeviceClient;
56 class NfcManagerClient;
57 class NfcRecordClient;
58 class NfcTagClient;
59 class PeerDaemonManagerClient;
60 class PermissionBrokerClient;
61 class PowerManagerClient;
62 class PrivetDaemonManagerClient;
63 class SMSClient;
64 class SessionManagerClient;
65 class ShillDeviceClient;
66 class ShillIPConfigClient;
67 class ShillManagerClient;
68 class ShillProfileClient;
69 class ShillServiceClient;
70 class ShillThirdPartyVpnDriverClient;
71 class SystemClockClient;
72 class UpdateEngineClient;
74 // DBusThreadManager manages the D-Bus thread, the thread dedicated to
75 // handling asynchronous D-Bus operations.
77 // This class also manages D-Bus connections and D-Bus clients, which
78 // depend on the D-Bus thread to ensure the right order of shutdowns for
79 // the D-Bus thread, the D-Bus connections, and the D-Bus clients.
81 // CALLBACKS IN D-BUS CLIENTS:
83 // D-Bus clients managed by DBusThreadManager are guaranteed to be deleted
84 // after the D-Bus thread so the clients don't need to worry if new
85 // incoming messages arrive from the D-Bus thread during shutdown of the
86 // clients. The UI message loop is not running during the shutdown hence
87 // the UI message loop won't post tasks to D-BUS clients during the
88 // shutdown. However, to be extra cautious, clients should use
89 // WeakPtrFactory when creating callbacks that run on UI thread. See
90 // session_manager_client.cc for examples.
92 class CHROMEOS_EXPORT DBusThreadManager {
93 public:
94 // Sets the global instance. Must be called before any calls to Get().
95 // We explicitly initialize and shut down the global object, rather than
96 // making it a Singleton, to ensure clean startup and shutdown.
97 // This will initialize real or stub DBusClients depending on command-line
98 // arguments and whether this process runs in a ChromeOS environment.
99 static void Initialize();
101 // Returns a DBusThreadManagerSetter instance that allows tests to
102 // replace individual D-Bus clients with their own implementations.
103 // Also initializes the main DBusThreadManager for testing if necessary.
104 static scoped_ptr<DBusThreadManagerSetter> GetSetterForTesting();
106 // Returns true if DBusThreadManager has been initialized. Call this to
107 // avoid initializing + shutting down DBusThreadManager more than once.
108 static bool IsInitialized();
110 // Destroys the global instance.
111 static void Shutdown();
113 // Gets the global instance. Initialize() must be called first.
114 static DBusThreadManager* Get();
116 // Returns true if |client| is stubbed.
117 bool IsUsingStub(DBusClientBundle::DBusClientType client);
119 // Returns various D-Bus bus instances, owned by DBusThreadManager.
120 dbus::Bus* GetSystemBus();
122 // All returned objects are owned by DBusThreadManager. Do not use these
123 // pointers after DBusThreadManager has been shut down.
124 AmplifierClient* GetAmplifierClient();
125 ApManagerClient* GetApManagerClient();
126 AudioDspClient* GetAudioDspClient();
127 BluetoothAdapterClient* GetBluetoothAdapterClient();
128 BluetoothLEAdvertisingManagerClient* GetBluetoothLEAdvertisingManagerClient();
129 BluetoothAgentManagerClient* GetBluetoothAgentManagerClient();
130 BluetoothDeviceClient* GetBluetoothDeviceClient();
131 BluetoothGattCharacteristicClient* GetBluetoothGattCharacteristicClient();
132 BluetoothGattDescriptorClient* GetBluetoothGattDescriptorClient();
133 BluetoothGattManagerClient* GetBluetoothGattManagerClient();
134 BluetoothGattServiceClient* GetBluetoothGattServiceClient();
135 BluetoothInputClient* GetBluetoothInputClient();
136 BluetoothMediaClient* GetBluetoothMediaClient();
137 BluetoothMediaTransportClient* GetBluetoothMediaTransportClient();
138 BluetoothProfileManagerClient* GetBluetoothProfileManagerClient();
139 CrasAudioClient* GetCrasAudioClient();
140 CrosDisksClient* GetCrosDisksClient();
141 CryptohomeClient* GetCryptohomeClient();
142 DebugDaemonClient* GetDebugDaemonClient();
143 EasyUnlockClient* GetEasyUnlockClient();
144 GsmSMSClient* GetGsmSMSClient();
145 ImageBurnerClient* GetImageBurnerClient();
146 IntrospectableClient* GetIntrospectableClient();
147 LorgnetteManagerClient* GetLorgnetteManagerClient();
148 ModemMessagingClient* GetModemMessagingClient();
149 NfcAdapterClient* GetNfcAdapterClient();
150 NfcDeviceClient* GetNfcDeviceClient();
151 NfcManagerClient* GetNfcManagerClient();
152 NfcRecordClient* GetNfcRecordClient();
153 NfcTagClient* GetNfcTagClient();
154 PeerDaemonManagerClient* GetPeerDaemonManagerClient();
155 PermissionBrokerClient* GetPermissionBrokerClient();
156 PrivetDaemonManagerClient* GetPrivetDaemonManagerClient();
157 PowerManagerClient* GetPowerManagerClient();
158 SessionManagerClient* GetSessionManagerClient();
159 ShillDeviceClient* GetShillDeviceClient();
160 ShillIPConfigClient* GetShillIPConfigClient();
161 ShillManagerClient* GetShillManagerClient();
162 ShillServiceClient* GetShillServiceClient();
163 ShillProfileClient* GetShillProfileClient();
164 ShillThirdPartyVpnDriverClient* GetShillThirdPartyVpnDriverClient();
165 SMSClient* GetSMSClient();
166 SystemClockClient* GetSystemClockClient();
167 UpdateEngineClient* GetUpdateEngineClient();
169 private:
170 friend class DBusThreadManagerSetter;
172 // Creates a new DBusThreadManager using the DBusClients set in
173 // |client_bundle|.
174 explicit DBusThreadManager(scoped_ptr<DBusClientBundle> client_bundle);
175 ~DBusThreadManager();
177 // Creates a global instance of DBusThreadManager with the real
178 // implementations for all clients that are listed in |unstub_client_mask| and
179 // stub implementations for all clients that are not included. Cannot be
180 // called more than once.
181 static void CreateGlobalInstance(
182 DBusClientBundle::DBusClientTypeMask unstub_client_mask);
184 // Initialize global thread manager instance with all real dbus client
185 // implementations.
186 static void InitializeWithRealClients();
188 // Initialize global thread manager instance with stubbed-out dbus clients
189 // implementation.
190 static void InitializeWithStubs();
192 // Initialize with stub implementations for only certain clients that are
193 // not included in the comma-separated |unstub_clients| list.
194 static void InitializeWithPartialStub(const std::string& unstub_clients);
196 // Initializes all currently stored DBusClients with the system bus and
197 // performs additional setup.
198 void InitializeClients();
200 scoped_ptr<base::Thread> dbus_thread_;
201 scoped_refptr<dbus::Bus> system_bus_;
202 scoped_ptr<DBusClientBundle> client_bundle_;
204 DISALLOW_COPY_AND_ASSIGN(DBusThreadManager);
207 class CHROMEOS_EXPORT DBusThreadManagerSetter {
208 public:
209 ~DBusThreadManagerSetter();
211 void SetAmplifierClient(scoped_ptr<AmplifierClient> client);
212 void SetAudioDspClient(scoped_ptr<AudioDspClient> client);
213 void SetBluetoothAdapterClient(scoped_ptr<BluetoothAdapterClient> client);
214 void SetBluetoothLEAdvertisingManagerClient(
215 scoped_ptr<BluetoothLEAdvertisingManagerClient> client);
216 void SetBluetoothAgentManagerClient(
217 scoped_ptr<BluetoothAgentManagerClient> client);
218 void SetBluetoothDeviceClient(scoped_ptr<BluetoothDeviceClient> client);
219 void SetBluetoothGattCharacteristicClient(
220 scoped_ptr<BluetoothGattCharacteristicClient> client);
221 void SetBluetoothGattDescriptorClient(
222 scoped_ptr<BluetoothGattDescriptorClient> client);
223 void SetBluetoothGattManagerClient(
224 scoped_ptr<BluetoothGattManagerClient> client);
225 void SetBluetoothGattServiceClient(
226 scoped_ptr<BluetoothGattServiceClient> client);
227 void SetBluetoothInputClient(scoped_ptr<BluetoothInputClient> client);
228 void SetBluetoothMediaClient(scoped_ptr<BluetoothMediaClient> client);
229 void SetBluetoothMediaTransportClient(
230 scoped_ptr<BluetoothMediaTransportClient> client);
231 void SetBluetoothProfileManagerClient(
232 scoped_ptr<BluetoothProfileManagerClient> client);
233 void SetCrasAudioClient(scoped_ptr<CrasAudioClient> client);
234 void SetCrosDisksClient(scoped_ptr<CrosDisksClient> client);
235 void SetCryptohomeClient(scoped_ptr<CryptohomeClient> client);
236 void SetDebugDaemonClient(scoped_ptr<DebugDaemonClient> client);
237 void SetEasyUnlockClient(scoped_ptr<EasyUnlockClient> client);
238 void SetLorgnetteManagerClient(scoped_ptr<LorgnetteManagerClient> client);
239 void SetShillDeviceClient(scoped_ptr<ShillDeviceClient> client);
240 void SetShillIPConfigClient(scoped_ptr<ShillIPConfigClient> client);
241 void SetShillManagerClient(scoped_ptr<ShillManagerClient> client);
242 void SetShillServiceClient(scoped_ptr<ShillServiceClient> client);
243 void SetShillProfileClient(scoped_ptr<ShillProfileClient> client);
244 void SetShillThirdPartyVpnDriverClient(
245 scoped_ptr<ShillThirdPartyVpnDriverClient> client);
246 void SetGsmSMSClient(scoped_ptr<GsmSMSClient> client);
247 void SetImageBurnerClient(scoped_ptr<ImageBurnerClient> client);
248 void SetIntrospectableClient(scoped_ptr<IntrospectableClient> client);
249 void SetModemMessagingClient(scoped_ptr<ModemMessagingClient> client);
250 void SetNfcAdapterClient(scoped_ptr<NfcAdapterClient> client);
251 void SetNfcDeviceClient(scoped_ptr<NfcDeviceClient> client);
252 void SetNfcManagerClient(scoped_ptr<NfcManagerClient> client);
253 void SetNfcRecordClient(scoped_ptr<NfcRecordClient> client);
254 void SetNfcTagClient(scoped_ptr<NfcTagClient> client);
255 void SetPeerDaemonManagerClient(scoped_ptr<PeerDaemonManagerClient> client);
256 void SetPermissionBrokerClient(scoped_ptr<PermissionBrokerClient> client);
257 void SetPrivetDaemonManagerClient(
258 scoped_ptr<PrivetDaemonManagerClient> client);
259 void SetPowerManagerClient(scoped_ptr<PowerManagerClient> client);
260 void SetSessionManagerClient(scoped_ptr<SessionManagerClient> client);
261 void SetSMSClient(scoped_ptr<SMSClient> client);
262 void SetSystemClockClient(scoped_ptr<SystemClockClient> client);
263 void SetUpdateEngineClient(scoped_ptr<UpdateEngineClient> client);
265 private:
266 friend class DBusThreadManager;
268 DBusThreadManagerSetter();
270 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerSetter);
273 } // namespace chromeos
275 #endif // CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_