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_BRIDGE_BOOTSTRAP_H_ |
6 #define COMPONENTS_ARC_ARC_BRIDGE_BOOTSTRAP_H_ | 6 #define COMPONENTS_ARC_ARC_BRIDGE_BOOTSTRAP_H_ |
7 | 7 |
| 8 #include <memory> |
| 9 |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
11 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
12 #include "components/arc/common/arc_bridge.mojom.h" | 13 #include "components/arc/common/arc_bridge.mojom.h" |
13 | 14 |
14 namespace arc { | 15 namespace arc { |
15 | 16 |
16 // Starts the ARC instance and bootstraps the bridge connection. | 17 // Starts the ARC instance and bootstraps the bridge connection. |
17 // Clients should implement the Delegate to be notified upon communications | 18 // Clients should implement the Delegate to be notified upon communications |
18 // being available. | 19 // being available. |
19 class ArcBridgeBootstrap { | 20 class ArcBridgeBootstrap { |
20 public: | 21 public: |
21 class Delegate { | 22 class Delegate { |
22 public: | 23 public: |
23 virtual void OnConnectionEstablished( | 24 virtual void OnConnectionEstablished( |
24 mojom::ArcBridgeInstancePtr instance_ptr) = 0; | 25 mojom::ArcBridgeInstancePtr instance_ptr) = 0; |
25 virtual void OnStopped() = 0; | 26 virtual void OnStopped() = 0; |
26 }; | 27 }; |
27 | 28 |
28 // Creates a default instance of ArcBridgeBootstrap. | 29 // Creates a default instance of ArcBridgeBootstrap. |
29 static scoped_ptr<ArcBridgeBootstrap> Create(); | 30 static std::unique_ptr<ArcBridgeBootstrap> Create(); |
30 virtual ~ArcBridgeBootstrap(); | 31 virtual ~ArcBridgeBootstrap(); |
31 | 32 |
32 // This must be called before calling Start() or Stop(). |delegate| is owned | 33 // This must be called before calling Start() or Stop(). |delegate| is owned |
33 // by the caller and must outlive this instance. | 34 // by the caller and must outlive this instance. |
34 void set_delegate(Delegate* delegate) { delegate_ = delegate; } | 35 void set_delegate(Delegate* delegate) { delegate_ = delegate; } |
35 | 36 |
36 // Starts and bootstraps a connection with the instance. The Delegate's | 37 // Starts and bootstraps a connection with the instance. The Delegate's |
37 // OnConnectionEstablished() will be called if the bootstrapping is | 38 // OnConnectionEstablished() will be called if the bootstrapping is |
38 // successful, or OnStopped() if it is not. | 39 // successful, or OnStopped() if it is not. |
39 virtual void Start() = 0; | 40 virtual void Start() = 0; |
40 | 41 |
41 // Stops the currently-running instance. | 42 // Stops the currently-running instance. |
42 virtual void Stop() = 0; | 43 virtual void Stop() = 0; |
43 | 44 |
44 protected: | 45 protected: |
45 ArcBridgeBootstrap(); | 46 ArcBridgeBootstrap(); |
46 | 47 |
47 // Owned by the caller. | 48 // Owned by the caller. |
48 Delegate* delegate_ = nullptr; | 49 Delegate* delegate_ = nullptr; |
49 | 50 |
50 private: | 51 private: |
51 DISALLOW_COPY_AND_ASSIGN(ArcBridgeBootstrap); | 52 DISALLOW_COPY_AND_ASSIGN(ArcBridgeBootstrap); |
52 }; | 53 }; |
53 | 54 |
54 } // namespace arc | 55 } // namespace arc |
55 | 56 |
56 #endif // COMPONENTS_ARC_ARC_BRIDGE_BOOTSTRAP_H_ | 57 #endif // COMPONENTS_ARC_ARC_BRIDGE_BOOTSTRAP_H_ |
OLD | NEW |