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

Side by Side Diff: components/arc/arc_bridge_service_impl.h

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/arc_bridge_service.cc ('k') | components/arc/arc_bridge_service_impl.cc » ('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 #ifndef COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_ 5 #ifndef COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_
6 #define COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_ 6 #define COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/files/scoped_file.h" 12 #include "base/files/scoped_file.h"
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "components/arc/arc_bridge_bootstrap.h" 15 #include "components/arc/arc_bridge_bootstrap.h"
16 #include "components/arc/arc_bridge_service.h" 16 #include "components/arc/arc_bridge_service.h"
17 #include "mojo/public/cpp/bindings/binding.h" 17 #include "mojo/public/cpp/bindings/binding.h"
18 18
19 namespace base { 19 namespace base {
20 class SequencedTaskRunner; 20 class SequencedTaskRunner;
21 class SingleThreadTaskRunner; 21 class SingleThreadTaskRunner;
22 } // namespace base 22 } // namespace base
23 23
24 namespace arc { 24 namespace arc {
25 25
26 // Real IPC based ArcBridgeService that is used in production. 26 // Real IPC based ArcBridgeService that is used in production.
27 class ArcBridgeServiceImpl : public ArcBridgeService, 27 class ArcBridgeServiceImpl : public ArcBridgeService,
28 public ArcBridgeBootstrap::Delegate { 28 public ArcBridgeBootstrap::Delegate {
29 public: 29 public:
30 explicit ArcBridgeServiceImpl(std::unique_ptr<ArcBridgeBootstrap> bootstrap); 30 // This is the factory interface to inject ArcBridgeBootstrap instance
31 // for testing purpose.
32 using ArcBridgeBootstrapFactory =
33 base::Callback<std::unique_ptr<ArcBridgeBootstrap>()>;
34
35 ArcBridgeServiceImpl();
31 ~ArcBridgeServiceImpl() override; 36 ~ArcBridgeServiceImpl() override;
32 37
33 void HandleStartup() override; 38 void HandleStartup() override;
34 39
35 void Shutdown() override; 40 void Shutdown() override;
36 41
42 // Inject a factory to create ArcBridgeBootstrap instance for testing
43 // purpose. |factory| must not be null.
44 void SetArcBridgeBootstrapFactoryForTesting(
45 const ArcBridgeBootstrapFactory& factory);
46
47 // Returns the current bootstrap instance for testing purpose.
48 ArcBridgeBootstrap* GetBootstrapForTesting() { return bootstrap_.get(); }
49
37 // Normally, reconnecting after connection shutdown happens after a short 50 // Normally, reconnecting after connection shutdown happens after a short
38 // delay. When testing, however, we'd like it to happen immediately to avoid 51 // delay. When testing, however, we'd like it to happen immediately to avoid
39 // adding unnecessary delays. 52 // adding unnecessary delays.
40 void DisableReconnectDelayForTesting(); 53 void DisableReconnectDelayForTesting();
41 54
42 private: 55 private:
43 friend class ArcBridgeTest; 56 friend class ArcBridgeTest;
44 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart); 57 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart);
45 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, OnBridgeStopped); 58 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, OnBridgeStopped);
46 59
(...skipping 18 matching lines...) Expand all
65 // TODO(hidehiko): Move this to ArcBridgeBootstrap. 78 // TODO(hidehiko): Move this to ArcBridgeBootstrap.
66 std::unique_ptr<mojom::ArcBridgeHost> arc_bridge_host_; 79 std::unique_ptr<mojom::ArcBridgeHost> arc_bridge_host_;
67 80
68 // If the instance had already been started but the connection to it was 81 // If the instance had already been started but the connection to it was
69 // lost. This should make the instance restart. 82 // lost. This should make the instance restart.
70 bool reconnect_ = false; 83 bool reconnect_ = false;
71 84
72 // Delay the reconnection. 85 // Delay the reconnection.
73 bool use_delay_before_reconnecting_ = true; 86 bool use_delay_before_reconnecting_ = true;
74 87
88 // Factory to inject a fake ArcBridgeBootstrap instance for testing.
89 ArcBridgeBootstrapFactory factory_;
90
75 // WeakPtrFactory to use callbacks. 91 // WeakPtrFactory to use callbacks.
76 base::WeakPtrFactory<ArcBridgeServiceImpl> weak_factory_; 92 base::WeakPtrFactory<ArcBridgeServiceImpl> weak_factory_;
77 93
78 DISALLOW_COPY_AND_ASSIGN(ArcBridgeServiceImpl); 94 DISALLOW_COPY_AND_ASSIGN(ArcBridgeServiceImpl);
79 }; 95 };
80 96
81 } // namespace arc 97 } // namespace arc
82 98
83 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_ 99 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_
OLDNEW
« no previous file with comments | « components/arc/arc_bridge_service.cc ('k') | components/arc/arc_bridge_service_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698