| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/test/fake_arc_bridge_bootstrap.h" | 5 #include "components/arc/test/fake_arc_bridge_bootstrap.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | |
| 9 | 8 |
| 10 #include "base/logging.h" | 9 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 12 | 11 |
| 13 namespace arc { | 12 namespace arc { |
| 14 | 13 |
| 15 FakeArcBridgeBootstrap::FakeArcBridgeBootstrap() = default; | 14 FakeArcBridgeBootstrap::FakeArcBridgeBootstrap() = default; |
| 16 | 15 |
| 17 FakeArcBridgeBootstrap::~FakeArcBridgeBootstrap() = default; | 16 FakeArcBridgeBootstrap::~FakeArcBridgeBootstrap() = default; |
| 18 | 17 |
| 19 void FakeArcBridgeBootstrap::Start() { | 18 void FakeArcBridgeBootstrap::Start() { |
| 20 DCHECK(delegate_); | |
| 21 if (boot_failure_emulation_enabled_) { | 19 if (boot_failure_emulation_enabled_) { |
| 22 delegate_->OnStopped(boot_failure_reason_); | 20 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 21 OnStopped(boot_failure_reason_)); |
| 23 } else if (!boot_suspended_) { | 22 } else if (!boot_suspended_) { |
| 24 mojom::ArcBridgeInstancePtr instance_ptr; | 23 FOR_EACH_OBSERVER(Observer, observer_list_, OnReady()); |
| 25 instance_.Bind(mojo::GetProxy(&instance_ptr)); | |
| 26 delegate_->OnConnectionEstablished(std::move(instance_ptr)); | |
| 27 } | 24 } |
| 28 } | 25 } |
| 29 | 26 |
| 30 void FakeArcBridgeBootstrap::Stop() { | 27 void FakeArcBridgeBootstrap::Stop() { |
| 31 StopWithReason(ArcBridgeService::StopReason::SHUTDOWN); | 28 StopWithReason(ArcBridgeService::StopReason::SHUTDOWN); |
| 32 } | 29 } |
| 33 | 30 |
| 34 void FakeArcBridgeBootstrap::StopWithReason( | 31 void FakeArcBridgeBootstrap::StopWithReason( |
| 35 ArcBridgeService::StopReason reason) { | 32 ArcBridgeService::StopReason reason) { |
| 36 DCHECK(delegate_); | 33 FOR_EACH_OBSERVER(Observer, observer_list_, OnStopped(reason)); |
| 37 instance_.Unbind(); | |
| 38 delegate_->OnStopped(reason); | |
| 39 } | 34 } |
| 40 | 35 |
| 41 void FakeArcBridgeBootstrap::EnableBootFailureEmulation( | 36 void FakeArcBridgeBootstrap::EnableBootFailureEmulation( |
| 42 ArcBridgeService::StopReason reason) { | 37 ArcBridgeService::StopReason reason) { |
| 43 DCHECK(!boot_failure_emulation_enabled_); | 38 DCHECK(!boot_failure_emulation_enabled_); |
| 44 DCHECK(!boot_suspended_); | 39 DCHECK(!boot_suspended_); |
| 45 | 40 |
| 46 boot_failure_emulation_enabled_ = true; | 41 boot_failure_emulation_enabled_ = true; |
| 47 boot_failure_reason_ = reason; | 42 boot_failure_reason_ = reason; |
| 48 } | 43 } |
| 49 | 44 |
| 50 void FakeArcBridgeBootstrap::SuspendBoot() { | 45 void FakeArcBridgeBootstrap::SuspendBoot() { |
| 51 DCHECK(!boot_failure_emulation_enabled_); | 46 DCHECK(!boot_failure_emulation_enabled_); |
| 52 DCHECK(!boot_suspended_); | 47 DCHECK(!boot_suspended_); |
| 53 | 48 |
| 54 boot_suspended_ = true; | 49 boot_suspended_ = true; |
| 55 } | 50 } |
| 56 | 51 |
| 57 // static | 52 // static |
| 58 std::unique_ptr<ArcBridgeBootstrap> FakeArcBridgeBootstrap::Create() { | 53 std::unique_ptr<ArcBridgeBootstrap> FakeArcBridgeBootstrap::Create() { |
| 59 return base::MakeUnique<FakeArcBridgeBootstrap>(); | 54 return base::MakeUnique<FakeArcBridgeBootstrap>(); |
| 60 } | 55 } |
| 61 | 56 |
| 62 } // namespace arc | 57 } // namespace arc |
| OLD | NEW |