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 | 17 |
18 namespace base { | 18 namespace base { |
19 class CommandLine; | 19 class CommandLine; |
20 } // namespace base | 20 } // namespace base |
21 | 21 |
22 namespace arc { | 22 namespace arc { |
23 | 23 |
24 class ArcBridgeBootstrap; | |
25 | |
26 // The Chrome-side service that handles ARC instances and ARC bridge creation. | 24 // The Chrome-side service that handles ARC instances and ARC bridge creation. |
27 // This service handles the lifetime of ARC instances and sets up the | 25 // This service handles the lifetime of ARC instances and sets up the |
28 // communication channel (the ARC bridge) used to send and receive messages. | 26 // communication channel (the ARC bridge) used to send and receive messages. |
29 class ArcBridgeService : public mojom::ArcBridgeHost { | 27 class ArcBridgeService : public mojom::ArcBridgeHost { |
30 public: | 28 public: |
31 // The possible states of the bridge. In the normal flow, the state changes | 29 // The possible states of the bridge. In the normal flow, the state changes |
32 // in the following sequence: | 30 // in the following sequence: |
33 // | 31 // |
34 // STOPPED | 32 // STOPPED |
35 // PrerequisitesChanged() -> | 33 // PrerequisitesChanged() -> |
(...skipping 20 matching lines...) Expand all Loading... |
56 CONNECTED, | 54 CONNECTED, |
57 | 55 |
58 // The ARC instance has finished initializing and is now ready for user | 56 // The ARC instance has finished initializing and is now ready for user |
59 // interaction. | 57 // interaction. |
60 READY, | 58 READY, |
61 | 59 |
62 // The ARC instance has started shutting down. | 60 // The ARC instance has started shutting down. |
63 STOPPING, | 61 STOPPING, |
64 }; | 62 }; |
65 | 63 |
| 64 // Describes the reason the bridge is stopped. |
| 65 enum class StopReason { |
| 66 // ARC instance has been gracefully shut down. |
| 67 SHUTDOWN, |
| 68 |
| 69 // Errors occurred during the ARC instance boot. This includes any failures |
| 70 // before the instance is actually attempted to be started, and also |
| 71 // failures on bootstrapping IPC channels with Android. |
| 72 GENERIC_BOOT_FAILURE, |
| 73 |
| 74 // ARC instance has crashed. |
| 75 CRASH, |
| 76 }; |
| 77 |
66 // Notifies life cycle events of ArcBridgeService. | 78 // Notifies life cycle events of ArcBridgeService. |
67 class Observer { | 79 class Observer { |
68 public: | 80 public: |
69 // Called whenever the state of the bridge has changed. | 81 // Called whenever the state of the bridge has changed. |
70 // TODO(lchavez): Rename to OnStateChangedForTest | 82 // TODO(lchavez): Rename to OnStateChangedForTest |
71 virtual void OnStateChanged(State state) {} | 83 virtual void OnStateChanged(State state) {} |
| 84 |
| 85 // Called whenever the bridge is ready. |
72 virtual void OnBridgeReady() {} | 86 virtual void OnBridgeReady() {} |
73 virtual void OnBridgeStopped() {} | 87 |
| 88 // Called whenever the bridge is stopped. |
| 89 virtual void OnBridgeStopped(StopReason reason) {} |
74 | 90 |
75 // Called whenever ARC's availability has changed for this system. | 91 // Called whenever ARC's availability has changed for this system. |
76 virtual void OnAvailableChanged(bool available) {} | 92 virtual void OnAvailableChanged(bool available) {} |
77 | 93 |
78 // Called whenever the ARC app interface state changes. | 94 // Called whenever the ARC app interface state changes. |
79 virtual void OnAppInstanceReady() {} | 95 virtual void OnAppInstanceReady() {} |
80 virtual void OnAppInstanceClosed() {} | 96 virtual void OnAppInstanceClosed() {} |
81 | 97 |
82 // Called whenever the ARC audio interface state changes. | 98 // Called whenever the ARC audio interface state changes. |
83 virtual void OnAudioInstanceReady() {} | 99 virtual void OnAudioInstanceReady() {} |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 | 307 |
292 protected: | 308 protected: |
293 ArcBridgeService(); | 309 ArcBridgeService(); |
294 | 310 |
295 // Changes the current state and notifies all observers. | 311 // Changes the current state and notifies all observers. |
296 void SetState(State state); | 312 void SetState(State state); |
297 | 313 |
298 // Changes the current availability and notifies all observers. | 314 // Changes the current availability and notifies all observers. |
299 void SetAvailable(bool availability); | 315 void SetAvailable(bool availability); |
300 | 316 |
| 317 // Sets the reason the bridge is stopped. This function must be always called |
| 318 // before SetState(State::STOPPED) to report a correct reason with |
| 319 // Observer::OnBridgeStopped(). |
| 320 void SetStopReason(StopReason stop_reason); |
| 321 |
301 base::ObserverList<Observer>& observer_list() { return observer_list_; } | 322 base::ObserverList<Observer>& observer_list() { return observer_list_; } |
302 | 323 |
303 bool CalledOnValidThread(); | 324 bool CalledOnValidThread(); |
304 | 325 |
305 // Closes all Mojo channels. | 326 // Closes all Mojo channels. |
306 void CloseAllChannels(); | 327 void CloseAllChannels(); |
307 | 328 |
308 private: | 329 private: |
309 friend class ArcBridgeTest; | 330 friend class ArcBridgeTest; |
310 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); | 331 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); |
311 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites); | 332 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites); |
312 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup); | 333 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup); |
313 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart); | 334 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart); |
| 335 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, OnBridgeStopped); |
314 | 336 |
315 // Called when one of the individual channels is closed. | 337 // Called when one of the individual channels is closed. |
316 void CloseAppChannel(); | 338 void CloseAppChannel(); |
317 void CloseAudioChannel(); | 339 void CloseAudioChannel(); |
318 void CloseAuthChannel(); | 340 void CloseAuthChannel(); |
319 void CloseBluetoothChannel(); | 341 void CloseBluetoothChannel(); |
320 void CloseClipboardChannel(); | 342 void CloseClipboardChannel(); |
321 void CloseCrashCollectorChannel(); | 343 void CloseCrashCollectorChannel(); |
322 void CloseFileSystemChannel(); | 344 void CloseFileSystemChannel(); |
323 void CloseImeChannel(); | 345 void CloseImeChannel(); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 base::ObserverList<Observer> observer_list_; | 426 base::ObserverList<Observer> observer_list_; |
405 | 427 |
406 base::ThreadChecker thread_checker_; | 428 base::ThreadChecker thread_checker_; |
407 | 429 |
408 // If the ARC instance service is available. | 430 // If the ARC instance service is available. |
409 bool available_; | 431 bool available_; |
410 | 432 |
411 // The current state of the bridge. | 433 // The current state of the bridge. |
412 ArcBridgeService::State state_; | 434 ArcBridgeService::State state_; |
413 | 435 |
| 436 // The reason the bridge is stopped. |
| 437 StopReason stop_reason_; |
| 438 |
414 // WeakPtrFactory to use callbacks. | 439 // WeakPtrFactory to use callbacks. |
415 base::WeakPtrFactory<ArcBridgeService> weak_factory_; | 440 base::WeakPtrFactory<ArcBridgeService> weak_factory_; |
416 | 441 |
417 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); | 442 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); |
418 }; | 443 }; |
419 | 444 |
420 } // namespace arc | 445 } // namespace arc |
421 | 446 |
422 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ | 447 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ |
OLD | NEW |