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

Unified Diff: components/arc/arc_session_runner.cc

Issue 2574013003: Refactor ArcSessionRunner part 1. (Closed)
Patch Set: rebase to the split CL Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: components/arc/arc_session_runner.cc
diff --git a/components/arc/arc_bridge_service_impl.cc b/components/arc/arc_session_runner.cc
similarity index 78%
rename from components/arc/arc_bridge_service_impl.cc
rename to components/arc/arc_session_runner.cc
index 524b13ab069c594f7bf9af0e0e21b941b8317156..513d1838232cfeaea6c5aa7d21e364b7c9060c13 100644
--- a/components/arc/arc_bridge_service_impl.cc
+++ b/components/arc/arc_session_runner.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/arc/arc_bridge_service_impl.h"
+#include "components/arc/arc_session_runner.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
@@ -17,19 +17,21 @@ constexpr base::TimeDelta kDefaultRestartDelay =
} // namespace
-ArcBridgeServiceImpl::ArcBridgeServiceImpl(
- const scoped_refptr<base::TaskRunner>& blocking_task_runner)
+ArcSessionRunner::ArcSessionRunner(scoped_refptr<base::TaskRunner> task_runner)
+ : ArcSessionRunner(base::Bind(&ArcSession::Create, this, task_runner)) {}
+
+ArcSessionRunner::ArcSessionRunner(const ArcSessionFactory& factory)
: restart_delay_(kDefaultRestartDelay),
- factory_(base::Bind(ArcSession::Create, this, blocking_task_runner)),
+ factory_(factory),
weak_ptr_factory_(this) {}
-ArcBridgeServiceImpl::~ArcBridgeServiceImpl() {
+ArcSessionRunner::~ArcSessionRunner() {
DCHECK(CalledOnValidThread());
if (arc_session_)
arc_session_->RemoveObserver(this);
}
-void ArcBridgeServiceImpl::RequestStart() {
+void ArcSessionRunner::RequestStart() {
DCHECK(CalledOnValidThread());
// Consecutive RequestStart() call. Do nothing.
@@ -55,7 +57,7 @@ void ArcBridgeServiceImpl::RequestStart() {
}
}
-void ArcBridgeServiceImpl::RequestStop() {
+void ArcSessionRunner::RequestStop() {
DCHECK(CalledOnValidThread());
// Consecutive RequestStop() call. Do nothing.
@@ -85,7 +87,7 @@ void ArcBridgeServiceImpl::RequestStop() {
}
}
-void ArcBridgeServiceImpl::OnShutdown() {
+void ArcSessionRunner::OnShutdown() {
DCHECK(CalledOnValidThread());
VLOG(1) << "OnShutdown";
@@ -98,16 +100,7 @@ void ArcBridgeServiceImpl::OnShutdown() {
DCHECK(!arc_session_);
}
-void ArcBridgeServiceImpl::SetArcSessionFactoryForTesting(
- const ArcSessionFactory& factory) {
- DCHECK(!factory.is_null());
- DCHECK_EQ(state(), State::STOPPED);
- DCHECK(!arc_session_);
- DCHECK(!restart_timer_.IsRunning());
- factory_ = factory;
-}
-
-void ArcBridgeServiceImpl::SetRestartDelayForTesting(
+void ArcSessionRunner::SetRestartDelayForTesting(
const base::TimeDelta& restart_delay) {
DCHECK_EQ(state(), State::STOPPED);
DCHECK(!arc_session_);
@@ -115,7 +108,7 @@ void ArcBridgeServiceImpl::SetRestartDelayForTesting(
restart_delay_ = restart_delay;
}
-void ArcBridgeServiceImpl::StartArcSession() {
+void ArcSessionRunner::StartArcSession() {
DCHECK(CalledOnValidThread());
DCHECK_EQ(state(), State::STOPPED);
DCHECK(!arc_session_);
@@ -129,7 +122,7 @@ void ArcBridgeServiceImpl::StartArcSession() {
arc_session_->Start();
}
-void ArcBridgeServiceImpl::OnSessionReady() {
+void ArcSessionRunner::OnSessionReady() {
DCHECK(CalledOnValidThread());
DCHECK_EQ(state(), State::STARTING);
DCHECK(arc_session_);
@@ -139,7 +132,7 @@ void ArcBridgeServiceImpl::OnSessionReady() {
SetState(State::RUNNING);
}
-void ArcBridgeServiceImpl::OnSessionStopped(StopReason stop_reason) {
+void ArcSessionRunner::OnSessionStopped(StopReason stop_reason) {
DCHECK(CalledOnValidThread());
DCHECK_NE(state(), State::STOPPED);
DCHECK(arc_session_);
@@ -149,20 +142,19 @@ void ArcBridgeServiceImpl::OnSessionStopped(StopReason stop_reason) {
arc_session_->RemoveObserver(this);
arc_session_.reset();
- // If READY, ARC instance is unexpectedly crashed so we need to restart it
+ // If RUNNING, ARC instance is unexpectedly crashed so we need restart it
// automatically. If STOPPING, it is the result of consecutive RequestStop()
// followed by RequestStart() invocation.
- // If CONNECTING, ARC instance has not been booted properly, so do not
- // restart it automatically.
+ // If STARTING, ARC instance has not been booted properly, so do not restart
+ // it automatically.
if (running_ && (state() == State::RUNNING || state() == State::STOPPING)) {
// There was a previous invocation and it crashed for some reason. Try
// starting ARC instance later again.
// Note that even |restart_delay_| is 0 (for testing), it needs to
- // PostTask, because observer callback may call RequestStart()/Stop(),
- // which can change restarting.
+ // PostTask, because observer callback may call RequestStart()/Stop().
VLOG(0) << "ARC restarting";
restart_timer_.Start(FROM_HERE, restart_delay_,
- base::Bind(&ArcBridgeServiceImpl::StartArcSession,
+ base::Bind(&ArcSessionRunner::StartArcSession,
weak_ptr_factory_.GetWeakPtr()));
}

Powered by Google App Engine
This is Rietveld 408576698