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_IMPL_H_ | 5 #ifndef COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_ |
6 #define COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_ | 6 #define COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | |
10 #include <vector> | |
11 | 9 |
12 #include "base/files/scoped_file.h" | 10 #include "base/callback.h" |
13 #include "base/macros.h" | 11 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | |
15 #include "base/task_runner.h" | |
16 #include "base/time/time.h" | 12 #include "base/time/time.h" |
17 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
18 #include "components/arc/arc_bridge_service.h" | 14 #include "components/arc/arc_bridge_service.h" |
19 #include "components/arc/arc_session_observer.h" | 15 #include "components/arc/arc_session_observer.h" |
20 #include "mojo/public/cpp/bindings/binding.h" | 16 |
| 17 template <typename T> |
| 18 class scoped_refptr; |
| 19 |
| 20 namespace base { |
| 21 class TaskRunner; |
| 22 } // namespace base |
21 | 23 |
22 namespace arc { | 24 namespace arc { |
23 | 25 |
24 class ArcSession; | 26 class ArcSession; |
25 | 27 |
26 // Real IPC based ArcBridgeService that is used in production. | 28 // Real IPC based ArcBridgeService that is used in production. |
27 class ArcBridgeServiceImpl : public ArcBridgeService, | 29 class ArcBridgeServiceImpl : public ArcBridgeService, |
28 public ArcSessionObserver { | 30 public ArcSessionObserver { |
29 public: | 31 public: |
30 // This is the factory interface to inject ArcSession instance | 32 // This is the factory interface to inject ArcSession instance |
(...skipping 15 matching lines...) Expand all Loading... |
46 | 48 |
47 // Returns the current ArcSession instance for testing purpose. | 49 // Returns the current ArcSession instance for testing purpose. |
48 ArcSession* GetArcSessionForTesting() { return arc_session_.get(); } | 50 ArcSession* GetArcSessionForTesting() { return arc_session_.get(); } |
49 | 51 |
50 // Normally, automatic restarting happens after a short delay. When testing, | 52 // Normally, automatic restarting happens after a short delay. When testing, |
51 // however, we'd like it to happen immediately to avoid adding unnecessary | 53 // however, we'd like it to happen immediately to avoid adding unnecessary |
52 // delays. | 54 // delays. |
53 void SetRestartDelayForTesting(const base::TimeDelta& restart_delay); | 55 void SetRestartDelayForTesting(const base::TimeDelta& restart_delay); |
54 | 56 |
55 private: | 57 private: |
56 // If all pre-requisites are true (ARC is available, it has been enabled, and | |
57 // the session has started), and ARC is stopped, start ARC. If ARC is running | |
58 // and the pre-requisites stop being true, stop ARC. | |
59 void PrerequisitesChanged(); | |
60 | |
61 // Starts to run an ARC instance. | 58 // Starts to run an ARC instance. |
62 void StartArcSession(); | 59 void StartArcSession(); |
63 | 60 |
64 // Stops the running instance. | 61 // Stops the running instance. |
65 void StopInstance(); | 62 void StopInstance(); |
66 | 63 |
67 // ArcSessionObserver: | 64 // ArcSessionObserver: |
68 void OnSessionReady() override; | 65 void OnSessionReady() override; |
69 void OnSessionStopped(StopReason reason) override; | 66 void OnSessionStopped(StopReason reason) override; |
70 | 67 |
71 std::unique_ptr<ArcSession> arc_session_; | 68 // Whether a client requests to run session or not. |
72 | 69 bool run_requested_ = false; |
73 // If the user's session has started. | |
74 bool session_started_; | |
75 | 70 |
76 // Instead of immediately trying to restart the container, give it some time | 71 // Instead of immediately trying to restart the container, give it some time |
77 // to finish tearing down in case it is still in the process of stopping. | 72 // to finish tearing down in case it is still in the process of stopping. |
78 base::TimeDelta restart_delay_; | 73 base::TimeDelta restart_delay_; |
79 base::OneShotTimer restart_timer_; | 74 base::OneShotTimer restart_timer_; |
80 | 75 |
81 // Factory to inject a fake ArcSession instance for testing. | 76 // Factory to inject a fake ArcSession instance for testing. |
82 ArcSessionFactory factory_; | 77 ArcSessionFactory factory_; |
83 | 78 |
| 79 // ArcSession object for currently running ARC instance. This should be |
| 80 // nullptr if the state is STOPPED, otherwise non-nullptr. |
| 81 std::unique_ptr<ArcSession> arc_session_; |
| 82 |
84 // WeakPtrFactory to use callbacks. | 83 // WeakPtrFactory to use callbacks. |
85 base::WeakPtrFactory<ArcBridgeServiceImpl> weak_factory_; | 84 base::WeakPtrFactory<ArcBridgeServiceImpl> weak_ptr_factory_; |
86 | 85 |
87 DISALLOW_COPY_AND_ASSIGN(ArcBridgeServiceImpl); | 86 DISALLOW_COPY_AND_ASSIGN(ArcBridgeServiceImpl); |
88 }; | 87 }; |
89 | 88 |
90 } // namespace arc | 89 } // namespace arc |
91 | 90 |
92 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_ | 91 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_ |
OLD | NEW |