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

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

Issue 8343069: chromeos: Add MockDBusThreadManager and mock clients. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add todo Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 // WeakPtrFactory when creating callbacks that run on UI thread. See 45 // WeakPtrFactory when creating callbacks that run on UI thread. See
46 // session_manager_client.cc for examples. 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 // Similar to Initialize(), but can inject an alternative
56 // DBusThreadManager such as MockDBusThreadManager for testing.
57 // The injected object will be owned by the internal pointer and deleted
58 // by Shutdown().
59 static void InitializeForTesting(DBusThreadManager* dbus_thread_manager);
60
55 // Destroys the global instance. 61 // Destroys the global instance.
56 static void Shutdown(); 62 static void Shutdown();
57 63
58 // Gets the global instance. Initialize() must be called first. 64 // Gets the global instance. Initialize() must be called first.
59 static DBusThreadManager* Get(); 65 static DBusThreadManager* Get();
60 66
61 // Returns the bluetooth manager client, owned by DBusThreadManager. 67 // TODO(satorux): Rename the following getters to something like
62 // Do not cache this pointer and use it after DBusThreadManager is shut 68 // GetFooClient() as they are now virtual.
63 // down.
64 BluetoothManagerClient* bluetooth_manager_client() {
65 return bluetooth_manager_client_.get();
66 }
67 69
68 // Returns the bluetooth adapter client, owned by DBusThreadManager. 70 // Returns the bluetooth adapter client, owned by DBusThreadManager.
69 // Do not cache this pointer and use it after DBusThreadManager is shut 71 // Do not cache this pointer and use it after DBusThreadManager is shut
70 // down. 72 // down.
71 BluetoothAdapterClient* bluetooth_adapter_client() { 73 virtual BluetoothAdapterClient* bluetooth_adapter_client() = 0;
72 return bluetooth_adapter_client_.get(); 74
73 } 75 // Returns the bluetooth manager client, owned by DBusThreadManager.
76 // Do not cache this pointer and use it after DBusThreadManager is shut
77 // down.
78 virtual BluetoothManagerClient* bluetooth_manager_client() = 0;
74 79
75 // Returns the power manager client, owned by DBusThreadManager. 80 // Returns the power manager client, owned by DBusThreadManager.
76 // See also comments at session_manager_client(). 81 // See also comments at session_manager_client().
77 PowerManagerClient* power_manager_client() { 82 virtual PowerManagerClient* power_manager_client() = 0;
78 return power_manager_client_.get();
79 }
80 83
81 // Returns the session manager client, owned by DBusThreadManager. 84 // Returns the session manager client, owned by DBusThreadManager.
82 // Do not cache this pointer and use it after DBusThreadManager is shut 85 // Do not cache this pointer and use it after DBusThreadManager is shut
83 // down. 86 // down.
84 SessionManagerClient* session_manager_client() { 87 virtual SensorsClient* sensors_client() = 0;
85 return session_manager_client_.get(); 88
86 } 89 // Returns the session manager client, owned by DBusThreadManager.
90 // Do not cache this pointer and use it after DBusThreadManager is shut
91 // down.
92 virtual SessionManagerClient* session_manager_client() = 0;
87 93
88 // Sets the session manager client. Takes the ownership. 94 // Sets the session manager client. Takes the ownership.
89 // The function is exported for testing. 95 // The function is exported for testing.
90 void set_session_manager_client_for_testing( 96 //
91 SessionManagerClient* session_manager_client); 97 // TODO(satorux): Remove this once we convert tests to use
98 // MockDBusThreadManager.
99 virtual void set_session_manager_client_for_testing(
100 SessionManagerClient* session_manager_client) = 0;
92 101
93 // Returns the speech synthesizer client, owned by DBusThreadManager. 102 // Returns the speech synthesizer client, owned by DBusThreadManager.
94 // Do not cache this pointer and use it after DBusThreadManager is shut 103 // Do not cache this pointer and use it after DBusThreadManager is shut
95 // down. 104 // down.
96 SpeechSynthesizerClient* speech_synthesizer_client() { 105 virtual SpeechSynthesizerClient* speech_synthesizer_client() = 0;
97 return speech_synthesizer_client_.get();
98 }
99 106
100 private:
101 DBusThreadManager();
102 virtual ~DBusThreadManager(); 107 virtual ~DBusThreadManager();
103 108
104 scoped_ptr<base::Thread> dbus_thread_; 109 protected:
105 scoped_refptr<dbus::Bus> system_bus_; 110 DBusThreadManager();
106 scoped_ptr<CrosDBusService> cros_dbus_service_;
107 scoped_ptr<SensorsClient> sensors_client_;
108 scoped_ptr<BluetoothManagerClient> bluetooth_manager_client_;
109 scoped_ptr<BluetoothAdapterClient> bluetooth_adapter_client_;
110 scoped_ptr<PowerManagerClient> power_manager_client_;
111 scoped_ptr<SessionManagerClient> session_manager_client_;
112 scoped_ptr<SpeechSynthesizerClient> speech_synthesizer_client_;
113 111
114 DISALLOW_COPY_AND_ASSIGN(DBusThreadManager); 112 DISALLOW_COPY_AND_ASSIGN(DBusThreadManager);
115 }; 113 };
116 114
117 } // namespace chromeos 115 } // namespace chromeos
118 116
119 #endif // CHROME_BROWSER_CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_ 117 #endif // CHROME_BROWSER_CHROMEOS_DBUS_DBUS_THREAD_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698