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