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

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

Issue 2425753002: Rename ArcBridgeBootstrap to ArcSession. (Closed)
Patch Set: Address comment. Created 4 years, 2 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_bridge_service_impl.h ('k') | components/arc/arc_bridge_service_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_bridge_service_impl.h" 5 #include "components/arc/arc_bridge_service_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 12 matching lines...) Expand all
23 namespace arc { 23 namespace arc {
24 24
25 extern ArcBridgeService* g_arc_bridge_service; 25 extern ArcBridgeService* g_arc_bridge_service;
26 26
27 namespace { 27 namespace {
28 constexpr int64_t kReconnectDelayInSeconds = 5; 28 constexpr int64_t kReconnectDelayInSeconds = 5;
29 } // namespace 29 } // namespace
30 30
31 ArcBridgeServiceImpl::ArcBridgeServiceImpl() 31 ArcBridgeServiceImpl::ArcBridgeServiceImpl()
32 : session_started_(false), 32 : session_started_(false),
33 factory_(base::Bind(ArcBridgeBootstrap::Create)), 33 factory_(base::Bind(ArcSession::Create)),
34 weak_factory_(this) { 34 weak_factory_(this) {
35 DCHECK(!g_arc_bridge_service); 35 DCHECK(!g_arc_bridge_service);
36 g_arc_bridge_service = this; 36 g_arc_bridge_service = this;
37 } 37 }
38 38
39 ArcBridgeServiceImpl::~ArcBridgeServiceImpl() { 39 ArcBridgeServiceImpl::~ArcBridgeServiceImpl() {
40 if (bootstrap_) 40 if (arc_session_)
41 bootstrap_->RemoveObserver(this); 41 arc_session_->RemoveObserver(this);
42 42
43 DCHECK(g_arc_bridge_service == this); 43 DCHECK(g_arc_bridge_service == this);
44 g_arc_bridge_service = nullptr; 44 g_arc_bridge_service = nullptr;
45 } 45 }
46 46
47 void ArcBridgeServiceImpl::HandleStartup() { 47 void ArcBridgeServiceImpl::HandleStartup() {
48 DCHECK(CalledOnValidThread()); 48 DCHECK(CalledOnValidThread());
49 if (session_started_) 49 if (session_started_)
50 return; 50 return;
51 VLOG(1) << "Session started"; 51 VLOG(1) << "Session started";
52 session_started_ = true; 52 session_started_ = true;
53 PrerequisitesChanged(); 53 PrerequisitesChanged();
54 } 54 }
55 55
56 void ArcBridgeServiceImpl::Shutdown() { 56 void ArcBridgeServiceImpl::Shutdown() {
57 DCHECK(CalledOnValidThread()); 57 DCHECK(CalledOnValidThread());
58 if (!session_started_) 58 if (!session_started_)
59 return; 59 return;
60 VLOG(1) << "Session ended"; 60 VLOG(1) << "Session ended";
61 session_started_ = false; 61 session_started_ = false;
62 PrerequisitesChanged(); 62 PrerequisitesChanged();
63 } 63 }
64 64
65 void ArcBridgeServiceImpl::SetArcBridgeBootstrapFactoryForTesting( 65 void ArcBridgeServiceImpl::SetArcSessionFactoryForTesting(
66 const ArcBridgeBootstrapFactory& factory) { 66 const ArcSessionFactory& factory) {
67 DCHECK(!factory.is_null()); 67 DCHECK(!factory.is_null());
68 factory_ = factory; 68 factory_ = factory;
69 } 69 }
70 70
71 71
72 void ArcBridgeServiceImpl::DisableReconnectDelayForTesting() { 72 void ArcBridgeServiceImpl::DisableReconnectDelayForTesting() {
73 use_delay_before_reconnecting_ = false; 73 use_delay_before_reconnecting_ = false;
74 } 74 }
75 75
76 void ArcBridgeServiceImpl::PrerequisitesChanged() { 76 void ArcBridgeServiceImpl::PrerequisitesChanged() {
77 DCHECK(CalledOnValidThread()); 77 DCHECK(CalledOnValidThread());
78 VLOG(1) << "Prerequisites changed. " 78 VLOG(1) << "Prerequisites changed. "
79 << "state=" << static_cast<uint32_t>(state()) 79 << "state=" << static_cast<uint32_t>(state())
80 << ", session_started=" << session_started_; 80 << ", session_started=" << session_started_;
81 if (state() == State::STOPPED) { 81 if (state() == State::STOPPED) {
82 if (!session_started_) 82 if (!session_started_)
83 return; 83 return;
84 VLOG(0) << "Prerequisites met, starting ARC"; 84 VLOG(0) << "Prerequisites met, starting ARC";
85 SetStopReason(StopReason::SHUTDOWN); 85 SetStopReason(StopReason::SHUTDOWN);
86 86
87 if (bootstrap_) 87 if (arc_session_)
88 bootstrap_->RemoveObserver(this); 88 arc_session_->RemoveObserver(this);
89 89
90 SetState(State::CONNECTING); 90 SetState(State::CONNECTING);
91 bootstrap_ = factory_.Run(); 91 arc_session_ = factory_.Run();
92 bootstrap_->AddObserver(this); 92 arc_session_->AddObserver(this);
93 bootstrap_->Start(); 93 arc_session_->Start();
94 } else { 94 } else {
95 if (session_started_) 95 if (session_started_)
96 return; 96 return;
97 VLOG(0) << "Prerequisites stopped being met, stopping ARC"; 97 VLOG(0) << "Prerequisites stopped being met, stopping ARC";
98 StopInstance(); 98 StopInstance();
99 } 99 }
100 } 100 }
101 101
102 void ArcBridgeServiceImpl::StopInstance() { 102 void ArcBridgeServiceImpl::StopInstance() {
103 DCHECK(CalledOnValidThread()); 103 DCHECK(CalledOnValidThread());
104 if (state() == State::STOPPED || state() == State::STOPPING) { 104 if (state() == State::STOPPED || state() == State::STOPPING) {
105 VLOG(1) << "StopInstance() called when ARC is not running"; 105 VLOG(1) << "StopInstance() called when ARC is not running";
106 return; 106 return;
107 } 107 }
108 108
109 // We were explicitly asked to stop, so do not reconnect. 109 // We were explicitly asked to stop, so do not reconnect.
110 reconnect_ = false; 110 reconnect_ = false;
111 111
112 VLOG(1) << "Stopping ARC"; 112 VLOG(1) << "Stopping ARC";
113 DCHECK(bootstrap_.get()); 113 DCHECK(arc_session_.get());
114 SetState(State::STOPPING); 114 SetState(State::STOPPING);
115 115
116 // Note: this can call OnStopped() internally as a callback. 116 // Note: this can call OnStopped() internally as a callback.
117 bootstrap_->Stop(); 117 arc_session_->Stop();
118 } 118 }
119 119
120 void ArcBridgeServiceImpl::OnReady() { 120 void ArcBridgeServiceImpl::OnReady() {
121 DCHECK(CalledOnValidThread()); 121 DCHECK(CalledOnValidThread());
122 if (state() != State::CONNECTING) { 122 if (state() != State::CONNECTING) {
123 VLOG(1) << "StopInstance() called while connecting"; 123 VLOG(1) << "StopInstance() called while connecting";
124 return; 124 return;
125 } 125 }
126 126
127 // The container can be considered to have been successfully launched, so 127 // The container can be considered to have been successfully launched, so
128 // restart if the connection goes down without being requested. 128 // restart if the connection goes down without being requested.
129 reconnect_ = true; 129 reconnect_ = true;
130 VLOG(0) << "ARC ready"; 130 VLOG(0) << "ARC ready";
131 SetState(State::READY); 131 SetState(State::READY);
132 } 132 }
133 133
134 void ArcBridgeServiceImpl::OnStopped(StopReason stop_reason) { 134 void ArcBridgeServiceImpl::OnStopped(StopReason stop_reason) {
135 DCHECK(CalledOnValidThread()); 135 DCHECK(CalledOnValidThread());
136 VLOG(0) << "ARC stopped: " << stop_reason; 136 VLOG(0) << "ARC stopped: " << stop_reason;
137 bootstrap_->RemoveObserver(this); 137 arc_session_->RemoveObserver(this);
138 bootstrap_.reset(); 138 arc_session_.reset();
139 SetStopReason(stop_reason); 139 SetStopReason(stop_reason);
140 SetState(State::STOPPED); 140 SetState(State::STOPPED);
141 141
142 if (reconnect_) { 142 if (reconnect_) {
143 // There was a previous invocation and it crashed for some reason. Try 143 // There was a previous invocation and it crashed for some reason. Try
144 // starting the container again. 144 // starting the container again.
145 reconnect_ = false; 145 reconnect_ = false;
146 VLOG(0) << "ARC reconnecting"; 146 VLOG(0) << "ARC reconnecting";
147 if (use_delay_before_reconnecting_) { 147 if (use_delay_before_reconnecting_) {
148 // Instead of immediately trying to restart the container, give it some 148 // Instead of immediately trying to restart the container, give it some
149 // time to finish tearing down in case it is still in the process of 149 // time to finish tearing down in case it is still in the process of
150 // stopping. 150 // stopping.
151 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 151 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
152 FROM_HERE, base::Bind(&ArcBridgeServiceImpl::PrerequisitesChanged, 152 FROM_HERE, base::Bind(&ArcBridgeServiceImpl::PrerequisitesChanged,
153 weak_factory_.GetWeakPtr()), 153 weak_factory_.GetWeakPtr()),
154 base::TimeDelta::FromSeconds(kReconnectDelayInSeconds)); 154 base::TimeDelta::FromSeconds(kReconnectDelayInSeconds));
155 } else { 155 } else {
156 // Restart immediately. 156 // Restart immediately.
157 PrerequisitesChanged(); 157 PrerequisitesChanged();
158 } 158 }
159 } 159 }
160 } 160 }
161 161
162 } // namespace arc 162 } // namespace arc
OLDNEW
« no previous file with comments | « components/arc/arc_bridge_service_impl.h ('k') | components/arc/arc_bridge_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698