| 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/test/fake_arc_bridge_instance.h" | 5 #include "components/arc/test/fake_arc_bridge_instance.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/run_loop.h" |
| 10 |
| 9 namespace arc { | 11 namespace arc { |
| 10 | 12 |
| 11 FakeArcBridgeInstance::FakeArcBridgeInstance() : binding_(this) {} | 13 FakeArcBridgeInstance::FakeArcBridgeInstance() : binding_(this) {} |
| 12 FakeArcBridgeInstance::~FakeArcBridgeInstance() {} | 14 FakeArcBridgeInstance::~FakeArcBridgeInstance() {} |
| 13 | 15 |
| 14 void FakeArcBridgeInstance::Init(mojom::ArcBridgeHostPtr host) { | 16 void FakeArcBridgeInstance::Init(mojom::ArcBridgeHostPtr host) { |
| 15 host_ptr_ = std::move(host); | 17 host_ptr_ = std::move(host); |
| 16 init_calls_++; | 18 init_calls_++; |
| 19 |
| 20 // Wake WaitForInitCall(). |
| 21 if (!quit_closure_.is_null()) |
| 22 quit_closure_.Run(); |
| 23 quit_closure_.Reset(); |
| 17 } | 24 } |
| 18 | 25 |
| 19 void FakeArcBridgeInstance::Unbind() { | 26 void FakeArcBridgeInstance::Unbind() { |
| 20 host_ptr_.reset(); | 27 host_ptr_.reset(); |
| 21 if (binding_.is_bound()) | 28 if (binding_.is_bound()) |
| 22 binding_.Close(); | 29 binding_.Close(); |
| 23 } | 30 } |
| 24 | 31 |
| 25 void FakeArcBridgeInstance::Bind( | 32 void FakeArcBridgeInstance::Bind( |
| 26 mojo::InterfaceRequest<mojom::ArcBridgeInstance> interface_request) { | 33 mojo::InterfaceRequest<mojom::ArcBridgeInstance> interface_request) { |
| 27 binding_.Bind(std::move(interface_request)); | 34 binding_.Bind(std::move(interface_request)); |
| 28 } | 35 } |
| 29 | 36 |
| 30 void FakeArcBridgeInstance::WaitForInitCall() { | 37 void FakeArcBridgeInstance::WaitForInitCall() { |
| 31 binding_.WaitForIncomingMethodCall(); | 38 base::RunLoop run_loop; |
| 39 quit_closure_ = run_loop.QuitClosure(); |
| 40 binding_.set_connection_error_handler(run_loop.QuitClosure()); |
| 41 run_loop.Run(); |
| 32 } | 42 } |
| 33 | 43 |
| 34 void FakeArcBridgeInstance::Stop(ArcBridgeService::StopReason reason) { | 44 void FakeArcBridgeInstance::Stop(ArcBridgeService::StopReason reason) { |
| 35 if (!delegate_) | 45 if (!delegate_) |
| 36 return; | 46 return; |
| 37 delegate_->OnStopped(reason); | 47 delegate_->OnStopped(reason); |
| 38 } | 48 } |
| 39 | 49 |
| 40 } // namespace arc | 50 } // namespace arc |
| OLD | NEW |