| 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/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 #include "components/arc/arc_session_runner.h" |
| 14 | 15 |
| 15 namespace arc { | 16 namespace arc { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 const base::Feature kArcEnabledFeature{"EnableARC", | 20 const base::Feature kArcEnabledFeature{"EnableARC", |
| 20 base::FEATURE_DISABLED_BY_DEFAULT}; | 21 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 21 | 22 |
| 22 } // namespace | 23 } // namespace |
| 23 | 24 |
| 24 ArcBridgeService::ArcBridgeService() | 25 ArcBridgeService::ArcBridgeService() = default; |
| 25 : state_(State::STOPPED), | |
| 26 stop_reason_(ArcSessionObserver::StopReason::SHUTDOWN), | |
| 27 weak_factory_(this) {} | |
| 28 | 26 |
| 29 ArcBridgeService::~ArcBridgeService() { | 27 ArcBridgeService::~ArcBridgeService() = default; |
| 30 DCHECK(CalledOnValidThread()); | |
| 31 DCHECK(state() == State::STOPPING || state() == State::STOPPED); | |
| 32 } | |
| 33 | 28 |
| 34 // static | 29 // static |
| 35 bool ArcBridgeService::GetEnabled(const base::CommandLine* command_line) { | 30 bool ArcBridgeService::GetEnabled(const base::CommandLine* command_line) { |
| 36 return command_line->HasSwitch(chromeos::switches::kEnableArc) || | 31 return command_line->HasSwitch(chromeos::switches::kEnableArc) || |
| 37 (command_line->HasSwitch(chromeos::switches::kArcAvailable) && | 32 (command_line->HasSwitch(chromeos::switches::kArcAvailable) && |
| 38 base::FeatureList::IsEnabled(kArcEnabledFeature)); | 33 base::FeatureList::IsEnabled(kArcEnabledFeature)); |
| 39 } | 34 } |
| 40 | 35 |
| 41 // static | 36 // static |
| 42 bool ArcBridgeService::GetAvailable(const base::CommandLine* command_line) { | 37 bool ArcBridgeService::GetAvailable(const base::CommandLine* command_line) { |
| 43 return command_line->HasSwitch(chromeos::switches::kArcAvailable); | 38 return command_line->HasSwitch(chromeos::switches::kArcAvailable); |
| 44 } | 39 } |
| 45 | 40 |
| 41 void ArcBridgeService::InitializeArcSessionRunner( |
| 42 std::unique_ptr<ArcSessionRunner> arc_session_runner) { |
| 43 DCHECK(!arc_session_runner_); |
| 44 arc_session_runner_ = std::move(arc_session_runner); |
| 45 } |
| 46 |
| 47 void ArcBridgeService::AddObserver(ArcSessionObserver* observer) { |
| 48 DCHECK(arc_session_runner_); |
| 49 arc_session_runner_->AddObserver(observer); |
| 50 } |
| 51 |
| 52 void ArcBridgeService::RemoveObserver(ArcSessionObserver* observer) { |
| 53 DCHECK(arc_session_runner_); |
| 54 arc_session_runner_->RemoveObserver(observer); |
| 55 } |
| 56 |
| 46 void ArcBridgeService::RequestStart() { | 57 void ArcBridgeService::RequestStart() { |
| 47 NOTREACHED(); | 58 DCHECK(arc_session_runner_); |
| 59 arc_session_runner_->RequestStart(); |
| 48 } | 60 } |
| 49 | 61 |
| 50 void ArcBridgeService::RequestStop() { | 62 void ArcBridgeService::RequestStop() { |
| 51 NOTREACHED(); | 63 DCHECK(arc_session_runner_); |
| 64 arc_session_runner_->RequestStop(); |
| 52 } | 65 } |
| 53 | 66 |
| 54 void ArcBridgeService::OnShutdown() { | 67 void ArcBridgeService::OnShutdown() { |
| 55 NOTREACHED(); | 68 DCHECK(arc_session_runner_); |
| 69 arc_session_runner_->OnShutdown(); |
| 56 } | 70 } |
| 57 | 71 |
| 58 void ArcBridgeService::AddObserver(ArcSessionObserver* observer) { | 72 bool ArcBridgeService::ready() const { |
| 59 DCHECK(CalledOnValidThread()); | 73 DCHECK(arc_session_runner_); |
| 60 observer_list_.AddObserver(observer); | 74 return arc_session_runner_->IsRunning(); |
| 61 } | 75 } |
| 62 | 76 |
| 63 void ArcBridgeService::RemoveObserver(ArcSessionObserver* observer) { | 77 bool ArcBridgeService::stopped() const { |
| 64 DCHECK(CalledOnValidThread()); | 78 DCHECK(arc_session_runner_); |
| 65 observer_list_.RemoveObserver(observer); | 79 return arc_session_runner_->IsStopped(); |
| 66 } | |
| 67 | |
| 68 void ArcBridgeService::SetState(State state) { | |
| 69 DCHECK(CalledOnValidThread()); | |
| 70 DCHECK_NE(state_, state); | |
| 71 state_ = state; | |
| 72 VLOG(2) << "State: " << static_cast<uint32_t>(state_); | |
| 73 if (state_ == State::RUNNING) { | |
| 74 for (auto& observer : observer_list()) | |
| 75 observer.OnSessionReady(); | |
| 76 } else if (state == State::STOPPED) { | |
| 77 for (auto& observer : observer_list()) | |
| 78 observer.OnSessionStopped(stop_reason_); | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 void ArcBridgeService::SetStopReason( | |
| 83 ArcSessionObserver::StopReason stop_reason) { | |
| 84 DCHECK(CalledOnValidThread()); | |
| 85 stop_reason_ = stop_reason; | |
| 86 } | |
| 87 | |
| 88 bool ArcBridgeService::CalledOnValidThread() { | |
| 89 return thread_checker_.CalledOnValidThread(); | |
| 90 } | 80 } |
| 91 | 81 |
| 92 } // namespace arc | 82 } // namespace arc |
| OLD | NEW |