Chromium Code Reviews| 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 // No error. | |
| 67 NO_ERROR, | |
|
Luis Héctor Chávez
2016/07/11 22:28:50
nit: I'd rename this to SHUTDOWN (and the descript
Shuhei Takahashi
2016/07/12 06:13:57
Sure, done.
| |
| 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, BootFailure); | |
| 336 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Crash); | |
| 314 | 337 |
| 315 // Called when one of the individual channels is closed. | 338 // Called when one of the individual channels is closed. |
| 316 void CloseAppChannel(); | 339 void CloseAppChannel(); |
| 317 void CloseAudioChannel(); | 340 void CloseAudioChannel(); |
| 318 void CloseAuthChannel(); | 341 void CloseAuthChannel(); |
| 319 void CloseBluetoothChannel(); | 342 void CloseBluetoothChannel(); |
| 320 void CloseClipboardChannel(); | 343 void CloseClipboardChannel(); |
| 321 void CloseCrashCollectorChannel(); | 344 void CloseCrashCollectorChannel(); |
| 322 void CloseFileSystemChannel(); | 345 void CloseFileSystemChannel(); |
| 323 void CloseImeChannel(); | 346 void CloseImeChannel(); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 base::ObserverList<Observer> observer_list_; | 427 base::ObserverList<Observer> observer_list_; |
| 405 | 428 |
| 406 base::ThreadChecker thread_checker_; | 429 base::ThreadChecker thread_checker_; |
| 407 | 430 |
| 408 // If the ARC instance service is available. | 431 // If the ARC instance service is available. |
| 409 bool available_; | 432 bool available_; |
| 410 | 433 |
| 411 // The current state of the bridge. | 434 // The current state of the bridge. |
| 412 ArcBridgeService::State state_; | 435 ArcBridgeService::State state_; |
| 413 | 436 |
| 437 // The reason the bridge is stopped. | |
| 438 StopReason stop_reason_; | |
| 439 | |
| 414 // WeakPtrFactory to use callbacks. | 440 // WeakPtrFactory to use callbacks. |
| 415 base::WeakPtrFactory<ArcBridgeService> weak_factory_; | 441 base::WeakPtrFactory<ArcBridgeService> weak_factory_; |
| 416 | 442 |
| 417 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); | 443 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); |
| 418 }; | 444 }; |
| 419 | 445 |
| 420 } // namespace arc | 446 } // namespace arc |
| 421 | 447 |
| 422 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ | 448 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ |
| OLD | NEW |