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

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

Issue 2190483003: arc: Revamp the ArcBridgeService interface (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@2785
Patch Set: One less diff line Created 4 years, 4 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
« no previous file with comments | « components/arc/BUILD.gn ('k') | components/arc/arc_bridge_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 #include "base/files/scoped_file.h" 11 #include "base/files/scoped_file.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/observer_list.h" 14 #include "base/observer_list.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "components/arc/common/arc_bridge.mojom.h" 16 #include "components/arc/common/arc_bridge.mojom.h"
17 #include "components/arc/instance_holder.h"
17 18
18 namespace base { 19 namespace base {
19 class CommandLine; 20 class CommandLine;
20 } // namespace base 21 } // namespace base
21 22
22 namespace arc { 23 namespace arc {
23 24
24 // The Chrome-side service that handles ARC instances and ARC bridge creation. 25 // The Chrome-side service that handles ARC instances and ARC bridge creation.
25 // This service handles the lifetime of ARC instances and sets up the 26 // This service handles the lifetime of ARC instances and sets up the
26 // communication channel (the ARC bridge) used to send and receive messages. 27 // communication channel (the ARC bridge) used to send and receive messages.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 public: 84 public:
84 // Called whenever the state of the bridge has changed. 85 // Called whenever the state of the bridge has changed.
85 // TODO(lchavez): Rename to OnStateChangedForTest 86 // TODO(lchavez): Rename to OnStateChangedForTest
86 virtual void OnStateChanged(State state) {} 87 virtual void OnStateChanged(State state) {}
87 virtual void OnBridgeReady() {} 88 virtual void OnBridgeReady() {}
88 virtual void OnBridgeStopped(StopReason reason) {} 89 virtual void OnBridgeStopped(StopReason reason) {}
89 90
90 // Called whenever ARC's availability has changed for this system. 91 // Called whenever ARC's availability has changed for this system.
91 virtual void OnAvailableChanged(bool available) {} 92 virtual void OnAvailableChanged(bool available) {}
92 93
93 // Called whenever the ARC app interface state changes.
94 virtual void OnAppInstanceReady() {}
95 virtual void OnAppInstanceClosed() {}
96
97 // Called whenever the ARC audio interface state changes.
98 virtual void OnAudioInstanceReady() {}
99 virtual void OnAudioInstanceClosed() {}
100
101 // Called whenever the ARC auth interface state changes.
102 virtual void OnAuthInstanceReady() {}
103 virtual void OnAuthInstanceClosed() {}
104
105 // Called whenever ARC Bluetooth instance is ready.
106 virtual void OnBluetoothInstanceReady() {}
107 virtual void OnBluetoothInstanceClosed() {}
108
109 // Called whenever the ARC clipboard interface state changes.
110 virtual void OnClipboardInstanceReady() {}
111 virtual void OnClipboardInstanceClosed() {}
112
113 // Called whenever the ARC crash collector interface state changes.
114 virtual void OnCrashCollectorInstanceReady() {}
115 virtual void OnCrashCollectorInstanceClosed() {}
116
117 // Called whenever the ARC file system interface state changes.
118 virtual void OnFileSystemInstanceReady() {}
119 virtual void OnFileSystemInstanceClosed() {}
120
121 // Called whenever the ARC IME interface state changes.
122 virtual void OnImeInstanceReady() {}
123 virtual void OnImeInstanceClosed() {}
124
125 // Called whenever the ARC intent helper interface state changes.
126 virtual void OnIntentHelperInstanceReady() {}
127 virtual void OnIntentHelperInstanceClosed() {}
128
129 // Called whenever the ARC metrics interface state changes.
130 virtual void OnMetricsInstanceReady() {}
131 virtual void OnMetricsInstanceClosed() {}
132
133 // Called whenever the ARC notification interface state changes.
134 virtual void OnNotificationsInstanceReady() {}
135 virtual void OnNotificationsInstanceClosed() {}
136
137 // Called whenever the ARC net interface state changes.
138 virtual void OnNetInstanceReady() {}
139 virtual void OnNetInstanceClosed() {}
140
141 // Called whenever the ARC OBB mounter interface state changes.
142 virtual void OnObbMounterInstanceReady() {}
143 virtual void OnObbMounterInstanceClosed() {}
144
145 // Called whenever the ARC policy interface state changes.
146 virtual void OnPolicyInstanceReady() {}
147 virtual void OnPolicyInstanceClosed() {}
148
149 // Called whenever the ARC power interface state changes.
150 virtual void OnPowerInstanceReady() {}
151 virtual void OnPowerInstanceClosed() {}
152
153 // Called whenever the ARC process interface state changes.
154 virtual void OnProcessInstanceReady() {}
155 virtual void OnProcessInstanceClosed() {}
156
157 // Called whenever the ARC storage manager interface state changes.
158 virtual void OnStorageManagerInstanceReady() {}
159 virtual void OnStorageManagerInstanceClosed() {}
160
161 // Called whenever the ARC video interface state changes.
162 virtual void OnVideoInstanceReady() {}
163 virtual void OnVideoInstanceClosed() {}
164
165 // Called whenever the ARC window manager interface state changes.
166 virtual void OnWindowManagerInstanceReady() {}
167 virtual void OnWindowManagerInstanceClosed() {}
168
169 protected: 94 protected:
170 virtual ~Observer() {} 95 virtual ~Observer() {}
171 }; 96 };
172 97
173 ~ArcBridgeService() override; 98 ~ArcBridgeService() override;
174 99
175 // Gets the global instance of the ARC Bridge Service. This can only be 100 // Gets the global instance of the ARC Bridge Service. This can only be
176 // called on the thread that this class was created on. 101 // called on the thread that this class was created on.
177 static ArcBridgeService* Get(); 102 static ArcBridgeService* Get();
178 103
(...skipping 14 matching lines...) Expand all
193 // Shutdown() should be called when the browser is shutting down. This can 118 // Shutdown() should be called when the browser is shutting down. This can
194 // only be called on the thread that this class was created on. 119 // only be called on the thread that this class was created on.
195 virtual void Shutdown() = 0; 120 virtual void Shutdown() = 0;
196 121
197 // Adds or removes observers. This can only be called on the thread that this 122 // Adds or removes observers. This can only be called on the thread that this
198 // class was created on. RemoveObserver does nothing if |observer| is not in 123 // class was created on. RemoveObserver does nothing if |observer| is not in
199 // the list. 124 // the list.
200 void AddObserver(Observer* observer); 125 void AddObserver(Observer* observer);
201 void RemoveObserver(Observer* observer); 126 void RemoveObserver(Observer* observer);
202 127
203 // Gets the Mojo interface for all the instance services. This will return 128 InstanceHolder<mojom::AppInstance>* app() { return &app_; }
204 // nullptr if that particular service is not ready yet. Use an Observer if 129 InstanceHolder<mojom::AudioInstance>* audio() { return &audio_; }
205 // you want to be notified when this is ready. This can only be called on the 130 InstanceHolder<mojom::AuthInstance>* auth() { return &auth_; }
206 // thread that this class was created on. 131 InstanceHolder<mojom::BluetoothInstance>* bluetooth() { return &bluetooth_; }
207 mojom::AppInstance* app_instance() { return app_ptr_.get(); } 132 InstanceHolder<mojom::ClipboardInstance>* clipboard() { return &clipboard_; }
208 mojom::AudioInstance* audio_instance() { return audio_ptr_.get(); } 133 InstanceHolder<mojom::CrashCollectorInstance>* crash_collector() {
209 mojom::AuthInstance* auth_instance() { return auth_ptr_.get(); } 134 return &crash_collector_;
210 mojom::BluetoothInstance* bluetooth_instance() {
211 return bluetooth_ptr_.get();
212 } 135 }
213 mojom::ClipboardInstance* clipboard_instance() { 136 InstanceHolder<mojom::FileSystemInstance>* file_system() {
214 return clipboard_ptr_.get(); 137 return &file_system_;
215 } 138 }
216 mojom::CrashCollectorInstance* crash_collector_instance() { 139 InstanceHolder<mojom::ImeInstance>* ime() { return &ime_; }
217 return crash_collector_ptr_.get(); 140 InstanceHolder<mojom::IntentHelperInstance>* intent_helper() {
141 return &intent_helper_;
218 } 142 }
219 mojom::FileSystemInstance* file_system_instance() { 143 InstanceHolder<mojom::MetricsInstance>* metrics() { return &metrics_; }
220 return file_system_ptr_.get(); 144 InstanceHolder<mojom::NetInstance>* net() { return &net_; }
145 InstanceHolder<mojom::NotificationsInstance>* notifications() {
146 return &notifications_;
221 } 147 }
222 mojom::ImeInstance* ime_instance() { return ime_ptr_.get(); } 148 InstanceHolder<mojom::ObbMounterInstance>* obb_mounter() {
223 mojom::IntentHelperInstance* intent_helper_instance() { 149 return &obb_mounter_;
224 return intent_helper_ptr_.get();
225 } 150 }
226 mojom::MetricsInstance* metrics_instance() { return metrics_ptr_.get(); } 151 InstanceHolder<mojom::PolicyInstance>* policy() { return &policy_; }
227 mojom::NetInstance* net_instance() { return net_ptr_.get(); } 152 InstanceHolder<mojom::PowerInstance>* power() { return &power_; }
228 mojom::NotificationsInstance* notifications_instance() { 153 InstanceHolder<mojom::ProcessInstance>* process() { return &process_; }
229 return notifications_ptr_.get(); 154 InstanceHolder<mojom::StorageManagerInstance>* storage_manager() {
155 return &storage_manager_;
230 } 156 }
231 mojom::ObbMounterInstance* obb_mounter_instance() { 157 InstanceHolder<mojom::VideoInstance>* video() { return &video_; }
232 return obb_mounter_ptr_.get(); 158 InstanceHolder<mojom::WindowManagerInstance>* window_manager() {
233 } 159 return &window_manager_;
234 mojom::PolicyInstance* policy_instance() { return policy_ptr_.get(); }
235 mojom::PowerInstance* power_instance() { return power_ptr_.get(); }
236 mojom::ProcessInstance* process_instance() { return process_ptr_.get(); }
237 mojom::StorageManagerInstance* storage_manager_instance() {
238 return storage_manager_ptr_.get();
239 }
240 mojom::VideoInstance* video_instance() { return video_ptr_.get(); }
241 mojom::WindowManagerInstance* window_manager_instance() {
242 return window_manager_ptr_.get();
243 }
244
245 int32_t app_version() const { return app_ptr_.version(); }
246 int32_t audio_version() const { return audio_ptr_.version(); }
247 int32_t bluetooth_version() const { return bluetooth_ptr_.version(); }
248 int32_t auth_version() const { return auth_ptr_.version(); }
249 int32_t clipboard_version() const { return clipboard_ptr_.version(); }
250 int32_t crash_collector_version() const {
251 return crash_collector_ptr_.version();
252 }
253 int32_t file_system_version() const { return file_system_ptr_.version(); }
254 int32_t ime_version() const { return ime_ptr_.version(); }
255 int32_t intent_helper_version() const { return intent_helper_ptr_.version(); }
256 int32_t metrics_version() const { return metrics_ptr_.version(); }
257 int32_t net_version() const { return net_ptr_.version(); }
258 int32_t notifications_version() const { return notifications_ptr_.version(); }
259 int32_t obb_mounter_version() const { return obb_mounter_ptr_.version(); }
260 int32_t policy_version() const { return policy_ptr_.version(); }
261 int32_t power_version() const { return power_ptr_.version(); }
262 int32_t process_version() const { return process_ptr_.version(); }
263 int32_t storage_manager_version() const {
264 return storage_manager_ptr_.version();
265 }
266 int32_t video_version() const { return video_ptr_.version(); }
267 int32_t window_manager_version() const {
268 return window_manager_ptr_.version();
269 } 160 }
270 161
271 // ArcHost: 162 // ArcHost:
272 void OnAppInstanceReady(mojom::AppInstancePtr app_ptr) override; 163 void OnAppInstanceReady(mojom::AppInstancePtr app_ptr) override;
273 void OnAudioInstanceReady(mojom::AudioInstancePtr audio_ptr) override; 164 void OnAudioInstanceReady(mojom::AudioInstancePtr audio_ptr) override;
274 void OnAuthInstanceReady(mojom::AuthInstancePtr auth_ptr) override; 165 void OnAuthInstanceReady(mojom::AuthInstancePtr auth_ptr) override;
275 void OnBluetoothInstanceReady( 166 void OnBluetoothInstanceReady(
276 mojom::BluetoothInstancePtr bluetooth_ptr) override; 167 mojom::BluetoothInstancePtr bluetooth_ptr) override;
277 void OnClipboardInstanceReady( 168 void OnClipboardInstanceReady(
278 mojom::ClipboardInstancePtr clipboard_ptr) override; 169 mojom::ClipboardInstancePtr clipboard_ptr) override;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 void CloseAllChannels(); 217 void CloseAllChannels();
327 218
328 private: 219 private:
329 friend class ArcBridgeTest; 220 friend class ArcBridgeTest;
330 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); 221 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic);
331 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites); 222 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites);
332 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup); 223 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup);
333 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart); 224 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart);
334 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, OnBridgeStopped); 225 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, OnBridgeStopped);
335 226
336 // Called when one of the individual channels is closed. 227 // Instance holders.
337 void CloseAppChannel(); 228 InstanceHolder<mojom::AppInstance> app_;
338 void CloseAudioChannel(); 229 InstanceHolder<mojom::AudioInstance> audio_;
339 void CloseAuthChannel(); 230 InstanceHolder<mojom::AuthInstance> auth_;
340 void CloseBluetoothChannel(); 231 InstanceHolder<mojom::BluetoothInstance> bluetooth_;
341 void CloseClipboardChannel(); 232 InstanceHolder<mojom::ClipboardInstance> clipboard_;
342 void CloseCrashCollectorChannel(); 233 InstanceHolder<mojom::CrashCollectorInstance> crash_collector_;
343 void CloseFileSystemChannel(); 234 InstanceHolder<mojom::FileSystemInstance> file_system_;
344 void CloseImeChannel(); 235 InstanceHolder<mojom::ImeInstance> ime_;
345 void CloseIntentHelperChannel(); 236 InstanceHolder<mojom::IntentHelperInstance> intent_helper_;
346 void CloseMetricsChannel(); 237 InstanceHolder<mojom::MetricsInstance> metrics_;
347 void CloseNetChannel(); 238 InstanceHolder<mojom::NetInstance> net_;
348 void CloseNotificationsChannel(); 239 InstanceHolder<mojom::NotificationsInstance> notifications_;
349 void CloseObbMounterChannel(); 240 InstanceHolder<mojom::ObbMounterInstance> obb_mounter_;
350 void ClosePolicyChannel(); 241 InstanceHolder<mojom::PolicyInstance> policy_;
351 void ClosePowerChannel(); 242 InstanceHolder<mojom::PowerInstance> power_;
352 void CloseProcessChannel(); 243 InstanceHolder<mojom::ProcessInstance> process_;
353 void CloseStorageManagerChannel(); 244 InstanceHolder<mojom::StorageManagerInstance> storage_manager_;
354 void CloseVideoChannel(); 245 InstanceHolder<mojom::VideoInstance> video_;
355 void CloseWindowManagerChannel(); 246 InstanceHolder<mojom::WindowManagerInstance> window_manager_;
356
357 // Callbacks for QueryVersion.
358 void OnAppVersionReady(uint32_t version);
359 void OnAudioVersionReady(uint32_t version);
360 void OnAuthVersionReady(uint32_t version);
361 void OnBluetoothVersionReady(uint32_t version);
362 void OnClipboardVersionReady(uint32_t version);
363 void OnCrashCollectorVersionReady(uint32_t version);
364 void OnFileSystemVersionReady(uint32_t version);
365 void OnImeVersionReady(uint32_t version);
366 void OnIntentHelperVersionReady(uint32_t version);
367 void OnMetricsVersionReady(uint32_t version);
368 void OnNetVersionReady(uint32_t version);
369 void OnNotificationsVersionReady(uint32_t version);
370 void OnObbMounterVersionReady(uint32_t version);
371 void OnPolicyVersionReady(uint32_t version);
372 void OnPowerVersionReady(uint32_t version);
373 void OnProcessVersionReady(uint32_t version);
374 void OnStorageManagerVersionReady(uint32_t version);
375 void OnVideoVersionReady(uint32_t version);
376 void OnWindowManagerVersionReady(uint32_t version);
377
378 // Mojo interfaces.
379 mojom::AppInstancePtr app_ptr_;
380 mojom::AudioInstancePtr audio_ptr_;
381 mojom::AuthInstancePtr auth_ptr_;
382 mojom::BluetoothInstancePtr bluetooth_ptr_;
383 mojom::ClipboardInstancePtr clipboard_ptr_;
384 mojom::CrashCollectorInstancePtr crash_collector_ptr_;
385 mojom::FileSystemInstancePtr file_system_ptr_;
386 mojom::ImeInstancePtr ime_ptr_;
387 mojom::IntentHelperInstancePtr intent_helper_ptr_;
388 mojom::MetricsInstancePtr metrics_ptr_;
389 mojom::NetInstancePtr net_ptr_;
390 mojom::NotificationsInstancePtr notifications_ptr_;
391 mojom::ObbMounterInstancePtr obb_mounter_ptr_;
392 mojom::PolicyInstancePtr policy_ptr_;
393 mojom::PowerInstancePtr power_ptr_;
394 mojom::ProcessInstancePtr process_ptr_;
395 mojom::StorageManagerInstancePtr storage_manager_ptr_;
396 mojom::VideoInstancePtr video_ptr_;
397 mojom::WindowManagerInstancePtr window_manager_ptr_;
398
399 // Temporary Mojo interfaces. After a Mojo interface pointer has been
400 // received from the other endpoint, we still need to asynchronously query
401 // its version. While that is going on, we should still return nullptr on
402 // the xxx_instance() functions.
403 // To keep the xxx_instance() functions being trivial, store the instance
404 // pointer in a temporary variable to avoid losing its reference.
405 mojom::AppInstancePtr temporary_app_ptr_;
406 mojom::AudioInstancePtr temporary_audio_ptr_;
407 mojom::AuthInstancePtr temporary_auth_ptr_;
408 mojom::BluetoothInstancePtr temporary_bluetooth_ptr_;
409 mojom::ClipboardInstancePtr temporary_clipboard_ptr_;
410 mojom::CrashCollectorInstancePtr temporary_crash_collector_ptr_;
411 mojom::FileSystemInstancePtr temporary_file_system_ptr_;
412 mojom::ImeInstancePtr temporary_ime_ptr_;
413 mojom::IntentHelperInstancePtr temporary_intent_helper_ptr_;
414 mojom::MetricsInstancePtr temporary_metrics_ptr_;
415 mojom::NetInstancePtr temporary_net_ptr_;
416 mojom::NotificationsInstancePtr temporary_notifications_ptr_;
417 mojom::ObbMounterInstancePtr temporary_obb_mounter_ptr_;
418 mojom::PolicyInstancePtr temporary_policy_ptr_;
419 mojom::PowerInstancePtr temporary_power_ptr_;
420 mojom::ProcessInstancePtr temporary_process_ptr_;
421 mojom::StorageManagerInstancePtr temporary_storage_manager_ptr_;
422 mojom::VideoInstancePtr temporary_video_ptr_;
423 mojom::WindowManagerInstancePtr temporary_window_manager_ptr_;
424 247
425 base::ObserverList<Observer> observer_list_; 248 base::ObserverList<Observer> observer_list_;
426 249
427 base::ThreadChecker thread_checker_; 250 base::ThreadChecker thread_checker_;
428 251
429 // If the ARC instance service is available. 252 // If the ARC instance service is available.
430 bool available_; 253 bool available_;
431 254
432 // The current state of the bridge. 255 // The current state of the bridge.
433 ArcBridgeService::State state_; 256 ArcBridgeService::State state_;
434 257
435 // The reason the bridge is stopped. 258 // The reason the bridge is stopped.
436 StopReason stop_reason_; 259 StopReason stop_reason_;
437 260
438 // WeakPtrFactory to use callbacks. 261 // WeakPtrFactory to use callbacks.
439 base::WeakPtrFactory<ArcBridgeService> weak_factory_; 262 base::WeakPtrFactory<ArcBridgeService> weak_factory_;
440 263
441 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); 264 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService);
442 }; 265 };
443 266
444 } // namespace arc 267 } // namespace arc
445 268
446 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ 269 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_
OLDNEW
« no previous file with comments | « components/arc/BUILD.gn ('k') | components/arc/arc_bridge_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698