OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ | |
7 #pragma once | |
8 | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/memory/ref_counted.h" | |
11 | |
12 namespace base { | |
13 class Thread; | |
14 }; | |
15 | |
16 namespace dbus { | |
17 class Bus; | |
18 }; | |
19 | |
20 namespace chromeos { | |
21 | |
22 // Style Note: Clients are sorted by names. | |
23 class BluetoothAdapterClient; | |
24 class BluetoothDeviceClient; | |
25 class BluetoothInputClient; | |
26 class BluetoothManagerClient; | |
27 class BluetoothNodeClient; | |
28 class CashewClient; | |
29 class CrosDisksClient; | |
30 class CryptohomeClient; | |
31 class DebugDaemonClient; | |
32 class FlimflamIPConfigClient; | |
33 class FlimflamNetworkClient; | |
34 class FlimflamProfileClient; | |
35 class ImageBurnerClient; | |
36 class IntrospectableClient; | |
37 class PowerManagerClient; | |
38 class SessionManagerClient; | |
39 class SpeechSynthesizerClient; | |
40 class UpdateEngineClient; | |
41 | |
42 // DBusThreadManager manages the D-Bus thread, the thread dedicated to | |
43 // handling asynchronous D-Bus operations. | |
44 // | |
45 // This class also manages D-Bus connections and D-Bus clients, which | |
46 // depend on the D-Bus thread to ensure the right order of shutdowns for | |
47 // the D-Bus thread, the D-Bus connections, and the D-Bus clients. | |
48 // | |
49 // CALLBACKS IN D-BUS CLIENTS: | |
50 // | |
51 // D-Bus clients managed by DBusThreadManager are guaranteed to be deleted | |
52 // after the D-Bus thread so the clients don't need to worry if new | |
53 // incoming messages arrive from the D-Bus thread during shutdown of the | |
54 // clients. The UI message loop is not running during the shutdown hence | |
55 // the UI message loop won't post tasks to D-BUS clients during the | |
56 // shutdown. However, to be extra cautious, clients should use | |
57 // WeakPtrFactory when creating callbacks that run on UI thread. See | |
58 // session_manager_client.cc for examples. | |
59 // | |
60 class DBusThreadManager { | |
61 public: | |
62 // Sets the global instance. Must be called before any calls to Get(). | |
63 // We explicitly initialize and shut down the global object, rather than | |
64 // making it a Singleton, to ensure clean startup and shutdown. | |
65 static void Initialize(); | |
66 | |
67 // Similar to Initialize(), but can inject an alternative | |
68 // DBusThreadManager such as MockDBusThreadManager for testing. | |
69 // The injected object will be owned by the internal pointer and deleted | |
70 // by Shutdown(). | |
71 static void InitializeForTesting(DBusThreadManager* dbus_thread_manager); | |
72 | |
73 // Destroys the global instance. | |
74 static void Shutdown(); | |
75 | |
76 // Gets the global instance. Initialize() must be called first. | |
77 static DBusThreadManager* Get(); | |
78 | |
79 // Returns the D-Bus system bus instance, owned by DBusThreadManager. | |
80 virtual dbus::Bus* GetSystemBus() = 0; | |
81 | |
82 // Returns the bluetooth adapter client, owned by DBusThreadManager. | |
83 // Do not cache this pointer and use it after DBusThreadManager is shut | |
84 // down. | |
85 virtual BluetoothAdapterClient* GetBluetoothAdapterClient() = 0; | |
86 | |
87 // Returns the bluetooth device client, owned by DBusThreadManager. | |
88 // Do not cache this pointer and use it after DBusThreadManager is shut | |
89 // down. | |
90 virtual BluetoothDeviceClient* GetBluetoothDeviceClient() = 0; | |
91 | |
92 // Returns the bluetooth input client, owned by DBusThreadManager. | |
93 // Do not cache this pointer and use it after DBusThreadManager is shut | |
94 // down. | |
95 virtual BluetoothInputClient* GetBluetoothInputClient() = 0; | |
96 | |
97 // Returns the bluetooth manager client, owned by DBusThreadManager. | |
98 // Do not cache this pointer and use it after DBusThreadManager is shut | |
99 // down. | |
100 virtual BluetoothManagerClient* GetBluetoothManagerClient() = 0; | |
101 | |
102 // Returns the bluetooth node client, owned by DBusThreadManager. | |
103 // Do not cache this pointer and use it after DBusThreadManager is shut | |
104 // down. | |
105 virtual BluetoothNodeClient* GetBluetoothNodeClient() = 0; | |
106 | |
107 // Returns the Cashew client, owned by DBusThreadManager. | |
108 // Do not cache this pointer and use it after DBusThreadManager is shut | |
109 // down. | |
110 virtual CashewClient* GetCashewClient() = 0; | |
111 | |
112 // Returns the cros-disks client, owned by DBusThreadManager. | |
113 // Do not cache this pointer and use it after DBusThreadManager is shut | |
114 // down. | |
115 virtual CrosDisksClient* GetCrosDisksClient() = 0; | |
116 | |
117 // Returns the Cryptohome client, owned by DBusThreadManager. | |
118 // Do not cache this pointer and use it after DBusThreadManager is shut | |
119 // down. | |
120 virtual CryptohomeClient* GetCryptohomeClient() = 0; | |
121 | |
122 // Returns the DebugDaemon client, owned by DBusThreadManager. | |
123 // Do not cache this pointer and use it after DBusThreadManager is shut | |
124 // down. | |
125 virtual DebugDaemonClient* GetDebugDaemonClient() = 0; | |
126 | |
127 // Returns the Flimflam IPConfig client, owned by DBusThreadManager. | |
128 // Do not cache this pointer and use it after DBusThreadManager is shut | |
129 // down. | |
130 virtual FlimflamIPConfigClient* GetFlimflamIPConfigClient() = 0; | |
131 | |
132 // Returns the Flimflam Network client, owned by DBusThreadManager. | |
133 // Do not cache this pointer and use it after DBusThreadManager is shut | |
134 // down. | |
135 virtual FlimflamNetworkClient* GetFlimflamNetworkClient() = 0; | |
136 | |
137 // Returns the Flimflam Profile client, owned by DBusThreadManager. | |
138 // Do not cache this pointer and use it after DBusThreadManager is shut | |
139 // down. | |
140 virtual FlimflamProfileClient* GetFlimflamProfileClient() = 0; | |
141 | |
142 // Returns the image burner client, owned by DBusThreadManager. | |
143 // Do not cache this pointer and use it after DBusThreadManger is shut | |
144 // down. | |
145 virtual ImageBurnerClient* GetImageBurnerClient() = 0; | |
146 | |
147 // Returns the introspectable object client, owned by DBusThreadManager. | |
148 // Do not cache this pointer and use it after DBusThreadManger is shut | |
149 // down. | |
150 virtual IntrospectableClient* GetIntrospectableClient() = 0; | |
151 | |
152 // Returns the power manager client, owned by DBusThreadManager. | |
153 // See also comments at session_manager_client(). | |
154 virtual PowerManagerClient* GetPowerManagerClient() = 0; | |
155 | |
156 // Returns the session manager client, owned by DBusThreadManager. | |
157 // Do not cache this pointer and use it after DBusThreadManager is shut | |
158 // down. | |
159 virtual SessionManagerClient* GetSessionManagerClient() = 0; | |
160 | |
161 // Returns the speech synthesizer client, owned by DBusThreadManager. | |
162 // Do not cache this pointer and use it after DBusThreadManager is shut | |
163 // down. | |
164 virtual SpeechSynthesizerClient* GetSpeechSynthesizerClient() = 0; | |
165 | |
166 // Returns the update engine client, owned by DBusThreadManager. Do not | |
167 // cache this pointer and use it after DBusThreadManager is shut down. | |
168 virtual UpdateEngineClient* GetUpdateEngineClient() = 0; | |
169 | |
170 virtual ~DBusThreadManager(); | |
171 | |
172 protected: | |
173 DBusThreadManager(); | |
174 | |
175 DISALLOW_COPY_AND_ASSIGN(DBusThreadManager); | |
176 }; | |
177 | |
178 } // namespace chromeos | |
179 | |
180 #endif // CHROME_BROWSER_CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ | |
OLD | NEW |