| 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_bundle.h" | 15 #include "chromeos/dbus/dbus_client_types.h" |
| 16 | 16 |
| 17 namespace base { | 17 namespace base { |
| 18 class Thread; | 18 class Thread; |
| 19 } // namespace base | 19 } // namespace base |
| 20 | 20 |
| 21 namespace dbus { | 21 namespace dbus { |
| 22 class Bus; | 22 class Bus; |
| 23 class ObjectPath; | 23 class ObjectPath; |
| 24 } // namespace dbus | 24 } // namespace dbus |
| 25 | 25 |
| 26 namespace chromeos { | 26 namespace chromeos { |
| 27 | 27 |
| 28 // Style Note: Clients are sorted by names. | 28 // Style Note: Clients are sorted by names. |
| 29 class ArcObbMounterClient; | 29 class ArcObbMounterClient; |
| 30 class CrasAudioClient; | 30 class CrasAudioClient; |
| 31 class CrosDisksClient; | 31 class CrosDisksClient; |
| 32 class CryptohomeClient; | 32 class CryptohomeClient; |
| 33 class DBusClientBundle; |
| 33 class DBusThreadManagerSetter; | 34 class DBusThreadManagerSetter; |
| 34 class DebugDaemonClient; | 35 class DebugDaemonClient; |
| 35 class EasyUnlockClient; | 36 class EasyUnlockClient; |
| 36 class GsmSMSClient; | 37 class GsmSMSClient; |
| 37 class ImageBurnerClient; | 38 class ImageBurnerClient; |
| 38 class LorgnetteManagerClient; | 39 class LorgnetteManagerClient; |
| 39 class ModemMessagingClient; | 40 class ModemMessagingClient; |
| 40 class PermissionBrokerClient; | 41 class PermissionBrokerClient; |
| 41 class PowerManagerClient; | 42 class PowerManagerClient; |
| 42 class SMSClient; | 43 class SMSClient; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 66 // the UI message loop won't post tasks to D-BUS clients during the | 67 // the UI message loop won't post tasks to D-BUS clients during the |
| 67 // shutdown. However, to be extra cautious, clients should use | 68 // shutdown. However, to be extra cautious, clients should use |
| 68 // WeakPtrFactory when creating callbacks that run on UI thread. See | 69 // WeakPtrFactory when creating callbacks that run on UI thread. See |
| 69 // session_manager_client.cc for examples. | 70 // session_manager_client.cc for examples. |
| 70 // | 71 // |
| 71 class CHROMEOS_EXPORT DBusThreadManager { | 72 class CHROMEOS_EXPORT DBusThreadManager { |
| 72 public: | 73 public: |
| 73 // Sets the global instance. Must be called before any calls to Get(). | 74 // Sets the global instance. Must be called before any calls to Get(). |
| 74 // We explicitly initialize and shut down the global object, rather than | 75 // We explicitly initialize and shut down the global object, rather than |
| 75 // making it a Singleton, to ensure clean startup and shutdown. | 76 // making it a Singleton, to ensure clean startup and shutdown. |
| 76 // This will initialize real or stub DBusClients depending on command-line | 77 // This will initialize real or fake DBusClients depending on command-line |
| 77 // arguments and whether this process runs in a ChromeOS environment. | 78 // arguments and whether this process runs in a ChromeOS environment. |
| 78 static void Initialize(); | 79 static void Initialize(); |
| 79 | 80 |
| 80 // Returns a DBusThreadManagerSetter instance that allows tests to | 81 // Returns a DBusThreadManagerSetter instance that allows tests to |
| 81 // replace individual D-Bus clients with their own implementations. | 82 // replace individual D-Bus clients with their own implementations. |
| 82 // Also initializes the main DBusThreadManager for testing if necessary. | 83 // Also initializes the main DBusThreadManager for testing if necessary. |
| 83 static std::unique_ptr<DBusThreadManagerSetter> GetSetterForTesting(); | 84 static std::unique_ptr<DBusThreadManagerSetter> GetSetterForTesting(); |
| 84 | 85 |
| 85 // Returns true if DBusThreadManager has been initialized. Call this to | 86 // Returns true if DBusThreadManager has been initialized. Call this to |
| 86 // avoid initializing + shutting down DBusThreadManager more than once. | 87 // avoid initializing + shutting down DBusThreadManager more than once. |
| 87 static bool IsInitialized(); | 88 static bool IsInitialized(); |
| 88 | 89 |
| 89 // Destroys the global instance. | 90 // Destroys the global instance. |
| 90 static void Shutdown(); | 91 static void Shutdown(); |
| 91 | 92 |
| 92 // Gets the global instance. Initialize() must be called first. | 93 // Gets the global instance. Initialize() must be called first. |
| 93 static DBusThreadManager* Get(); | 94 static DBusThreadManager* Get(); |
| 94 | 95 |
| 95 // Returns true if |client| is stubbed. | 96 // Returns true if |client| is faked. |
| 96 bool IsUsingStub(DBusClientBundle::DBusClientType client); | 97 bool IsUsingFake(DBusClientType client); |
| 97 | 98 |
| 98 // Returns various D-Bus bus instances, owned by DBusThreadManager. | 99 // Returns various D-Bus bus instances, owned by DBusThreadManager. |
| 99 dbus::Bus* GetSystemBus(); | 100 dbus::Bus* GetSystemBus(); |
| 100 | 101 |
| 101 // All returned objects are owned by DBusThreadManager. Do not use these | 102 // All returned objects are owned by DBusThreadManager. Do not use these |
| 102 // pointers after DBusThreadManager has been shut down. | 103 // pointers after DBusThreadManager has been shut down. |
| 103 ArcObbMounterClient* GetArcObbMounterClient(); | 104 ArcObbMounterClient* GetArcObbMounterClient(); |
| 104 CrasAudioClient* GetCrasAudioClient(); | 105 CrasAudioClient* GetCrasAudioClient(); |
| 105 CrosDisksClient* GetCrosDisksClient(); | 106 CrosDisksClient* GetCrosDisksClient(); |
| 106 CryptohomeClient* GetCryptohomeClient(); | 107 CryptohomeClient* GetCryptohomeClient(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 125 | 126 |
| 126 private: | 127 private: |
| 127 friend class DBusThreadManagerSetter; | 128 friend class DBusThreadManagerSetter; |
| 128 | 129 |
| 129 // Creates a new DBusThreadManager using the DBusClients set in | 130 // Creates a new DBusThreadManager using the DBusClients set in |
| 130 // |client_bundle|. | 131 // |client_bundle|. |
| 131 explicit DBusThreadManager(std::unique_ptr<DBusClientBundle> client_bundle); | 132 explicit DBusThreadManager(std::unique_ptr<DBusClientBundle> client_bundle); |
| 132 ~DBusThreadManager(); | 133 ~DBusThreadManager(); |
| 133 | 134 |
| 134 // Creates a global instance of DBusThreadManager with the real | 135 // Creates a global instance of DBusThreadManager with the real |
| 135 // implementations for all clients that are listed in |unstub_client_mask| and | 136 // implementations for all clients that are listed in |real_client_mask| and |
| 136 // stub implementations for all clients that are not included. Cannot be | 137 // fake implementations for all clients that are not included. Cannot be |
| 137 // called more than once. | 138 // called more than once. |
| 138 static void CreateGlobalInstance( | 139 static void CreateGlobalInstance(DBusClientTypeMask real_client_mask); |
| 139 DBusClientBundle::DBusClientTypeMask unstub_client_mask); | |
| 140 | 140 |
| 141 // Initialize global thread manager instance with all real dbus client | 141 // Initialize global thread manager instance with all real dbus client |
| 142 // implementations. | 142 // implementations. |
| 143 static void InitializeWithRealClients(); | 143 static void InitializeWithRealClients(); |
| 144 | 144 |
| 145 // Initialize global thread manager instance with stubbed-out dbus clients | 145 // Initialize global thread manager instance with fake dbus clients. |
| 146 // implementation. | 146 static void InitializeWithFakeClients(); |
| 147 static void InitializeWithStubs(); | |
| 148 | 147 |
| 149 // Initialize with stub implementations for only certain clients that are | 148 // Initialize with fake implementations for only certain clients that are |
| 150 // not included in the comma-separated |unstub_clients| list. | 149 // not included in the comma-separated |force_real_clients| list. |
| 151 static void InitializeWithPartialStub(const std::string& unstub_clients); | 150 static void InitializeWithPartialFakes(const std::string& force_real_clients); |
| 152 | 151 |
| 153 // Initializes all currently stored DBusClients with the system bus and | 152 // Initializes all currently stored DBusClients with the system bus and |
| 154 // performs additional setup. | 153 // performs additional setup. |
| 155 void InitializeClients(); | 154 void InitializeClients(); |
| 156 | 155 |
| 157 std::unique_ptr<base::Thread> dbus_thread_; | 156 std::unique_ptr<base::Thread> dbus_thread_; |
| 158 scoped_refptr<dbus::Bus> system_bus_; | 157 scoped_refptr<dbus::Bus> system_bus_; |
| 159 std::unique_ptr<DBusClientBundle> client_bundle_; | 158 std::unique_ptr<DBusClientBundle> client_bundle_; |
| 160 | 159 |
| 161 DISALLOW_COPY_AND_ASSIGN(DBusThreadManager); | 160 DISALLOW_COPY_AND_ASSIGN(DBusThreadManager); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 friend class DBusThreadManager; | 193 friend class DBusThreadManager; |
| 195 | 194 |
| 196 DBusThreadManagerSetter(); | 195 DBusThreadManagerSetter(); |
| 197 | 196 |
| 198 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerSetter); | 197 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerSetter); |
| 199 }; | 198 }; |
| 200 | 199 |
| 201 } // namespace chromeos | 200 } // namespace chromeos |
| 202 | 201 |
| 203 #endif // CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ | 202 #endif // CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ |
| OLD | NEW |