OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CHROME_BROWSER_CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 // | 32 // |
33 // This class also manages D-Bus connections and D-Bus clients, which | 33 // This class also manages D-Bus connections and D-Bus clients, which |
34 // depend on the D-Bus thread to ensure the right order of shutdowns for | 34 // depend on the D-Bus thread to ensure the right order of shutdowns for |
35 // the D-Bus thread, the D-Bus connections, and the D-Bus clients. | 35 // the D-Bus thread, the D-Bus connections, and the D-Bus clients. |
36 // | 36 // |
37 // CALLBACKS IN D-BUS CLIENTS: | 37 // CALLBACKS IN D-BUS CLIENTS: |
38 // | 38 // |
39 // D-Bus clients managed by DBusThreadManager are guaranteed to be deleted | 39 // D-Bus clients managed by DBusThreadManager are guaranteed to be deleted |
40 // after the D-Bus thread so the clients don't need to worry if new | 40 // after the D-Bus thread so the clients don't need to worry if new |
41 // incoming messages arrive from the D-Bus thread during shutdown of the | 41 // incoming messages arrive from the D-Bus thread during shutdown of the |
42 // clients. However, the UI message loop may still be running during the | 42 // clients. The UI message loop is not running during the shutdown hence |
43 // shutdown, hence the D-Bus clients should inherit | 43 // the UI message loop won't post tasks to D-BUS clients during the |
44 // base::RefCountedThreadSafe if they export methods or call methods, to | 44 // shutdown. However, to be extra cautious, clients should use |
45 // ensure that callbacks can reference |this| safely on the UI thread | 45 // WeakPtrFactory when creating callbacks that run on UI thread. See |
46 // during the shutdown. | 46 // session_manager_client.cc for examples. |
47 // | 47 // |
48 class DBusThreadManager { | 48 class DBusThreadManager { |
49 public: | 49 public: |
50 // Sets the global instance. Must be called before any calls to Get(). | 50 // Sets the global instance. Must be called before any calls to Get(). |
51 // We explicitly initialize and shut down the global object, rather than | 51 // We explicitly initialize and shut down the global object, rather than |
52 // making it a Singleton, to ensure clean startup and shutdown. | 52 // making it a Singleton, to ensure clean startup and shutdown. |
53 static void Initialize(); | 53 static void Initialize(); |
54 | 54 |
55 // Destroys the global instance. | 55 // Destroys the global instance. |
56 static void Shutdown(); | 56 static void Shutdown(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 SpeechSynthesizerClient* speech_synthesizer_client() { | 96 SpeechSynthesizerClient* speech_synthesizer_client() { |
97 return speech_synthesizer_client_.get(); | 97 return speech_synthesizer_client_.get(); |
98 } | 98 } |
99 | 99 |
100 private: | 100 private: |
101 DBusThreadManager(); | 101 DBusThreadManager(); |
102 virtual ~DBusThreadManager(); | 102 virtual ~DBusThreadManager(); |
103 | 103 |
104 scoped_ptr<base::Thread> dbus_thread_; | 104 scoped_ptr<base::Thread> dbus_thread_; |
105 scoped_refptr<dbus::Bus> system_bus_; | 105 scoped_refptr<dbus::Bus> system_bus_; |
106 CrosDBusService* cros_dbus_service_; | 106 scoped_ptr<CrosDBusService> cros_dbus_service_; |
107 scoped_ptr<SensorsSource> sensors_source_; | 107 scoped_ptr<SensorsSource> sensors_source_; |
108 scoped_ptr<BluetoothManagerClient> bluetooth_manager_client_; | 108 scoped_ptr<BluetoothManagerClient> bluetooth_manager_client_; |
109 scoped_ptr<BluetoothAdapterClient> bluetooth_adapter_client_; | 109 scoped_ptr<BluetoothAdapterClient> bluetooth_adapter_client_; |
110 scoped_ptr<PowerManagerClient> power_manager_client_; | 110 scoped_ptr<PowerManagerClient> power_manager_client_; |
111 scoped_ptr<SessionManagerClient> session_manager_client_; | 111 scoped_ptr<SessionManagerClient> session_manager_client_; |
112 scoped_ptr<SpeechSynthesizerClient> speech_synthesizer_client_; | 112 scoped_ptr<SpeechSynthesizerClient> speech_synthesizer_client_; |
113 | 113 |
114 DISALLOW_COPY_AND_ASSIGN(DBusThreadManager); | 114 DISALLOW_COPY_AND_ASSIGN(DBusThreadManager); |
115 }; | 115 }; |
116 | 116 |
117 } // namespace chromeos | 117 } // namespace chromeos |
118 | 118 |
119 #endif // CHROME_BROWSER_CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ | 119 #endif // CHROME_BROWSER_CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ |
OLD | NEW |