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