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

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

Issue 2567083002: Migrate ArcBridgeService::Observer and ArcSession::Observer. (Closed)
Patch Set: rebase 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 unified diff | Download patch
« no previous file with comments | « components/arc/arc_bridge_service.h ('k') | components/arc/arc_bridge_service_impl.h » ('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.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/feature_list.h" 10 #include "base/feature_list.h"
11 #include "base/sequenced_task_runner.h" 11 #include "base/sequenced_task_runner.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "chromeos/chromeos_switches.h" 13 #include "chromeos/chromeos_switches.h"
14 14
15 namespace arc { 15 namespace arc {
16 16
17 namespace { 17 namespace {
18 18
19 const base::Feature kArcEnabledFeature{"EnableARC", 19 const base::Feature kArcEnabledFeature{"EnableARC",
20 base::FEATURE_DISABLED_BY_DEFAULT}; 20 base::FEATURE_DISABLED_BY_DEFAULT};
21 21
22 } // namespace 22 } // namespace
23 23
24 ArcBridgeService::ArcBridgeService() 24 ArcBridgeService::ArcBridgeService()
25 : state_(State::STOPPED), 25 : state_(State::STOPPED),
26 stop_reason_(StopReason::SHUTDOWN), 26 stop_reason_(ArcSessionObserver::StopReason::SHUTDOWN),
27 weak_factory_(this) {} 27 weak_factory_(this) {}
28 28
29 ArcBridgeService::~ArcBridgeService() { 29 ArcBridgeService::~ArcBridgeService() {
30 DCHECK(CalledOnValidThread()); 30 DCHECK(CalledOnValidThread());
31 DCHECK(state() == State::STOPPING || state() == State::STOPPED); 31 DCHECK(state() == State::STOPPING || state() == State::STOPPED);
32 } 32 }
33 33
34 // static 34 // static
35 bool ArcBridgeService::GetEnabled(const base::CommandLine* command_line) { 35 bool ArcBridgeService::GetEnabled(const base::CommandLine* command_line) {
36 return command_line->HasSwitch(chromeos::switches::kEnableArc) || 36 return command_line->HasSwitch(chromeos::switches::kEnableArc) ||
(...skipping 11 matching lines...) Expand all
48 } 48 }
49 49
50 void ArcBridgeService::RequestStop() { 50 void ArcBridgeService::RequestStop() {
51 NOTREACHED(); 51 NOTREACHED();
52 } 52 }
53 53
54 void ArcBridgeService::OnShutdown() { 54 void ArcBridgeService::OnShutdown() {
55 NOTREACHED(); 55 NOTREACHED();
56 } 56 }
57 57
58 void ArcBridgeService::AddObserver(Observer* observer) { 58 void ArcBridgeService::AddObserver(ArcSessionObserver* observer) {
59 DCHECK(CalledOnValidThread()); 59 DCHECK(CalledOnValidThread());
60 observer_list_.AddObserver(observer); 60 observer_list_.AddObserver(observer);
61 } 61 }
62 62
63 void ArcBridgeService::RemoveObserver(Observer* observer) { 63 void ArcBridgeService::RemoveObserver(ArcSessionObserver* observer) {
64 DCHECK(CalledOnValidThread()); 64 DCHECK(CalledOnValidThread());
65 observer_list_.RemoveObserver(observer); 65 observer_list_.RemoveObserver(observer);
66 } 66 }
67 67
68 void ArcBridgeService::SetState(State state) { 68 void ArcBridgeService::SetState(State state) {
69 DCHECK(CalledOnValidThread()); 69 DCHECK(CalledOnValidThread());
70 DCHECK_NE(state_, state); 70 DCHECK_NE(state_, state);
71 state_ = state; 71 state_ = state;
72 VLOG(2) << "State: " << static_cast<uint32_t>(state_); 72 VLOG(2) << "State: " << static_cast<uint32_t>(state_);
73 if (state_ == State::READY) { 73 if (state_ == State::READY) {
74 for (auto& observer : observer_list()) 74 for (auto& observer : observer_list())
75 observer.OnBridgeReady(); 75 observer.OnSessionReady();
76 } else if (state == State::STOPPED) { 76 } else if (state == State::STOPPED) {
77 for (auto& observer : observer_list()) 77 for (auto& observer : observer_list())
78 observer.OnBridgeStopped(stop_reason_); 78 observer.OnSessionStopped(stop_reason_);
79 } 79 }
80 } 80 }
81 81
82 void ArcBridgeService::SetStopReason(StopReason stop_reason) { 82 void ArcBridgeService::SetStopReason(
83 ArcSessionObserver::StopReason stop_reason) {
83 DCHECK(CalledOnValidThread()); 84 DCHECK(CalledOnValidThread());
84 stop_reason_ = stop_reason; 85 stop_reason_ = stop_reason;
85 } 86 }
86 87
87 bool ArcBridgeService::CalledOnValidThread() { 88 bool ArcBridgeService::CalledOnValidThread() {
88 return thread_checker_.CalledOnValidThread(); 89 return thread_checker_.CalledOnValidThread();
89 } 90 }
90 91
91 std::ostream& operator<<(
92 std::ostream& os, ArcBridgeService::StopReason reason) {
93 switch (reason) {
94 #define CASE_IMPL(val) \
95 case ArcBridgeService::StopReason::val: \
96 return os << #val
97
98 CASE_IMPL(SHUTDOWN);
99 CASE_IMPL(GENERIC_BOOT_FAILURE);
100 CASE_IMPL(LOW_DISK_SPACE);
101 CASE_IMPL(CRASH);
102 #undef CASE_IMPL
103 }
104
105 // In case of unexpected value, output the int value.
106 return os << "StopReason(" << static_cast<int>(reason) << ")";
107 }
108
109 } // namespace arc 92 } // namespace arc
OLDNEW
« no previous file with comments | « components/arc/arc_bridge_service.h ('k') | components/arc/arc_bridge_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698