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> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/files/scoped_file.h" | 12 #include "base/files/scoped_file.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/task_runner.h" | 15 #include "base/task_runner.h" |
| 16 #include "base/time/time.h" |
| 17 #include "base/timer/timer.h" |
16 #include "components/arc/arc_bridge_service.h" | 18 #include "components/arc/arc_bridge_service.h" |
17 #include "components/arc/arc_session_observer.h" | 19 #include "components/arc/arc_session_observer.h" |
18 #include "mojo/public/cpp/bindings/binding.h" | 20 #include "mojo/public/cpp/bindings/binding.h" |
19 | 21 |
20 namespace arc { | 22 namespace arc { |
21 | 23 |
22 class ArcSession; | 24 class ArcSession; |
23 | 25 |
24 // Real IPC based ArcBridgeService that is used in production. | 26 // Real IPC based ArcBridgeService that is used in production. |
25 class ArcBridgeServiceImpl : public ArcBridgeService, | 27 class ArcBridgeServiceImpl : public ArcBridgeService, |
(...skipping 12 matching lines...) Expand all Loading... |
38 void RequestStop() override; | 40 void RequestStop() override; |
39 void OnShutdown() override; | 41 void OnShutdown() override; |
40 | 42 |
41 // Inject a factory to create ArcSession instance for testing purpose. | 43 // Inject a factory to create ArcSession instance for testing purpose. |
42 // |factory| must not be null. | 44 // |factory| must not be null. |
43 void SetArcSessionFactoryForTesting(const ArcSessionFactory& factory); | 45 void SetArcSessionFactoryForTesting(const ArcSessionFactory& factory); |
44 | 46 |
45 // Returns the current ArcSession instance for testing purpose. | 47 // Returns the current ArcSession instance for testing purpose. |
46 ArcSession* GetArcSessionForTesting() { return arc_session_.get(); } | 48 ArcSession* GetArcSessionForTesting() { return arc_session_.get(); } |
47 | 49 |
48 // Normally, reconnecting after connection shutdown happens after a short | 50 // Normally, automatic restarting happens after a short delay. When testing, |
49 // delay. When testing, however, we'd like it to happen immediately to avoid | 51 // however, we'd like it to happen immediately to avoid adding unnecessary |
50 // adding unnecessary delays. | 52 // delays. |
51 void DisableReconnectDelayForTesting(); | 53 void SetRestartDelayForTesting(const base::TimeDelta& restart_delay); |
52 | 54 |
53 private: | 55 private: |
54 // If all pre-requisites are true (ARC is available, it has been enabled, and | 56 // If all pre-requisites are true (ARC is available, it has been enabled, and |
55 // the session has started), and ARC is stopped, start ARC. If ARC is running | 57 // the session has started), and ARC is stopped, start ARC. If ARC is running |
56 // and the pre-requisites stop being true, stop ARC. | 58 // and the pre-requisites stop being true, stop ARC. |
57 void PrerequisitesChanged(); | 59 void PrerequisitesChanged(); |
58 | 60 |
| 61 // Starts to run an ARC instance. |
| 62 void StartArcSession(); |
| 63 |
59 // Stops the running instance. | 64 // Stops the running instance. |
60 void StopInstance(); | 65 void StopInstance(); |
61 | 66 |
62 // ArcSessionObserver: | 67 // ArcSessionObserver: |
63 void OnSessionReady() override; | 68 void OnSessionReady() override; |
64 void OnSessionStopped(StopReason reason) override; | 69 void OnSessionStopped(StopReason reason) override; |
65 | 70 |
66 std::unique_ptr<ArcSession> arc_session_; | 71 std::unique_ptr<ArcSession> arc_session_; |
67 | 72 |
68 // If the user's session has started. | 73 // If the user's session has started. |
69 bool session_started_; | 74 bool session_started_; |
70 | 75 |
71 // If the instance had already been started but the connection to it was | 76 // Instead of immediately trying to restart the container, give it some time |
72 // lost. This should make the instance restart. | 77 // to finish tearing down in case it is still in the process of stopping. |
73 bool reconnect_ = false; | 78 base::TimeDelta restart_delay_; |
74 | 79 base::OneShotTimer restart_timer_; |
75 // Delay the reconnection. | |
76 bool use_delay_before_reconnecting_ = true; | |
77 | 80 |
78 // Factory to inject a fake ArcSession instance for testing. | 81 // Factory to inject a fake ArcSession instance for testing. |
79 ArcSessionFactory factory_; | 82 ArcSessionFactory factory_; |
80 | 83 |
81 // WeakPtrFactory to use callbacks. | 84 // WeakPtrFactory to use callbacks. |
82 base::WeakPtrFactory<ArcBridgeServiceImpl> weak_factory_; | 85 base::WeakPtrFactory<ArcBridgeServiceImpl> weak_factory_; |
83 | 86 |
84 DISALLOW_COPY_AND_ASSIGN(ArcBridgeServiceImpl); | 87 DISALLOW_COPY_AND_ASSIGN(ArcBridgeServiceImpl); |
85 }; | 88 }; |
86 | 89 |
87 } // namespace arc | 90 } // namespace arc |
88 | 91 |
89 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_ | 92 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_ |
OLD | NEW |