OLD | NEW |
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.h" | 5 #include "components/arc/arc_bridge_service.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
12 #include "chromeos/chromeos_switches.h" | 12 #include "chromeos/chromeos_switches.h" |
13 | 13 |
14 namespace arc { | 14 namespace arc { |
15 | 15 |
16 // Weak pointer. This class is owned by ArcServiceManager. | 16 // Weak pointer. This class is owned by ArcServiceManager. |
17 ArcBridgeService* g_arc_bridge_service = nullptr; | 17 ArcBridgeService* g_arc_bridge_service = nullptr; |
18 | 18 |
19 ArcBridgeService::ArcBridgeService() | 19 ArcBridgeService::ArcBridgeService() |
20 : available_(false), state_(State::STOPPED), weak_factory_(this) { | 20 : available_(false), |
21 } | 21 state_(State::STOPPED), |
| 22 stop_reason_(StopReason::SHUTDOWN), |
| 23 weak_factory_(this) {} |
22 | 24 |
23 ArcBridgeService::~ArcBridgeService() { | 25 ArcBridgeService::~ArcBridgeService() { |
24 DCHECK(CalledOnValidThread()); | 26 DCHECK(CalledOnValidThread()); |
25 DCHECK(state() == State::STOPPING || state() == State::STOPPED); | 27 DCHECK(state() == State::STOPPING || state() == State::STOPPED); |
26 } | 28 } |
27 | 29 |
28 // static | 30 // static |
29 ArcBridgeService* ArcBridgeService::Get() { | 31 ArcBridgeService* ArcBridgeService::Get() { |
30 if (!g_arc_bridge_service) { | 32 if (!g_arc_bridge_service) { |
31 // ArcBridgeService may be indirectly referenced in unit tests where | 33 // ArcBridgeService may be indirectly referenced in unit tests where |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 } | 162 } |
161 | 163 |
162 void ArcBridgeService::SetState(State state) { | 164 void ArcBridgeService::SetState(State state) { |
163 DCHECK(CalledOnValidThread()); | 165 DCHECK(CalledOnValidThread()); |
164 DCHECK_NE(state_, state); | 166 DCHECK_NE(state_, state); |
165 state_ = state; | 167 state_ = state; |
166 VLOG(2) << "State: " << static_cast<uint32_t>(state_); | 168 VLOG(2) << "State: " << static_cast<uint32_t>(state_); |
167 if (state_ == State::READY) | 169 if (state_ == State::READY) |
168 FOR_EACH_OBSERVER(Observer, observer_list(), OnBridgeReady()); | 170 FOR_EACH_OBSERVER(Observer, observer_list(), OnBridgeReady()); |
169 else if (state == State::STOPPED) | 171 else if (state == State::STOPPED) |
170 FOR_EACH_OBSERVER(Observer, observer_list(), OnBridgeStopped()); | 172 FOR_EACH_OBSERVER(Observer, observer_list(), OnBridgeStopped(stop_reason_)); |
171 } | 173 } |
172 | 174 |
173 void ArcBridgeService::SetAvailable(bool available) { | 175 void ArcBridgeService::SetAvailable(bool available) { |
174 DCHECK(CalledOnValidThread()); | 176 DCHECK(CalledOnValidThread()); |
175 DCHECK_NE(available_, available); | 177 DCHECK_NE(available_, available); |
176 available_ = available; | 178 available_ = available; |
177 FOR_EACH_OBSERVER(Observer, observer_list(), OnAvailableChanged(available_)); | 179 FOR_EACH_OBSERVER(Observer, observer_list(), OnAvailableChanged(available_)); |
178 } | 180 } |
179 | 181 |
| 182 void ArcBridgeService::SetStopReason(StopReason stop_reason) { |
| 183 DCHECK(CalledOnValidThread()); |
| 184 stop_reason_ = stop_reason; |
| 185 } |
| 186 |
180 bool ArcBridgeService::CalledOnValidThread() { | 187 bool ArcBridgeService::CalledOnValidThread() { |
181 return thread_checker_.CalledOnValidThread(); | 188 return thread_checker_.CalledOnValidThread(); |
182 } | 189 } |
183 | 190 |
184 void ArcBridgeService::CloseAllChannels() { | 191 void ArcBridgeService::CloseAllChannels() { |
185 // Call all the error handlers of all the channels to both close the channel | 192 // Call all the error handlers of all the channels to both close the channel |
186 // and notify any observers that the channel is closed. | 193 // and notify any observers that the channel is closed. |
187 app_.CloseChannel(); | 194 app_.CloseChannel(); |
188 audio_.CloseChannel(); | 195 audio_.CloseChannel(); |
189 auth_.CloseChannel(); | 196 auth_.CloseChannel(); |
190 bluetooth_.CloseChannel(); | 197 bluetooth_.CloseChannel(); |
191 clipboard_.CloseChannel(); | 198 clipboard_.CloseChannel(); |
192 crash_collector_.CloseChannel(); | 199 crash_collector_.CloseChannel(); |
193 file_system_.CloseChannel(); | 200 file_system_.CloseChannel(); |
194 ime_.CloseChannel(); | 201 ime_.CloseChannel(); |
195 intent_helper_.CloseChannel(); | 202 intent_helper_.CloseChannel(); |
196 metrics_.CloseChannel(); | 203 metrics_.CloseChannel(); |
197 net_.CloseChannel(); | 204 net_.CloseChannel(); |
198 notifications_.CloseChannel(); | 205 notifications_.CloseChannel(); |
199 obb_mounter_.CloseChannel(); | 206 obb_mounter_.CloseChannel(); |
200 policy_.CloseChannel(); | 207 policy_.CloseChannel(); |
201 power_.CloseChannel(); | 208 power_.CloseChannel(); |
202 process_.CloseChannel(); | 209 process_.CloseChannel(); |
203 storage_manager_.CloseChannel(); | 210 storage_manager_.CloseChannel(); |
204 video_.CloseChannel(); | 211 video_.CloseChannel(); |
205 window_manager_.CloseChannel(); | 212 window_manager_.CloseChannel(); |
206 } | 213 } |
207 | 214 |
208 } // namespace arc | 215 } // namespace arc |
OLD | NEW |