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 delegate interface for testing purpose only. |
| 31 class Delegate { | |
|
Luis Héctor Chávez
2016/09/07 23:38:32
Wouldn't this make more sense to be called "Factor
hidehiko
2016/09/08 16:53:41
Replaced by Factory style with base::Callback.
Can
Luis Héctor Chávez
2016/09/15 23:08:49
Sure, after the refactor and in callback-style it
| |
| 32 public: | |
| 33 // Creates ArcBridgeBootstrap instance. | |
| 34 virtual std::unique_ptr<ArcBridgeBootstrap> CreateBootstrap() = 0; | |
|
Luis Héctor Chávez
2016/09/07 23:38:32
this needs a virtual destructor.
hidehiko
2016/09/08 16:53:41
Acknowledged.
| |
| 35 }; | |
| 36 | |
| 37 ArcBridgeServiceImpl(); | |
| 31 ~ArcBridgeServiceImpl() override; | 38 ~ArcBridgeServiceImpl() override; |
| 32 | 39 |
| 33 void HandleStartup() override; | 40 void HandleStartup() override; |
| 34 | 41 |
| 35 void Shutdown() override; | 42 void Shutdown() override; |
| 36 | 43 |
| 44 // |delegate| is managed by the caller. This is only for testing purpose. | |
| 45 void SetDelegateForTesting(Delegate* delegate) { delegate_ = delegate; } | |
| 46 | |
| 37 // Normally, reconnecting after connection shutdown happens after a short | 47 // Normally, reconnecting after connection shutdown happens after a short |
| 38 // delay. When testing, however, we'd like it to happen immediately to avoid | 48 // delay. When testing, however, we'd like it to happen immediately to avoid |
| 39 // adding unnecessary delays. | 49 // adding unnecessary delays. |
| 40 void DisableReconnectDelayForTesting(); | 50 void DisableReconnectDelayForTesting(); |
| 41 | 51 |
| 42 private: | 52 private: |
| 43 friend class ArcBridgeTest; | 53 friend class ArcBridgeTest; |
| 44 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart); | 54 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart); |
| 45 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, OnBridgeStopped); | 55 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, OnBridgeStopped); |
| 46 | 56 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 65 // TODO(hidehiko): Move this to ArcBridgeBootstrap. | 75 // TODO(hidehiko): Move this to ArcBridgeBootstrap. |
| 66 std::unique_ptr<mojom::ArcBridgeHost> arc_bridge_host_; | 76 std::unique_ptr<mojom::ArcBridgeHost> arc_bridge_host_; |
| 67 | 77 |
| 68 // If the instance had already been started but the connection to it was | 78 // If the instance had already been started but the connection to it was |
| 69 // lost. This should make the instance restart. | 79 // lost. This should make the instance restart. |
| 70 bool reconnect_ = false; | 80 bool reconnect_ = false; |
| 71 | 81 |
| 72 // Delay the reconnection. | 82 // Delay the reconnection. |
| 73 bool use_delay_before_reconnecting_ = true; | 83 bool use_delay_before_reconnecting_ = true; |
| 74 | 84 |
| 85 // Delegate to inject a fake ArcBridgeBootstrap instance for testing. | |
| 86 Delegate* delegate_ = nullptr; | |
|
Luis Héctor Chávez
2016/09/07 23:38:32
If you make the Delegate a Factory, maybe make thi
hidehiko
2016/09/08 16:53:41
Replaced by Callback, and now life-time should be
| |
| 87 | |
| 75 // WeakPtrFactory to use callbacks. | 88 // WeakPtrFactory to use callbacks. |
| 76 base::WeakPtrFactory<ArcBridgeServiceImpl> weak_factory_; | 89 base::WeakPtrFactory<ArcBridgeServiceImpl> weak_factory_; |
| 77 | 90 |
| 78 DISALLOW_COPY_AND_ASSIGN(ArcBridgeServiceImpl); | 91 DISALLOW_COPY_AND_ASSIGN(ArcBridgeServiceImpl); |
| 79 }; | 92 }; |
| 80 | 93 |
| 81 } // namespace arc | 94 } // namespace arc |
| 82 | 95 |
| 83 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_ | 96 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_ |
| OLD | NEW |