Chromium Code Reviews| 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 #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 factory_ = factory; | |
|
Luis Héctor Chávez
2016/09/23 05:13:38
nit: maybe add a DCHECK(!factory.is_null()) to enf
hidehiko
2016/09/26 14:31:49
Done. Moved to .cc.
| |
| 47 } | |
| 48 | |
| 49 // Returns the current bootstrap instance for testing purpose. | |
| 50 ArcBridgeBootstrap* GetBootstrapForTesting() { return bootstrap_.get(); } | |
| 51 | |
| 37 // Normally, reconnecting after connection shutdown happens after a short | 52 // Normally, reconnecting after connection shutdown happens after a short |
| 38 // delay. When testing, however, we'd like it to happen immediately to avoid | 53 // delay. When testing, however, we'd like it to happen immediately to avoid |
| 39 // adding unnecessary delays. | 54 // adding unnecessary delays. |
| 40 void DisableReconnectDelayForTesting(); | 55 void DisableReconnectDelayForTesting(); |
| 41 | 56 |
| 42 private: | 57 private: |
| 43 friend class ArcBridgeTest; | 58 friend class ArcBridgeTest; |
| 44 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart); | 59 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart); |
| 45 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, OnBridgeStopped); | 60 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, OnBridgeStopped); |
| 46 | 61 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 65 // TODO(hidehiko): Move this to ArcBridgeBootstrap. | 80 // TODO(hidehiko): Move this to ArcBridgeBootstrap. |
| 66 std::unique_ptr<mojom::ArcBridgeHost> arc_bridge_host_; | 81 std::unique_ptr<mojom::ArcBridgeHost> arc_bridge_host_; |
| 67 | 82 |
| 68 // If the instance had already been started but the connection to it was | 83 // If the instance had already been started but the connection to it was |
| 69 // lost. This should make the instance restart. | 84 // lost. This should make the instance restart. |
| 70 bool reconnect_ = false; | 85 bool reconnect_ = false; |
| 71 | 86 |
| 72 // Delay the reconnection. | 87 // Delay the reconnection. |
| 73 bool use_delay_before_reconnecting_ = true; | 88 bool use_delay_before_reconnecting_ = true; |
| 74 | 89 |
| 90 // Factory to inject a fake ArcBridgeBootstrap instance for testing. | |
| 91 ArcBridgeBootstrapFactory factory_; | |
| 92 | |
| 75 // WeakPtrFactory to use callbacks. | 93 // WeakPtrFactory to use callbacks. |
| 76 base::WeakPtrFactory<ArcBridgeServiceImpl> weak_factory_; | 94 base::WeakPtrFactory<ArcBridgeServiceImpl> weak_factory_; |
| 77 | 95 |
| 78 DISALLOW_COPY_AND_ASSIGN(ArcBridgeServiceImpl); | 96 DISALLOW_COPY_AND_ASSIGN(ArcBridgeServiceImpl); |
| 79 }; | 97 }; |
| 80 | 98 |
| 81 } // namespace arc | 99 } // namespace arc |
| 82 | 100 |
| 83 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_ | 101 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_ |
| OLD | NEW |