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

Side by Side Diff: components/arc/arc_bridge_service.h

Issue 2146573005: Revert of arc: Use the new InstanceHolder for unittests (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@bridge_refactor_first
Patch Set: Created 4 years, 5 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ 5 #ifndef COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_
6 #define COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ 6 #define COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 10 matching lines...) Expand all
21 } // namespace base 21 } // namespace base
22 22
23 namespace arc { 23 namespace arc {
24 24
25 class ArcBridgeBootstrap; 25 class ArcBridgeBootstrap;
26 class ArcBridgeTest; 26 class ArcBridgeTest;
27 27
28 // The Chrome-side service that handles ARC instances and ARC bridge creation. 28 // The Chrome-side service that handles ARC instances and ARC bridge creation.
29 // This service handles the lifetime of ARC instances and sets up the 29 // This service handles the lifetime of ARC instances and sets up the
30 // communication channel (the ARC bridge) used to send and receive messages. 30 // communication channel (the ARC bridge) used to send and receive messages.
31 class ArcBridgeService { 31 class ArcBridgeService : public mojom::ArcBridgeHost {
32 public: 32 public:
33 // Notifies life cycle events of ArcBridgeService. 33 // Notifies life cycle events of ArcBridgeService.
34 class Observer { 34 class Observer {
35 public: 35 public:
36 // Called whenever the state of the bridge has changed. 36 // Called whenever the state of the bridge has changed.
37 virtual void OnBridgeReady() {} 37 virtual void OnBridgeReady() {}
38 virtual void OnBridgeStopped() {} 38 virtual void OnBridgeStopped() {}
39 39
40 // Called whenever ARC's availability has changed for this system. 40 // Called whenever ARC's availability has changed for this system.
41 virtual void OnAvailableChanged(bool available) {} 41 virtual void OnAvailableChanged(bool available) {}
42 42
43 protected: 43 protected:
44 virtual ~Observer() {} 44 virtual ~Observer() {}
45 }; 45 };
46 46
47 virtual ~ArcBridgeService(); 47 ~ArcBridgeService() override;
48 48
49 // Gets the global instance of the ARC Bridge Service. This can only be 49 // Gets the global instance of the ARC Bridge Service. This can only be
50 // called on the thread that this class was created on. 50 // called on the thread that this class was created on.
51 static ArcBridgeService* Get(); 51 static ArcBridgeService* Get();
52 52
53 // Return true if ARC has been enabled through a commandline 53 // Return true if ARC has been enabled through a commandline
54 // switch. 54 // switch.
55 static bool GetEnabled(const base::CommandLine* command_line); 55 static bool GetEnabled(const base::CommandLine* command_line);
56 56
57 // SetDetectedAvailability() should be called once CheckArcAvailability() on 57 // SetDetectedAvailability() should be called once CheckArcAvailability() on
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 InstanceHolder<mojom::PowerInstance>* power() { return &power_; } 101 InstanceHolder<mojom::PowerInstance>* power() { return &power_; }
102 InstanceHolder<mojom::ProcessInstance>* process() { return &process_; } 102 InstanceHolder<mojom::ProcessInstance>* process() { return &process_; }
103 InstanceHolder<mojom::StorageManagerInstance>* storage_manager() { 103 InstanceHolder<mojom::StorageManagerInstance>* storage_manager() {
104 return &storage_manager_; 104 return &storage_manager_;
105 } 105 }
106 InstanceHolder<mojom::VideoInstance>* video() { return &video_; } 106 InstanceHolder<mojom::VideoInstance>* video() { return &video_; }
107 InstanceHolder<mojom::WindowManagerInstance>* window_manager() { 107 InstanceHolder<mojom::WindowManagerInstance>* window_manager() {
108 return &window_manager_; 108 return &window_manager_;
109 } 109 }
110 110
111 // ArcHost:
112 void OnAppInstanceReady(mojom::AppInstancePtr app_ptr) override;
113 void OnAudioInstanceReady(mojom::AudioInstancePtr audio_ptr) override;
114 void OnAuthInstanceReady(mojom::AuthInstancePtr auth_ptr) override;
115 void OnBluetoothInstanceReady(
116 mojom::BluetoothInstancePtr bluetooth_ptr) override;
117 void OnClipboardInstanceReady(
118 mojom::ClipboardInstancePtr clipboard_ptr) override;
119 void OnCrashCollectorInstanceReady(
120 mojom::CrashCollectorInstancePtr crash_collector_ptr) override;
121 void OnFileSystemInstanceReady(
122 mojom::FileSystemInstancePtr file_system_ptr) override;
123 void OnImeInstanceReady(mojom::ImeInstancePtr ime_ptr) override;
124 void OnIntentHelperInstanceReady(
125 mojom::IntentHelperInstancePtr intent_helper_ptr) override;
126 void OnMetricsInstanceReady(mojom::MetricsInstancePtr metrics_ptr) override;
127 void OnNetInstanceReady(mojom::NetInstancePtr net_ptr) override;
128 void OnNotificationsInstanceReady(
129 mojom::NotificationsInstancePtr notifications_ptr) override;
130 void OnObbMounterInstanceReady(
131 mojom::ObbMounterInstancePtr obb_mounter_ptr) override;
132 void OnPolicyInstanceReady(mojom::PolicyInstancePtr policy_ptr) override;
133 void OnPowerInstanceReady(mojom::PowerInstancePtr power_ptr) override;
134 void OnProcessInstanceReady(mojom::ProcessInstancePtr process_ptr) override;
135 void OnStorageManagerInstanceReady(
136 mojom::StorageManagerInstancePtr storage_manager_ptr) override;
137 void OnVideoInstanceReady(mojom::VideoInstancePtr video_ptr) override;
138 void OnWindowManagerInstanceReady(
139 mojom::WindowManagerInstancePtr window_manager_ptr) override;
140
111 // Gets if ARC is available in this system. 141 // Gets if ARC is available in this system.
112 bool available() const { return available_; } 142 bool available() const { return available_; }
113 143
114 // Gets if ARC is currently running. 144 // Gets if ARC is currently running.
115 bool ready() const { return state() == State::READY; } 145 bool ready() const { return state() == State::READY; }
116 146
117 // Gets if ARC is currently stopped. This is not exactly !ready() since there 147 // Gets if ARC is currently stopped. This is not exactly !ready() since there
118 // are transient states between ready() and stopped(). 148 // are transient states between ready() and stopped().
119 bool stopped() const { return state() == State::STOPPED; } 149 bool stopped() const { return state() == State::STOPPED; }
120 150
(...skipping 28 matching lines...) Expand all
149 // The ARC instance has finished initializing and is now ready for user 179 // The ARC instance has finished initializing and is now ready for user
150 // interaction. 180 // interaction.
151 READY, 181 READY,
152 182
153 // The ARC instance has started shutting down. 183 // The ARC instance has started shutting down.
154 STOPPING, 184 STOPPING,
155 }; 185 };
156 186
157 ArcBridgeService(); 187 ArcBridgeService();
158 188
189 // Gets the current state of the bridge service.
190 State state() const { return state_; }
191
192 // Changes the current state and notifies all observers.
193 void SetState(State state);
194
195 // Changes the current availability and notifies all observers.
196 void SetAvailable(bool availability);
197
198 base::ObserverList<Observer>& observer_list() { return observer_list_; }
199
200 bool CalledOnValidThread();
201
202 // Closes all Mojo channels.
203 void CloseAllChannels();
204
205 private:
206 friend class ArcBridgeTest;
207 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic);
208 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites);
209 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup);
210 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart);
211
159 // Instance holders. 212 // Instance holders.
160 InstanceHolder<mojom::AppInstance> app_; 213 InstanceHolder<mojom::AppInstance> app_;
161 InstanceHolder<mojom::AudioInstance> audio_; 214 InstanceHolder<mojom::AudioInstance> audio_;
162 InstanceHolder<mojom::AuthInstance> auth_; 215 InstanceHolder<mojom::AuthInstance> auth_;
163 InstanceHolder<mojom::BluetoothInstance> bluetooth_; 216 InstanceHolder<mojom::BluetoothInstance> bluetooth_;
164 InstanceHolder<mojom::ClipboardInstance> clipboard_; 217 InstanceHolder<mojom::ClipboardInstance> clipboard_;
165 InstanceHolder<mojom::CrashCollectorInstance> crash_collector_; 218 InstanceHolder<mojom::CrashCollectorInstance> crash_collector_;
166 InstanceHolder<mojom::FileSystemInstance> file_system_; 219 InstanceHolder<mojom::FileSystemInstance> file_system_;
167 InstanceHolder<mojom::ImeInstance> ime_; 220 InstanceHolder<mojom::ImeInstance> ime_;
168 InstanceHolder<mojom::IntentHelperInstance> intent_helper_; 221 InstanceHolder<mojom::IntentHelperInstance> intent_helper_;
169 InstanceHolder<mojom::MetricsInstance> metrics_; 222 InstanceHolder<mojom::MetricsInstance> metrics_;
170 InstanceHolder<mojom::NetInstance> net_; 223 InstanceHolder<mojom::NetInstance> net_;
171 InstanceHolder<mojom::NotificationsInstance> notifications_; 224 InstanceHolder<mojom::NotificationsInstance> notifications_;
172 InstanceHolder<mojom::ObbMounterInstance> obb_mounter_; 225 InstanceHolder<mojom::ObbMounterInstance> obb_mounter_;
173 InstanceHolder<mojom::PolicyInstance> policy_; 226 InstanceHolder<mojom::PolicyInstance> policy_;
174 InstanceHolder<mojom::PowerInstance> power_; 227 InstanceHolder<mojom::PowerInstance> power_;
175 InstanceHolder<mojom::ProcessInstance> process_; 228 InstanceHolder<mojom::ProcessInstance> process_;
176 InstanceHolder<mojom::StorageManagerInstance> storage_manager_; 229 InstanceHolder<mojom::StorageManagerInstance> storage_manager_;
177 InstanceHolder<mojom::VideoInstance> video_; 230 InstanceHolder<mojom::VideoInstance> video_;
178 InstanceHolder<mojom::WindowManagerInstance> window_manager_; 231 InstanceHolder<mojom::WindowManagerInstance> window_manager_;
179 232
180 // Gets the current state of the bridge service.
181 State state() const { return state_; }
182
183 // Changes the current state and notifies all observers.
184 void SetState(State state);
185
186 // Changes the current availability and notifies all observers.
187 void SetAvailable(bool availability);
188
189 base::ObserverList<Observer>& observer_list() { return observer_list_; }
190
191 bool CalledOnValidThread();
192
193 private:
194 friend class ArcBridgeTest;
195 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic);
196 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites);
197 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup);
198 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart);
199
200 base::ObserverList<Observer> observer_list_; 233 base::ObserverList<Observer> observer_list_;
201 234
202 base::ThreadChecker thread_checker_; 235 base::ThreadChecker thread_checker_;
203 236
204 // If the ARC instance service is available. 237 // If the ARC instance service is available.
205 bool available_; 238 bool available_;
206 239
207 // The current state of the bridge. 240 // The current state of the bridge.
208 ArcBridgeService::State state_; 241 ArcBridgeService::State state_;
209 242
210 // WeakPtrFactory to use callbacks. 243 // WeakPtrFactory to use callbacks.
211 base::WeakPtrFactory<ArcBridgeService> weak_factory_; 244 base::WeakPtrFactory<ArcBridgeService> weak_factory_;
212 245
213 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); 246 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService);
214 }; 247 };
215 248
216 } // namespace arc 249 } // namespace arc
217 250
218 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ 251 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/arc/arc_app_unittest.cc ('k') | components/arc/arc_bridge_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698