OLD | NEW |
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 class ArcBridgeBootstrap; | 25 class ArcBridgeBootstrap; |
25 class ArcBridgeTest; | 26 class ArcBridgeTest; |
26 | 27 |
27 // 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. |
28 // 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 |
29 // communication channel (the ARC bridge) used to send and receive messages. | 30 // communication channel (the ARC bridge) used to send and receive messages. |
30 class ArcBridgeService : public mojom::ArcBridgeHost { | 31 class ArcBridgeService : public mojom::ArcBridgeHost { |
31 public: | 32 public: |
32 // Notifies life cycle events of ArcBridgeService. | 33 // Notifies life cycle events of ArcBridgeService. |
33 class Observer { | 34 class Observer { |
34 public: | 35 public: |
35 // Called whenever the state of the bridge has changed. | 36 // Called whenever the state of the bridge has changed. |
36 virtual void OnBridgeReady() {} | 37 virtual void OnBridgeReady() {} |
37 virtual void OnBridgeStopped() {} | 38 virtual void OnBridgeStopped() {} |
38 | 39 |
39 // Called whenever ARC's availability has changed for this system. | 40 // Called whenever ARC's availability has changed for this system. |
40 virtual void OnAvailableChanged(bool available) {} | 41 virtual void OnAvailableChanged(bool available) {} |
41 | 42 |
42 // Called whenever the ARC app interface state changes. | |
43 virtual void OnAppInstanceReady() {} | |
44 virtual void OnAppInstanceClosed() {} | |
45 | |
46 // Called whenever the ARC audio interface state changes. | |
47 virtual void OnAudioInstanceReady() {} | |
48 virtual void OnAudioInstanceClosed() {} | |
49 | |
50 // Called whenever the ARC auth interface state changes. | |
51 virtual void OnAuthInstanceReady() {} | |
52 virtual void OnAuthInstanceClosed() {} | |
53 | |
54 // Called whenever ARC Bluetooth instance is ready. | |
55 virtual void OnBluetoothInstanceReady() {} | |
56 virtual void OnBluetoothInstanceClosed() {} | |
57 | |
58 // Called whenever the ARC clipboard interface state changes. | |
59 virtual void OnClipboardInstanceReady() {} | |
60 virtual void OnClipboardInstanceClosed() {} | |
61 | |
62 // Called whenever the ARC crash collector interface state changes. | |
63 virtual void OnCrashCollectorInstanceReady() {} | |
64 virtual void OnCrashCollectorInstanceClosed() {} | |
65 | |
66 // Called whenever the ARC file system interface state changes. | |
67 virtual void OnFileSystemInstanceReady() {} | |
68 virtual void OnFileSystemInstanceClosed() {} | |
69 | |
70 // Called whenever the ARC IME interface state changes. | |
71 virtual void OnImeInstanceReady() {} | |
72 virtual void OnImeInstanceClosed() {} | |
73 | |
74 // Called whenever the ARC intent helper interface state changes. | |
75 virtual void OnIntentHelperInstanceReady() {} | |
76 virtual void OnIntentHelperInstanceClosed() {} | |
77 | |
78 // Called whenever the ARC metrics interface state changes. | |
79 virtual void OnMetricsInstanceReady() {} | |
80 virtual void OnMetricsInstanceClosed() {} | |
81 | |
82 // Called whenever the ARC notification interface state changes. | |
83 virtual void OnNotificationsInstanceReady() {} | |
84 virtual void OnNotificationsInstanceClosed() {} | |
85 | |
86 // Called whenever the ARC net interface state changes. | |
87 virtual void OnNetInstanceReady() {} | |
88 virtual void OnNetInstanceClosed() {} | |
89 | |
90 // Called whenever the ARC OBB mounter interface state changes. | |
91 virtual void OnObbMounterInstanceReady() {} | |
92 virtual void OnObbMounterInstanceClosed() {} | |
93 | |
94 // Called whenever the ARC policy interface state changes. | |
95 virtual void OnPolicyInstanceReady() {} | |
96 virtual void OnPolicyInstanceClosed() {} | |
97 | |
98 // Called whenever the ARC power interface state changes. | |
99 virtual void OnPowerInstanceReady() {} | |
100 virtual void OnPowerInstanceClosed() {} | |
101 | |
102 // Called whenever the ARC process interface state changes. | |
103 virtual void OnProcessInstanceReady() {} | |
104 virtual void OnProcessInstanceClosed() {} | |
105 | |
106 // Called whenever the ARC storage manager interface state changes. | |
107 virtual void OnStorageManagerInstanceReady() {} | |
108 virtual void OnStorageManagerInstanceClosed() {} | |
109 | |
110 // Called whenever the ARC video interface state changes. | |
111 virtual void OnVideoInstanceReady() {} | |
112 virtual void OnVideoInstanceClosed() {} | |
113 | |
114 // Called whenever the ARC window manager interface state changes. | |
115 virtual void OnWindowManagerInstanceReady() {} | |
116 virtual void OnWindowManagerInstanceClosed() {} | |
117 | |
118 protected: | 43 protected: |
119 virtual ~Observer() {} | 44 virtual ~Observer() {} |
120 }; | 45 }; |
121 | 46 |
122 ~ArcBridgeService() override; | 47 ~ArcBridgeService() override; |
123 | 48 |
124 // 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 |
125 // called on the thread that this class was created on. | 50 // called on the thread that this class was created on. |
126 static ArcBridgeService* Get(); | 51 static ArcBridgeService* Get(); |
127 | 52 |
(...skipping 14 matching lines...) Expand all Loading... |
142 // Shutdown() should be called when the browser is shutting down. This can | 67 // Shutdown() should be called when the browser is shutting down. This can |
143 // only be called on the thread that this class was created on. | 68 // only be called on the thread that this class was created on. |
144 virtual void Shutdown() = 0; | 69 virtual void Shutdown() = 0; |
145 | 70 |
146 // Adds or removes observers. This can only be called on the thread that this | 71 // Adds or removes observers. This can only be called on the thread that this |
147 // class was created on. RemoveObserver does nothing if |observer| is not in | 72 // class was created on. RemoveObserver does nothing if |observer| is not in |
148 // the list. | 73 // the list. |
149 void AddObserver(Observer* observer); | 74 void AddObserver(Observer* observer); |
150 void RemoveObserver(Observer* observer); | 75 void RemoveObserver(Observer* observer); |
151 | 76 |
152 // Gets the Mojo interface for all the instance services. This will return | 77 InstanceHolder<mojom::AppInstance>* app() { return &app_; } |
153 // nullptr if that particular service is not ready yet. Use an Observer if | 78 InstanceHolder<mojom::AudioInstance>* audio() { return &audio_; } |
154 // you want to be notified when this is ready. This can only be called on the | 79 InstanceHolder<mojom::AuthInstance>* auth() { return &auth_; } |
155 // thread that this class was created on. | 80 InstanceHolder<mojom::BluetoothInstance>* bluetooth() { return &bluetooth_; } |
156 mojom::AppInstance* app_instance() { return app_ptr_.get(); } | 81 InstanceHolder<mojom::ClipboardInstance>* clipboard() { return &clipboard_; } |
157 mojom::AudioInstance* audio_instance() { return audio_ptr_.get(); } | 82 InstanceHolder<mojom::CrashCollectorInstance>* crash_collector() { |
158 mojom::AuthInstance* auth_instance() { return auth_ptr_.get(); } | 83 return &crash_collector_; |
159 mojom::BluetoothInstance* bluetooth_instance() { | |
160 return bluetooth_ptr_.get(); | |
161 } | 84 } |
162 mojom::ClipboardInstance* clipboard_instance() { | 85 InstanceHolder<mojom::FileSystemInstance>* file_system() { |
163 return clipboard_ptr_.get(); | 86 return &file_system_; |
164 } | 87 } |
165 mojom::CrashCollectorInstance* crash_collector_instance() { | 88 InstanceHolder<mojom::ImeInstance>* ime() { return &ime_; } |
166 return crash_collector_ptr_.get(); | 89 InstanceHolder<mojom::IntentHelperInstance>* intent_helper() { |
| 90 return &intent_helper_; |
167 } | 91 } |
168 mojom::FileSystemInstance* file_system_instance() { | 92 InstanceHolder<mojom::MetricsInstance>* metrics() { return &metrics_; } |
169 return file_system_ptr_.get(); | 93 InstanceHolder<mojom::NetInstance>* net() { return &net_; } |
| 94 InstanceHolder<mojom::NotificationsInstance>* notifications() { |
| 95 return ¬ifications_; |
170 } | 96 } |
171 mojom::ImeInstance* ime_instance() { return ime_ptr_.get(); } | 97 InstanceHolder<mojom::ObbMounterInstance>* obb_mounter() { |
172 mojom::IntentHelperInstance* intent_helper_instance() { | 98 return &obb_mounter_; |
173 return intent_helper_ptr_.get(); | |
174 } | 99 } |
175 mojom::MetricsInstance* metrics_instance() { return metrics_ptr_.get(); } | 100 InstanceHolder<mojom::PolicyInstance>* policy() { return &policy_; } |
176 mojom::NetInstance* net_instance() { return net_ptr_.get(); } | 101 InstanceHolder<mojom::PowerInstance>* power() { return &power_; } |
177 mojom::NotificationsInstance* notifications_instance() { | 102 InstanceHolder<mojom::ProcessInstance>* process() { return &process_; } |
178 return notifications_ptr_.get(); | 103 InstanceHolder<mojom::StorageManagerInstance>* storage_manager() { |
| 104 return &storage_manager_; |
179 } | 105 } |
180 mojom::ObbMounterInstance* obb_mounter_instance() { | 106 InstanceHolder<mojom::VideoInstance>* video() { return &video_; } |
181 return obb_mounter_ptr_.get(); | 107 InstanceHolder<mojom::WindowManagerInstance>* window_manager() { |
182 } | 108 return &window_manager_; |
183 mojom::PolicyInstance* policy_instance() { return policy_ptr_.get(); } | |
184 mojom::PowerInstance* power_instance() { return power_ptr_.get(); } | |
185 mojom::ProcessInstance* process_instance() { return process_ptr_.get(); } | |
186 mojom::StorageManagerInstance* storage_manager_instance() { | |
187 return storage_manager_ptr_.get(); | |
188 } | |
189 mojom::VideoInstance* video_instance() { return video_ptr_.get(); } | |
190 mojom::WindowManagerInstance* window_manager_instance() { | |
191 return window_manager_ptr_.get(); | |
192 } | |
193 | |
194 int32_t app_version() const { return app_ptr_.version(); } | |
195 int32_t audio_version() const { return audio_ptr_.version(); } | |
196 int32_t bluetooth_version() const { return bluetooth_ptr_.version(); } | |
197 int32_t auth_version() const { return auth_ptr_.version(); } | |
198 int32_t clipboard_version() const { return clipboard_ptr_.version(); } | |
199 int32_t crash_collector_version() const { | |
200 return crash_collector_ptr_.version(); | |
201 } | |
202 int32_t file_system_version() const { return file_system_ptr_.version(); } | |
203 int32_t ime_version() const { return ime_ptr_.version(); } | |
204 int32_t intent_helper_version() const { return intent_helper_ptr_.version(); } | |
205 int32_t metrics_version() const { return metrics_ptr_.version(); } | |
206 int32_t net_version() const { return net_ptr_.version(); } | |
207 int32_t notifications_version() const { return notifications_ptr_.version(); } | |
208 int32_t obb_mounter_version() const { return obb_mounter_ptr_.version(); } | |
209 int32_t policy_version() const { return policy_ptr_.version(); } | |
210 int32_t power_version() const { return power_ptr_.version(); } | |
211 int32_t process_version() const { return process_ptr_.version(); } | |
212 int32_t storage_manager_version() const { | |
213 return storage_manager_ptr_.version(); | |
214 } | |
215 int32_t video_version() const { return video_ptr_.version(); } | |
216 int32_t window_manager_version() const { | |
217 return window_manager_ptr_.version(); | |
218 } | 109 } |
219 | 110 |
220 // ArcHost: | 111 // ArcHost: |
221 void OnAppInstanceReady(mojom::AppInstancePtr app_ptr) override; | 112 void OnAppInstanceReady(mojom::AppInstancePtr app_ptr) override; |
222 void OnAudioInstanceReady(mojom::AudioInstancePtr audio_ptr) override; | 113 void OnAudioInstanceReady(mojom::AudioInstancePtr audio_ptr) override; |
223 void OnAuthInstanceReady(mojom::AuthInstancePtr auth_ptr) override; | 114 void OnAuthInstanceReady(mojom::AuthInstancePtr auth_ptr) override; |
224 void OnBluetoothInstanceReady( | 115 void OnBluetoothInstanceReady( |
225 mojom::BluetoothInstancePtr bluetooth_ptr) override; | 116 mojom::BluetoothInstancePtr bluetooth_ptr) override; |
226 void OnClipboardInstanceReady( | 117 void OnClipboardInstanceReady( |
227 mojom::ClipboardInstancePtr clipboard_ptr) override; | 118 mojom::ClipboardInstancePtr clipboard_ptr) override; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 // Closes all Mojo channels. | 202 // Closes all Mojo channels. |
312 void CloseAllChannels(); | 203 void CloseAllChannels(); |
313 | 204 |
314 private: | 205 private: |
315 friend class ArcBridgeTest; | 206 friend class ArcBridgeTest; |
316 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); | 207 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); |
317 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites); | 208 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites); |
318 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup); | 209 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup); |
319 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart); | 210 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart); |
320 | 211 |
321 // Called when one of the individual channels is closed. | 212 // Instance holders. |
322 void CloseAppChannel(); | 213 InstanceHolder<mojom::AppInstance> app_; |
323 void CloseAudioChannel(); | 214 InstanceHolder<mojom::AudioInstance> audio_; |
324 void CloseAuthChannel(); | 215 InstanceHolder<mojom::AuthInstance> auth_; |
325 void CloseBluetoothChannel(); | 216 InstanceHolder<mojom::BluetoothInstance> bluetooth_; |
326 void CloseClipboardChannel(); | 217 InstanceHolder<mojom::ClipboardInstance> clipboard_; |
327 void CloseCrashCollectorChannel(); | 218 InstanceHolder<mojom::CrashCollectorInstance> crash_collector_; |
328 void CloseFileSystemChannel(); | 219 InstanceHolder<mojom::FileSystemInstance> file_system_; |
329 void CloseImeChannel(); | 220 InstanceHolder<mojom::ImeInstance> ime_; |
330 void CloseIntentHelperChannel(); | 221 InstanceHolder<mojom::IntentHelperInstance> intent_helper_; |
331 void CloseMetricsChannel(); | 222 InstanceHolder<mojom::MetricsInstance> metrics_; |
332 void CloseNetChannel(); | 223 InstanceHolder<mojom::NetInstance> net_; |
333 void CloseNotificationsChannel(); | 224 InstanceHolder<mojom::NotificationsInstance> notifications_; |
334 void CloseObbMounterChannel(); | 225 InstanceHolder<mojom::ObbMounterInstance> obb_mounter_; |
335 void ClosePolicyChannel(); | 226 InstanceHolder<mojom::PolicyInstance> policy_; |
336 void ClosePowerChannel(); | 227 InstanceHolder<mojom::PowerInstance> power_; |
337 void CloseProcessChannel(); | 228 InstanceHolder<mojom::ProcessInstance> process_; |
338 void CloseStorageManagerChannel(); | 229 InstanceHolder<mojom::StorageManagerInstance> storage_manager_; |
339 void CloseVideoChannel(); | 230 InstanceHolder<mojom::VideoInstance> video_; |
340 void CloseWindowManagerChannel(); | 231 InstanceHolder<mojom::WindowManagerInstance> window_manager_; |
341 | |
342 // Callbacks for QueryVersion. | |
343 void OnAppVersionReady(uint32_t version); | |
344 void OnAudioVersionReady(uint32_t version); | |
345 void OnAuthVersionReady(uint32_t version); | |
346 void OnBluetoothVersionReady(uint32_t version); | |
347 void OnClipboardVersionReady(uint32_t version); | |
348 void OnCrashCollectorVersionReady(uint32_t version); | |
349 void OnFileSystemVersionReady(uint32_t version); | |
350 void OnImeVersionReady(uint32_t version); | |
351 void OnIntentHelperVersionReady(uint32_t version); | |
352 void OnMetricsVersionReady(uint32_t version); | |
353 void OnNetVersionReady(uint32_t version); | |
354 void OnNotificationsVersionReady(uint32_t version); | |
355 void OnObbMounterVersionReady(uint32_t version); | |
356 void OnPolicyVersionReady(uint32_t version); | |
357 void OnPowerVersionReady(uint32_t version); | |
358 void OnProcessVersionReady(uint32_t version); | |
359 void OnStorageManagerVersionReady(uint32_t version); | |
360 void OnVideoVersionReady(uint32_t version); | |
361 void OnWindowManagerVersionReady(uint32_t version); | |
362 | |
363 // Mojo interfaces. | |
364 mojom::AppInstancePtr app_ptr_; | |
365 mojom::AudioInstancePtr audio_ptr_; | |
366 mojom::AuthInstancePtr auth_ptr_; | |
367 mojom::BluetoothInstancePtr bluetooth_ptr_; | |
368 mojom::ClipboardInstancePtr clipboard_ptr_; | |
369 mojom::CrashCollectorInstancePtr crash_collector_ptr_; | |
370 mojom::FileSystemInstancePtr file_system_ptr_; | |
371 mojom::ImeInstancePtr ime_ptr_; | |
372 mojom::IntentHelperInstancePtr intent_helper_ptr_; | |
373 mojom::MetricsInstancePtr metrics_ptr_; | |
374 mojom::NetInstancePtr net_ptr_; | |
375 mojom::NotificationsInstancePtr notifications_ptr_; | |
376 mojom::ObbMounterInstancePtr obb_mounter_ptr_; | |
377 mojom::PolicyInstancePtr policy_ptr_; | |
378 mojom::PowerInstancePtr power_ptr_; | |
379 mojom::ProcessInstancePtr process_ptr_; | |
380 mojom::StorageManagerInstancePtr storage_manager_ptr_; | |
381 mojom::VideoInstancePtr video_ptr_; | |
382 mojom::WindowManagerInstancePtr window_manager_ptr_; | |
383 | |
384 // Temporary Mojo interfaces. After a Mojo interface pointer has been | |
385 // received from the other endpoint, we still need to asynchronously query | |
386 // its version. While that is going on, we should still return nullptr on | |
387 // the xxx_instance() functions. | |
388 // To keep the xxx_instance() functions being trivial, store the instance | |
389 // pointer in a temporary variable to avoid losing its reference. | |
390 mojom::AppInstancePtr temporary_app_ptr_; | |
391 mojom::AudioInstancePtr temporary_audio_ptr_; | |
392 mojom::AuthInstancePtr temporary_auth_ptr_; | |
393 mojom::BluetoothInstancePtr temporary_bluetooth_ptr_; | |
394 mojom::ClipboardInstancePtr temporary_clipboard_ptr_; | |
395 mojom::CrashCollectorInstancePtr temporary_crash_collector_ptr_; | |
396 mojom::FileSystemInstancePtr temporary_file_system_ptr_; | |
397 mojom::ImeInstancePtr temporary_ime_ptr_; | |
398 mojom::IntentHelperInstancePtr temporary_intent_helper_ptr_; | |
399 mojom::MetricsInstancePtr temporary_metrics_ptr_; | |
400 mojom::NetInstancePtr temporary_net_ptr_; | |
401 mojom::NotificationsInstancePtr temporary_notifications_ptr_; | |
402 mojom::ObbMounterInstancePtr temporary_obb_mounter_ptr_; | |
403 mojom::PolicyInstancePtr temporary_policy_ptr_; | |
404 mojom::PowerInstancePtr temporary_power_ptr_; | |
405 mojom::ProcessInstancePtr temporary_process_ptr_; | |
406 mojom::StorageManagerInstancePtr temporary_storage_manager_ptr_; | |
407 mojom::VideoInstancePtr temporary_video_ptr_; | |
408 mojom::WindowManagerInstancePtr temporary_window_manager_ptr_; | |
409 | 232 |
410 base::ObserverList<Observer> observer_list_; | 233 base::ObserverList<Observer> observer_list_; |
411 | 234 |
412 base::ThreadChecker thread_checker_; | 235 base::ThreadChecker thread_checker_; |
413 | 236 |
414 // If the ARC instance service is available. | 237 // If the ARC instance service is available. |
415 bool available_; | 238 bool available_; |
416 | 239 |
417 // The current state of the bridge. | 240 // The current state of the bridge. |
418 ArcBridgeService::State state_; | 241 ArcBridgeService::State state_; |
419 | 242 |
420 // WeakPtrFactory to use callbacks. | 243 // WeakPtrFactory to use callbacks. |
421 base::WeakPtrFactory<ArcBridgeService> weak_factory_; | 244 base::WeakPtrFactory<ArcBridgeService> weak_factory_; |
422 | 245 |
423 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); | 246 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); |
424 }; | 247 }; |
425 | 248 |
426 } // namespace arc | 249 } // namespace arc |
427 | 250 |
428 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ | 251 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ |
OLD | NEW |