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

Side by Side Diff: components/arc/test/fake_arc_bridge_bootstrap.cc

Issue 2194193002: Fix ArcBridgeBootstrap race issues. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 2 months 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/test/fake_arc_bridge_bootstrap.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <utility> 8 #include <utility>
8 9
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "components/arc/common/arc_bridge.mojom.h" 11 #include "base/memory/ptr_util.h"
11 #include "components/arc/test/fake_arc_bridge_instance.h"
12 #include "mojo/public/cpp/bindings/interface_request.h"
13 12
14 namespace arc { 13 namespace arc {
15 14
16 FakeArcBridgeBootstrap::FakeArcBridgeBootstrap(FakeArcBridgeInstance* instance) 15 FakeArcBridgeBootstrap::FakeArcBridgeBootstrap() = default;
17 : instance_(instance) { 16
18 instance_->set_delegate(this); 17 FakeArcBridgeBootstrap::~FakeArcBridgeBootstrap() = default;
19 }
20 18
21 void FakeArcBridgeBootstrap::Start() { 19 void FakeArcBridgeBootstrap::Start() {
22 DCHECK(delegate_); 20 DCHECK(delegate_);
23 mojom::ArcBridgeInstancePtr instance; 21 if (boot_failure_emulation_enabled_) {
24 instance_->Bind(mojo::GetProxy(&instance)); 22 delegate_->OnStopped(boot_failure_reason_);
25 delegate_->OnConnectionEstablished(std::move(instance)); 23 } else if (!boot_suspended_) {
24 mojom::ArcBridgeInstancePtr instance_ptr;
25 instance_.Bind(mojo::GetProxy(&instance_ptr));
26 delegate_->OnConnectionEstablished(std::move(instance_ptr));
27 }
26 } 28 }
27 29
28 void FakeArcBridgeBootstrap::Stop() { 30 void FakeArcBridgeBootstrap::Stop() {
29 DCHECK(delegate_); 31 StopWithReason(ArcBridgeService::StopReason::SHUTDOWN);
30 instance_->Unbind();
31 delegate_->OnStopped(ArcBridgeService::StopReason::SHUTDOWN);
32 } 32 }
33 33
34 void FakeArcBridgeBootstrap::OnStopped(ArcBridgeService::StopReason reason) { 34 void FakeArcBridgeBootstrap::StopWithReason(
35 ArcBridgeService::StopReason reason) {
35 DCHECK(delegate_); 36 DCHECK(delegate_);
36 instance_->Unbind(); 37 instance_.Unbind();
37 delegate_->OnStopped(reason); 38 delegate_->OnStopped(reason);
38 } 39 }
39 40
41 void FakeArcBridgeBootstrap::EnableBootFailureEmulation(
42 ArcBridgeService::StopReason reason) {
43 DCHECK(!boot_failure_emulation_enabled_);
44 DCHECK(!boot_suspended_);
45
46 boot_failure_emulation_enabled_ = true;
47 boot_failure_reason_ = reason;
48 }
49
50 void FakeArcBridgeBootstrap::SuspendBoot() {
51 DCHECK(!boot_failure_emulation_enabled_);
52 DCHECK(!boot_suspended_);
53
54 boot_suspended_ = true;
55 }
56
57 // static
58 std::unique_ptr<ArcBridgeBootstrap> FakeArcBridgeBootstrap::Create() {
59 return base::MakeUnique<FakeArcBridgeBootstrap>();
60 }
61
40 } // namespace arc 62 } // namespace arc
OLDNEW
« no previous file with comments | « components/arc/test/fake_arc_bridge_bootstrap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698