| 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_BOOTSTRAP_H_ | 5 #ifndef COMPONENTS_ARC_ARC_SESSION_H_ |
| 6 #define COMPONENTS_ARC_ARC_BRIDGE_BOOTSTRAP_H_ | 6 #define COMPONENTS_ARC_ARC_SESSION_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 12 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "components/arc/arc_bridge_service.h" | 14 #include "components/arc/arc_bridge_service.h" |
| 15 | 15 |
| 16 namespace arc { | 16 namespace arc { |
| 17 | 17 |
| 18 // Starts the ARC instance and bootstraps the bridge connection. | 18 // Starts the ARC instance and bootstraps the bridge connection. |
| 19 // Clients should implement the Delegate to be notified upon communications | 19 // Clients should implement the Delegate to be notified upon communications |
| 20 // being available. | 20 // being available. |
| 21 // The instance can be safely removed 1) before Start() is called, or 2) after | 21 // The instance can be safely removed 1) before Start() is called, or 2) after |
| 22 // OnStopped() is called. | 22 // OnStopped() is called. |
| 23 // The number of instances must be at most one. Otherwise, ARC instances will | 23 // The number of instances must be at most one. Otherwise, ARC instances will |
| 24 // conflict. | 24 // conflict. |
| 25 // TODO(hidehiko): This class manages more than "bootstrap" procedure now. | 25 class ArcSession { |
| 26 // Rename this to ArcSession. | |
| 27 class ArcBridgeBootstrap { | |
| 28 public: | 26 public: |
| 29 class Observer { | 27 class Observer { |
| 30 public: | 28 public: |
| 31 Observer() = default; | 29 Observer() = default; |
| 32 virtual ~Observer() = default; | 30 virtual ~Observer() = default; |
| 33 | 31 |
| 34 // Called when the connection with ARC instance has been established. | 32 // Called when the connection with ARC instance has been established. |
| 35 virtual void OnReady() = 0; | 33 virtual void OnReady() = 0; |
| 36 | 34 |
| 37 // Called when ARC instance is stopped. This is called exactly once | 35 // Called when ARC instance is stopped. This is called exactly once |
| 38 // per instance which is Start()ed. | 36 // per instance which is Start()ed. |
| 39 virtual void OnStopped(ArcBridgeService::StopReason reason) = 0; | 37 virtual void OnStopped(ArcBridgeService::StopReason reason) = 0; |
| 40 | 38 |
| 41 private: | 39 private: |
| 42 DISALLOW_COPY_AND_ASSIGN(Observer); | 40 DISALLOW_COPY_AND_ASSIGN(Observer); |
| 43 }; | 41 }; |
| 44 | 42 |
| 45 // Creates a default instance of ArcBridgeBootstrap. | 43 // Creates a default instance of ArcSession. |
| 46 static std::unique_ptr<ArcBridgeBootstrap> Create(); | 44 static std::unique_ptr<ArcSession> Create(); |
| 47 virtual ~ArcBridgeBootstrap(); | 45 virtual ~ArcSession(); |
| 48 | 46 |
| 49 // Starts and bootstraps a connection with the instance. The Delegate's | 47 // Starts and bootstraps a connection with the instance. The Observer's |
| 50 // OnConnectionEstablished() will be called if the bootstrapping is | 48 // OnReady() will be called if the bootstrapping is successful, or |
| 51 // successful, or OnStopped() if it is not. | 49 // OnStopped() if it is not. Start() should not be called twice or more. |
| 52 // Start() should not be called twice or more. | |
| 53 virtual void Start() = 0; | 50 virtual void Start() = 0; |
| 54 | 51 |
| 55 // Requests to stop the currently-running instance. | 52 // Requests to stop the currently-running instance. |
| 56 // The completion is notified via OnStopped() of the Delegate. | 53 // The completion is notified via OnStopped() of the Delegate. |
| 57 virtual void Stop() = 0; | 54 virtual void Stop() = 0; |
| 58 | 55 |
| 59 void AddObserver(Observer* observer); | 56 void AddObserver(Observer* observer); |
| 60 void RemoveObserver(Observer* observer); | 57 void RemoveObserver(Observer* observer); |
| 61 | 58 |
| 62 protected: | 59 protected: |
| 63 ArcBridgeBootstrap(); | 60 ArcSession(); |
| 64 | 61 |
| 65 base::ObserverList<Observer> observer_list_; | 62 base::ObserverList<Observer> observer_list_; |
| 66 | 63 |
| 67 private: | 64 private: |
| 68 DISALLOW_COPY_AND_ASSIGN(ArcBridgeBootstrap); | 65 DISALLOW_COPY_AND_ASSIGN(ArcSession); |
| 69 }; | 66 }; |
| 70 | 67 |
| 71 } // namespace arc | 68 } // namespace arc |
| 72 | 69 |
| 73 #endif // COMPONENTS_ARC_ARC_BRIDGE_BOOTSTRAP_H_ | 70 #endif // COMPONENTS_ARC_ARC_SESSION_H_ |
| OLD | NEW |