Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(679)

Side by Side Diff: components/arc/arc_session_runner.h

Issue 2720303002: Do nothing on OnSessionStopped if ARC is being restarted. (Closed)
Patch Set: Get rid of ArcSessionObserver Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_SESSION_RUNNER_H_ 5 #ifndef COMPONENTS_ARC_ARC_SESSION_RUNNER_H_
6 #define COMPONENTS_ARC_ARC_SESSION_RUNNER_H_ 6 #define COMPONENTS_ARC_ARC_SESSION_RUNNER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "base/timer/timer.h" 13 #include "base/timer/timer.h"
14 #include "components/arc/arc_bridge_service.h" 14 #include "components/arc/arc_session.h"
15 #include "components/arc/arc_session_observer.h" 15 #include "components/arc/arc_stop_reason.h"
16 16
17 namespace arc { 17 namespace arc {
18 18
19 class ArcSession;
20
21 // Accept requests to start/stop ARC instance. Also supports automatic 19 // Accept requests to start/stop ARC instance. Also supports automatic
22 // restarting on unexpected ARC instance crash. 20 // restarting on unexpected ARC instance crash.
23 // TODO(hidehiko): Get rid of ArcBridgeService inheritance. 21 class ArcSessionRunner : public ArcSession::Observer {
24 class ArcSessionRunner : public ArcSessionObserver {
25 public: 22 public:
23 class Observer {
Yusuke Sato 2017/03/01 15:51:01 same?
hidehiko 2017/03/01 17:28:03 Done.
24 public:
25 // Called when ARC instance is stopped. If |restarting| is true, another
26 // ARC session is being restarted (practically after certain delay).
27 // Note: this is called once per ARC session, including unexpected
28 // CRASH on ARC container, and expected SHUTDOWN of ARC triggered by
29 // RequestStop(), so may be called multiple times for one RequestStart().
30 virtual void OnSessionStopped(ArcStopReason reason, bool restarting) = 0;
31
32 protected:
33 // Do not directly create/destroy the instance via the interface.
34 Observer() = default;
35 ~Observer() = default;
36 };
37
26 // This is the factory interface to inject ArcSession instance 38 // This is the factory interface to inject ArcSession instance
27 // for testing purpose. 39 // for testing purpose.
28 using ArcSessionFactory = base::Callback<std::unique_ptr<ArcSession>()>; 40 using ArcSessionFactory = base::Callback<std::unique_ptr<ArcSession>()>;
29 41
30 explicit ArcSessionRunner(const ArcSessionFactory& factory); 42 explicit ArcSessionRunner(const ArcSessionFactory& factory);
31 ~ArcSessionRunner() override; 43 ~ArcSessionRunner();
32 44
33 // Add/Remove an observer. 45 // Add/Remove an observer.
34 void AddObserver(ArcSessionObserver* observer); 46 void AddObserver(Observer* observer);
35 void RemoveObserver(ArcSessionObserver* observer); 47 void RemoveObserver(Observer* observer);
36 48
37 // Starts the ARC service, then it will connect the Mojo channel. When the 49 // Starts the ARC service, then it will connect the Mojo channel. When the
38 // bridge becomes ready, registered Observer's OnSessionReady() is called. 50 // bridge becomes ready, registered Observer's OnSessionReady() is called.
39 void RequestStart(); 51 void RequestStart();
40 52
41 // Stops the ARC service. 53 // Stops the ARC service.
42 void RequestStop(); 54 void RequestStop();
43 55
44 // OnShutdown() should be called when the browser is shutting down. This can 56 // OnShutdown() should be called when the browser is shutting down. This can
45 // only be called on the thread that this class was created on. We assume that 57 // only be called on the thread that this class was created on. We assume that
(...skipping 15 matching lines...) Expand all
61 void SetRestartDelayForTesting(const base::TimeDelta& restart_delay); 73 void SetRestartDelayForTesting(const base::TimeDelta& restart_delay);
62 74
63 private: 75 private:
64 // The possible states. In the normal flow, the state changes in the 76 // The possible states. In the normal flow, the state changes in the
65 // following sequence: 77 // following sequence:
66 // 78 //
67 // STOPPED 79 // STOPPED
68 // RequestStart() -> 80 // RequestStart() ->
69 // STARTING 81 // STARTING
70 // OnSessionReady() -> 82 // OnSessionReady() ->
71 // READY 83 // RUNNING
72 // 84 //
73 // The ArcSession state machine can be thought of being substates of 85 // The ArcSession state machine can be thought of being substates of
74 // ArcBridgeService's STARTING state. 86 // ArcBridgeService's STARTING state.
75 // ArcBridgeService's state machine can be stopped at any phase. 87 // ArcBridgeService's state machine can be stopped at any phase.
76 // 88 //
77 // * 89 // *
78 // RequestStop() -> 90 // RequestStop() ->
79 // STOPPING 91 // STOPPING
80 // OnSessionStopped() -> 92 // OnSessionStopped() ->
81 // STOPPED 93 // STOPPED
82 enum class State { 94 enum class State {
83 // ARC instance is not currently running. 95 // ARC instance is not currently running.
84 STOPPED, 96 STOPPED,
85 97
86 // Request to start ARC instance is received. Starting an ARC instance. 98 // Request to start ARC instance is received. Starting an ARC instance.
87 STARTING, 99 STARTING,
88 100
89 // ARC instance has finished initializing, and is now ready for interaction 101 // ARC instance has finished initializing, and is now ready for interaction
90 // with other services. 102 // with other services.
91 RUNNING, 103 RUNNING,
92 104
93 // Request to stop ARC instance is recieved. Stopping the ARC instance. 105 // Request to stop ARC instance is recieved. Stopping the ARC instance.
94 STOPPING, 106 STOPPING,
95 }; 107 };
96 108
97 // Starts to run an ARC instance. 109 // Starts to run an ARC instance.
98 void StartArcSession(); 110 void StartArcSession();
99 111
100 // ArcSessionObserver: 112 // ArcSession::Observer:
101 void OnSessionReady() override; 113 void OnSessionReady() override;
102 void OnSessionStopped(StopReason reason) override; 114 void OnSessionStopped(ArcStopReason reason) override;
103 115
104 base::ThreadChecker thread_checker_; 116 base::ThreadChecker thread_checker_;
105 117
106 // Observers for the ARC instance state change events. 118 // Observers for the ARC instance state change events.
107 base::ObserverList<ArcSessionObserver> observer_list_; 119 base::ObserverList<Observer> observer_list_;
108 120
109 // Whether a client requests to run session or not. 121 // Whether a client requests to run session or not.
110 bool run_requested_ = false; 122 bool run_requested_ = false;
111 123
112 // Instead of immediately trying to restart the container, give it some time 124 // Instead of immediately trying to restart the container, give it some time
113 // to finish tearing down in case it is still in the process of stopping. 125 // to finish tearing down in case it is still in the process of stopping.
114 base::TimeDelta restart_delay_; 126 base::TimeDelta restart_delay_;
115 base::OneShotTimer restart_timer_; 127 base::OneShotTimer restart_timer_;
116 128
117 // Factory to inject a fake ArcSession instance for testing. 129 // Factory to inject a fake ArcSession instance for testing.
118 ArcSessionFactory factory_; 130 ArcSessionFactory factory_;
119 131
120 // Current runner's state. 132 // Current runner's state.
121 State state_ = State::STOPPED; 133 State state_ = State::STOPPED;
122 134
123 // ArcSession object for currently running ARC instance. This should be 135 // ArcSession object for currently running ARC instance. This should be
124 // nullptr if the state is STOPPED, otherwise non-nullptr. 136 // nullptr if the state is STOPPED, otherwise non-nullptr.
125 std::unique_ptr<ArcSession> arc_session_; 137 std::unique_ptr<ArcSession> arc_session_;
126 138
127 // WeakPtrFactory to use callbacks. 139 // WeakPtrFactory to use callbacks.
128 base::WeakPtrFactory<ArcSessionRunner> weak_ptr_factory_; 140 base::WeakPtrFactory<ArcSessionRunner> weak_ptr_factory_;
129 141
130 DISALLOW_COPY_AND_ASSIGN(ArcSessionRunner); 142 DISALLOW_COPY_AND_ASSIGN(ArcSessionRunner);
131 }; 143 };
132 144
133 } // namespace arc 145 } // namespace arc
134 146
135 #endif // COMPONENTS_ARC_ARC_SESSION_RUNNER_H_ 147 #endif // COMPONENTS_ARC_ARC_SESSION_RUNNER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698