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

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

Issue 2720303002: Do nothing on OnSessionStopped if ARC is being restarted. (Closed)
Patch Set: 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 #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" 10 #include "components/arc/arc_session.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 DCHECK(arc_session_); 149 DCHECK(arc_session_);
150 DCHECK(!restart_timer_.IsRunning()); 150 DCHECK(!restart_timer_.IsRunning());
151 151
152 VLOG(0) << "ARC ready"; 152 VLOG(0) << "ARC ready";
153 state_ = State::RUNNING; 153 state_ = State::RUNNING;
154 154
155 for (auto& observer : observer_list_) 155 for (auto& observer : observer_list_)
156 observer.OnSessionReady(); 156 observer.OnSessionReady();
157 } 157 }
158 158
159 void ArcSessionRunner::OnSessionStopped(StopReason stop_reason) { 159 void ArcSessionRunner::OnSessionStopped(StopReason stop_reason,
160 bool restarting) {
160 DCHECK(thread_checker_.CalledOnValidThread()); 161 DCHECK(thread_checker_.CalledOnValidThread());
161 DCHECK_NE(state_, State::STOPPED); 162 DCHECK_NE(state_, State::STOPPED);
162 DCHECK(arc_session_); 163 DCHECK(arc_session_);
163 DCHECK(!restart_timer_.IsRunning()); 164 DCHECK(!restart_timer_.IsRunning());
165 // Because ArcSession won't restart automatically by itself, |restarting|
Yusuke Sato 2017/02/28 21:07:17 Then you can remove L165-167 :)
hidehiko 2017/03/01 09:10:05 Done.
166 // should be always false.
167 DCHECK(!restarting);
164 168
165 VLOG(0) << "ARC stopped: " << stop_reason; 169 VLOG(0) << "ARC stopped: " << stop_reason;
166 arc_session_->RemoveObserver(this); 170 arc_session_->RemoveObserver(this);
167 arc_session_.reset(); 171 arc_session_.reset();
168 172
169 // If RUNNING, ARC instance unexpectedly crashed so we need to restart it 173 // If RUNNING, ARC instance unexpectedly crashed so we need to restart it
170 // automatically. 174 // automatically.
171 // If STOPPING, at least once RequestStop() is called. If |session_started_| 175 // If STOPPING, at least once RequestStop() is called. If |session_started_|
172 // is true, RequestStart() is following so schedule to restart ARC session. 176 // is true, RequestStart() is following so schedule to restart ARC session.
173 // Otherwise, do nothing. 177 // Otherwise, do nothing.
174 // If STARTING, ARC instance has not been booted properly, so do not 178 // If STARTING, ARC instance has not been booted properly, so do not
175 // restart it automatically. 179 // restart it automatically.
176 if (state_ == State::RUNNING || 180 if (state_ == State::RUNNING ||
177 (state_ == State::STOPPING && run_requested_)) { 181 (state_ == State::STOPPING && run_requested_)) {
178 // This check is for RUNNING case. In RUNNING case |run_requested_| should 182 // This check is for RUNNING case. In RUNNING case |run_requested_| should
179 // be always true, because if once RequestStop() is called, the state_ 183 // be always true, because if once RequestStop() is called, the state_
180 // will be set to STOPPING. 184 // will be set to STOPPING.
181 DCHECK(run_requested_); 185 DCHECK(run_requested_);
182 186
183 // There was a previous invocation and it crashed for some reason. Try 187 // There was a previous invocation and it crashed for some reason. Try
184 // starting ARC instance later again. 188 // starting ARC instance later again.
185 // Note that even |restart_delay_| is 0 (for testing), it needs to 189 // Note that even |restart_delay_| is 0 (for testing), it needs to
186 // PostTask, because observer callback may call RequestStart()/Stop(). 190 // PostTask, because observer callback may call RequestStart()/Stop().
187 VLOG(0) << "ARC restarting"; 191 VLOG(0) << "ARC restarting";
188 restart_timer_.Start(FROM_HERE, restart_delay_, 192 restart_timer_.Start(FROM_HERE, restart_delay_,
189 base::Bind(&ArcSessionRunner::StartArcSession, 193 base::Bind(&ArcSessionRunner::StartArcSession,
190 weak_ptr_factory_.GetWeakPtr())); 194 weak_ptr_factory_.GetWeakPtr()));
195 restarting = true; // Overwrite the passing argument to true.
hidehiko 2017/02/28 16:33:48 Note: another approach will be; not calling OnSess
191 } 196 }
192 197
193 // TODO(hidehiko): Consider to let observers know whether there is scheduled
194 // restarting event, or not.
195 state_ = State::STOPPED; 198 state_ = State::STOPPED;
196 for (auto& observer : observer_list_) 199 for (auto& observer : observer_list_)
197 observer.OnSessionStopped(stop_reason); 200 observer.OnSessionStopped(stop_reason, restarting);
198 } 201 }
199 202
200 } // namespace arc 203 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698