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

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

Issue 2720303002: Do nothing on OnSessionStopped if ARC is being restarted. (Closed)
Patch Set: Address comments. 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
« no previous file with comments | « components/arc/arc_session_runner.h ('k') | components/arc/arc_session_runner_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "components/arc/arc_session_runner.h" 5 #include "components/arc/arc_session_runner.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/task_runner.h" 9 #include "base/task_runner.h"
10 #include "components/arc/arc_session.h"
11 10
12 namespace arc { 11 namespace arc {
13 12
14 namespace { 13 namespace {
15 14
16 constexpr base::TimeDelta kDefaultRestartDelay = 15 constexpr base::TimeDelta kDefaultRestartDelay =
17 base::TimeDelta::FromSeconds(5); 16 base::TimeDelta::FromSeconds(5);
18 17
19 } // namespace 18 } // namespace
20 19
21 ArcSessionRunner::ArcSessionRunner(const ArcSessionFactory& factory) 20 ArcSessionRunner::ArcSessionRunner(const ArcSessionFactory& factory)
22 : restart_delay_(kDefaultRestartDelay), 21 : restart_delay_(kDefaultRestartDelay),
23 factory_(factory), 22 factory_(factory),
24 weak_ptr_factory_(this) {} 23 weak_ptr_factory_(this) {}
25 24
26 ArcSessionRunner::~ArcSessionRunner() { 25 ArcSessionRunner::~ArcSessionRunner() {
27 DCHECK(thread_checker_.CalledOnValidThread()); 26 DCHECK(thread_checker_.CalledOnValidThread());
28 if (arc_session_) 27 if (arc_session_)
29 arc_session_->RemoveObserver(this); 28 arc_session_->RemoveObserver(this);
30 } 29 }
31 30
32 void ArcSessionRunner::AddObserver(ArcSessionObserver* observer) { 31 void ArcSessionRunner::AddObserver(Observer* observer) {
33 DCHECK(thread_checker_.CalledOnValidThread()); 32 DCHECK(thread_checker_.CalledOnValidThread());
34 observer_list_.AddObserver(observer); 33 observer_list_.AddObserver(observer);
35 } 34 }
36 35
37 void ArcSessionRunner::RemoveObserver(ArcSessionObserver* observer) { 36 void ArcSessionRunner::RemoveObserver(Observer* observer) {
38 DCHECK(thread_checker_.CalledOnValidThread()); 37 DCHECK(thread_checker_.CalledOnValidThread());
39 observer_list_.RemoveObserver(observer); 38 observer_list_.RemoveObserver(observer);
40 } 39 }
41 40
42 void ArcSessionRunner::RequestStart() { 41 void ArcSessionRunner::RequestStart() {
43 DCHECK(thread_checker_.CalledOnValidThread()); 42 DCHECK(thread_checker_.CalledOnValidThread());
44 43
45 // Consecutive RequestStart() call. Do nothing. 44 // Consecutive RequestStart() call. Do nothing.
46 if (run_requested_) 45 if (run_requested_)
47 return; 46 return;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 } 143 }
145 144
146 void ArcSessionRunner::OnSessionReady() { 145 void ArcSessionRunner::OnSessionReady() {
147 DCHECK(thread_checker_.CalledOnValidThread()); 146 DCHECK(thread_checker_.CalledOnValidThread());
148 DCHECK_EQ(state_, State::STARTING); 147 DCHECK_EQ(state_, State::STARTING);
149 DCHECK(arc_session_); 148 DCHECK(arc_session_);
150 DCHECK(!restart_timer_.IsRunning()); 149 DCHECK(!restart_timer_.IsRunning());
151 150
152 VLOG(0) << "ARC ready"; 151 VLOG(0) << "ARC ready";
153 state_ = State::RUNNING; 152 state_ = State::RUNNING;
154
155 for (auto& observer : observer_list_)
156 observer.OnSessionReady();
157 } 153 }
158 154
159 void ArcSessionRunner::OnSessionStopped(StopReason stop_reason) { 155 void ArcSessionRunner::OnSessionStopped(ArcStopReason stop_reason) {
160 DCHECK(thread_checker_.CalledOnValidThread()); 156 DCHECK(thread_checker_.CalledOnValidThread());
161 DCHECK_NE(state_, State::STOPPED); 157 DCHECK_NE(state_, State::STOPPED);
162 DCHECK(arc_session_); 158 DCHECK(arc_session_);
163 DCHECK(!restart_timer_.IsRunning()); 159 DCHECK(!restart_timer_.IsRunning());
164 160
165 VLOG(0) << "ARC stopped: " << stop_reason; 161 VLOG(0) << "ARC stopped: " << stop_reason;
166 arc_session_->RemoveObserver(this); 162 arc_session_->RemoveObserver(this);
167 arc_session_.reset(); 163 arc_session_.reset();
168 164
169 // If RUNNING, ARC instance unexpectedly crashed so we need to restart it 165 // If RUNNING, ARC instance unexpectedly crashed so we need to restart it
170 // automatically. 166 // automatically.
171 // If STOPPING, at least once RequestStop() is called. If |session_started_| 167 // If STOPPING, at least once RequestStop() is called. If |session_started_|
172 // is true, RequestStart() is following so schedule to restart ARC session. 168 // is true, RequestStart() is following so schedule to restart ARC session.
173 // Otherwise, do nothing. 169 // Otherwise, do nothing.
174 // If STARTING, ARC instance has not been booted properly, so do not 170 // If STARTING, ARC instance has not been booted properly, so do not
175 // restart it automatically. 171 // restart it automatically.
176 if (state_ == State::RUNNING || 172 const bool restarting = (state_ == State::RUNNING ||
177 (state_ == State::STOPPING && run_requested_)) { 173 (state_ == State::STOPPING && run_requested_));
174 if (restarting) {
178 // This check is for RUNNING case. In RUNNING case |run_requested_| should 175 // This check is for RUNNING case. In RUNNING case |run_requested_| should
179 // be always true, because if once RequestStop() is called, the state_ 176 // be always true, because if once RequestStop() is called, the state_
180 // will be set to STOPPING. 177 // will be set to STOPPING.
181 DCHECK(run_requested_); 178 DCHECK(run_requested_);
182 179
183 // There was a previous invocation and it crashed for some reason. Try 180 // There was a previous invocation and it crashed for some reason. Try
184 // starting ARC instance later again. 181 // starting ARC instance later again.
185 // Note that even |restart_delay_| is 0 (for testing), it needs to 182 // Note that even |restart_delay_| is 0 (for testing), it needs to
186 // PostTask, because observer callback may call RequestStart()/Stop(). 183 // PostTask, because observer callback may call RequestStart()/Stop().
187 VLOG(0) << "ARC restarting"; 184 VLOG(0) << "ARC restarting";
188 restart_timer_.Start(FROM_HERE, restart_delay_, 185 restart_timer_.Start(FROM_HERE, restart_delay_,
189 base::Bind(&ArcSessionRunner::StartArcSession, 186 base::Bind(&ArcSessionRunner::StartArcSession,
190 weak_ptr_factory_.GetWeakPtr())); 187 weak_ptr_factory_.GetWeakPtr()));
191 } 188 }
192 189
193 // TODO(hidehiko): Consider to let observers know whether there is scheduled
194 // restarting event, or not.
195 state_ = State::STOPPED; 190 state_ = State::STOPPED;
196 for (auto& observer : observer_list_) 191 for (auto& observer : observer_list_)
197 observer.OnSessionStopped(stop_reason); 192 observer.OnSessionStopped(stop_reason, restarting);
198 } 193 }
199 194
200 } // namespace arc 195 } // namespace arc
OLDNEW
« no previous file with comments | « components/arc/arc_session_runner.h ('k') | components/arc/arc_session_runner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698