Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(607)

Side by Side Diff: chromeos/dbus/dbus_thread_manager.h

Issue 556833003: Fix minor issues about DBusThreadManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/callback.h" 8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // the UI message loop won't post tasks to D-BUS clients during the 79 // the UI message loop won't post tasks to D-BUS clients during the
80 // shutdown. However, to be extra cautious, clients should use 80 // shutdown. However, to be extra cautious, clients should use
81 // WeakPtrFactory when creating callbacks that run on UI thread. See 81 // WeakPtrFactory when creating callbacks that run on UI thread. See
82 // session_manager_client.cc for examples. 82 // session_manager_client.cc for examples.
83 // 83 //
84 class CHROMEOS_EXPORT DBusThreadManager { 84 class CHROMEOS_EXPORT DBusThreadManager {
85 public: 85 public:
86 // Sets the global instance. Must be called before any calls to Get(). 86 // Sets the global instance. Must be called before any calls to Get().
87 // We explicitly initialize and shut down the global object, rather than 87 // We explicitly initialize and shut down the global object, rather than
88 // making it a Singleton, to ensure clean startup and shutdown. 88 // making it a Singleton, to ensure clean startup and shutdown.
89 // This will initialize regular or stub DBusClients depending on command-line
90 // arguments and whether this process runs in a ChromeOS environment.
89 static void Initialize(); 91 static void Initialize();
90 92
91 // Returns a DBusThreadManagerSetter instance that allows tests to 93 // Returns a DBusThreadManagerSetter instance that allows tests to
92 // replace individual D-Bus clients with their own implementations. 94 // replace individual D-Bus clients with their own implementations.
93 // Also initializes the main DBusThreadManager for testing if necessary. 95 // Also initializes the main DBusThreadManager for testing if necessary.
94 static scoped_ptr<DBusThreadManagerSetter> GetSetterForTesting(); 96 static scoped_ptr<DBusThreadManagerSetter> GetSetterForTesting();
95 97
96 // Returns true if DBusThreadManager has been initialized. Call this to 98 // Returns true if DBusThreadManager has been initialized. Call this to
97 // avoid initializing + shutting down DBusThreadManager more than once. 99 // avoid initializing + shutting down DBusThreadManager more than once.
98 static bool IsInitialized(); 100 static bool IsInitialized();
99 101
100 // Destroys the global instance. 102 // Destroys the global instance.
101 static void Shutdown(); 103 static void Shutdown();
102 104
103 // Gets the global instance. Initialize() must be called first. 105 // Gets the global instance. Initialize() must be called first.
104 static DBusThreadManager* Get(); 106 static DBusThreadManager* Get();
105 107
106 // Returns true if |client| is stubbed. 108 // Returns true if |client| is stubbed.
107 static bool IsUsingStub(DBusClientBundle::DBusClientType client); 109 bool IsUsingStub(DBusClientBundle::DBusClientType client);
108 110
109 // Returns various D-Bus bus instances, owned by DBusThreadManager. 111 // Returns various D-Bus bus instances, owned by DBusThreadManager.
110 dbus::Bus* GetSystemBus(); 112 dbus::Bus* GetSystemBus();
111 113
112 // All returned objects are owned by DBusThreadManager. Do not cache these 114 // All returned objects are owned by DBusThreadManager. Do not cache these
113 // pointers and use them after DBusThreadManager has been shut down. 115 // pointers and use them after DBusThreadManager has been shut down.
114 BluetoothAdapterClient* GetBluetoothAdapterClient(); 116 BluetoothAdapterClient* GetBluetoothAdapterClient();
115 BluetoothAgentManagerClient* GetBluetoothAgentManagerClient(); 117 BluetoothAgentManagerClient* GetBluetoothAgentManagerClient();
116 BluetoothDeviceClient* GetBluetoothDeviceClient(); 118 BluetoothDeviceClient* GetBluetoothDeviceClient();
117 BluetoothGattCharacteristicClient* GetBluetoothGattCharacteristicClient(); 119 BluetoothGattCharacteristicClient* GetBluetoothGattCharacteristicClient();
(...skipping 26 matching lines...) Expand all
144 ShillManagerClient* GetShillManagerClient(); 146 ShillManagerClient* GetShillManagerClient();
145 ShillServiceClient* GetShillServiceClient(); 147 ShillServiceClient* GetShillServiceClient();
146 ShillProfileClient* GetShillProfileClient(); 148 ShillProfileClient* GetShillProfileClient();
147 SMSClient* GetSMSClient(); 149 SMSClient* GetSMSClient();
148 SystemClockClient* GetSystemClockClient(); 150 SystemClockClient* GetSystemClockClient();
149 UpdateEngineClient* GetUpdateEngineClient(); 151 UpdateEngineClient* GetUpdateEngineClient();
150 152
151 private: 153 private:
152 friend class DBusThreadManagerSetter; 154 friend class DBusThreadManagerSetter;
153 155
154 DBusThreadManager(); 156 // Creates a new DBusThreadManager using the DBusClients set in
157 // |client_bundle|.
158 DBusThreadManager(scoped_ptr<DBusClientBundle> client_bundle);
155 ~DBusThreadManager(); 159 ~DBusThreadManager();
156 160
157 // Creates a global instance of DBusThreadManager. Can not be called more 161 // Creates a global instance of DBusThreadManager. Can not be called more
158 // than once. 162 // than once.
159 static void CreateGlobalInstance(); 163 static void CreateGlobalInstance(
164 DBusClientBundle::DBusClientTypeMask unstub_client_mask);
160 165
161 // Initialize global thread manager instance. 166 // Initialize global thread manager instance.
162 static void InitializeRegular(); 167 static void InitializeRegular();
163 168
164 // Initialize global thread manager instance with stubbed-out dbus clients 169 // Initialize global thread manager instance with stubbed-out dbus clients
165 // implementation. 170 // implementation.
166 static void InitializeWithStubs(); 171 static void InitializeWithStubs();
167 172
168 // Initialize with stub implementations for only certain clients that are 173 // Initialize with stub implementations for only certain clients that are
169 // not included in comma-separated |unstub_clients| list. 174 // not included in comma-separated |unstub_clients| list.
170 static void InitializeWithPartialStub(const std::string& unstub_clients); 175 static void InitializeWithPartialStub(const std::string& unstub_clients);
171 176
172 // Constructs all clients and stores them in the respective *_client_ member 177 // Initializes all currently stored DBusClients with the system bus and
173 // variable. 178 // creates a stub network environment.
174 void CreateDefaultClients();
175
176 // Constructs all clients and stores them in the respective *_client_ member
177 // variable.
178 void InitializeClients(); 179 void InitializeClients();
179 180
180 // Bitmask that defines which dbus clients are not stubbed out. Bitmap flags
181 // are defined within DBusClientBundle::DBusClientType enum.
182 static DBusClientBundle::DBusClientTypeMask unstub_client_mask_;
183
184 scoped_ptr<base::Thread> dbus_thread_; 181 scoped_ptr<base::Thread> dbus_thread_;
185 scoped_refptr<dbus::Bus> system_bus_; 182 scoped_refptr<dbus::Bus> system_bus_;
186 scoped_ptr<DBusClientBundle> client_bundle_; 183 scoped_ptr<DBusClientBundle> client_bundle_;
187 scoped_ptr<PowerPolicyController> power_policy_controller_; 184 scoped_ptr<PowerPolicyController> power_policy_controller_;
188 185
189 DISALLOW_COPY_AND_ASSIGN(DBusThreadManager); 186 DISALLOW_COPY_AND_ASSIGN(DBusThreadManager);
190 }; 187 };
191 188
192 class CHROMEOS_EXPORT DBusThreadManagerSetter { 189 class CHROMEOS_EXPORT DBusThreadManagerSetter {
193 public: 190 public:
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 friend class DBusThreadManager; 236 friend class DBusThreadManager;
240 237
241 DBusThreadManagerSetter(); 238 DBusThreadManagerSetter();
242 239
243 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerSetter); 240 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerSetter);
244 }; 241 };
245 242
246 } // namespace chromeos 243 } // namespace chromeos
247 244
248 #endif // CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ 245 #endif // CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698