| 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> | |
| 10 #include <vector> | |
| 11 | 9 |
| 12 #include "base/files/scoped_file.h" | |
| 13 #include "base/gtest_prod_util.h" | |
| 14 #include "base/macros.h" | 10 #include "base/macros.h" |
| 15 #include "components/arc/arc_bridge_bootstrap.h" | 11 #include "components/arc/arc_bridge_bootstrap.h" |
| 16 #include "components/arc/arc_bridge_service.h" | 12 #include "components/arc/arc_bridge_service.h" |
| 17 #include "mojo/public/cpp/bindings/binding.h" | |
| 18 | 13 |
| 19 namespace base { | 14 namespace base { |
| 20 class SequencedTaskRunner; | 15 class SequencedTaskRunner; |
| 21 class SingleThreadTaskRunner; | 16 class SingleThreadTaskRunner; |
| 22 } // namespace base | 17 } // namespace base |
| 23 | 18 |
| 24 namespace arc { | 19 namespace arc { |
| 25 | 20 |
| 26 // Real IPC based ArcBridgeService that is used in production. | 21 // Real IPC based ArcBridgeService that is used in production. |
| 27 class ArcBridgeServiceImpl : public ArcBridgeService, | 22 class ArcBridgeServiceImpl : public ArcBridgeService, |
| 28 public ArcBridgeBootstrap::Delegate { | 23 public ArcBridgeBootstrap::Delegate { |
| 29 public: | 24 public: |
| 30 explicit ArcBridgeServiceImpl(std::unique_ptr<ArcBridgeBootstrap> bootstrap); | 25 // This is the delegate interface for testing purpose only. |
| 26 class Delegate { |
| 27 public: |
| 28 // Creates ArcBridgeBootstrap instance. |
| 29 virtual std::unique_ptr<ArcBridgeBootstrap> CreateBootstrap() = 0; |
| 30 }; |
| 31 |
| 32 ArcBridgeServiceImpl(); |
| 31 ~ArcBridgeServiceImpl() override; | 33 ~ArcBridgeServiceImpl() override; |
| 32 | 34 |
| 33 void HandleStartup() override; | 35 void HandleStartup() override; |
| 34 | 36 |
| 35 void Shutdown() override; | 37 void Shutdown() override; |
| 36 | 38 |
| 39 // |delegate| is managed by the caller. This is only for testing purpose. |
| 40 void SetDelegateForTesting(Delegate* delegate) { delegate_ = delegate; } |
| 41 |
| 37 // Normally, reconnecting after connection shutdown happens after a short | 42 // Normally, reconnecting after connection shutdown happens after a short |
| 38 // delay. When testing, however, we'd like it to happen immediately to avoid | 43 // delay. When testing, however, we'd like it to happen immediately to avoid |
| 39 // adding unnecessary delays. | 44 // adding unnecessary delays. |
| 40 void DisableReconnectDelayForTesting(); | 45 void DisableReconnectDelayForTesting(); |
| 41 | 46 |
| 42 private: | 47 private: |
| 43 friend class ArcBridgeTest; | |
| 44 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart); | |
| 45 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, OnBridgeStopped); | |
| 46 | |
| 47 // If all pre-requisites are true (ARC is available, it has been enabled, and | 48 // If all pre-requisites are true (ARC is available, it has been enabled, and |
| 48 // the session has started), and ARC is stopped, start ARC. If ARC is running | 49 // the session has started), and ARC is stopped, start ARC. If ARC is running |
| 49 // and the pre-requisites stop being true, stop ARC. | 50 // and the pre-requisites stop being true, stop ARC. |
| 50 void PrerequisitesChanged(); | 51 void PrerequisitesChanged(); |
| 51 | 52 |
| 52 // Stops the running instance. | 53 // Stops the running instance. |
| 53 void StopInstance(); | 54 void StopInstance(); |
| 54 | 55 |
| 55 // ArcBridgeBootstrap::Delegate: | 56 // ArcBridgeBootstrap::Delegate: |
| 56 void OnConnectionEstablished(mojom::ArcBridgeInstancePtr instance) override; | 57 void OnReady() override; |
| 57 void OnStopped(StopReason reason) override; | 58 void OnStopped(StopReason reason) override; |
| 58 | 59 |
| 59 std::unique_ptr<ArcBridgeBootstrap> bootstrap_; | 60 std::unique_ptr<ArcBridgeBootstrap> bootstrap_; |
| 60 | 61 |
| 61 // If the user's session has started. | 62 // If the user's session has started. |
| 62 bool session_started_; | 63 bool session_started_ = false; |
| 63 | |
| 64 // Mojo endpoint. | |
| 65 // TODO(hidehiko): Move this to ArcBridgeBootstrap. | |
| 66 std::unique_ptr<mojom::ArcBridgeHost> arc_bridge_host_; | |
| 67 | 64 |
| 68 // If the instance had already been started but the connection to it was | 65 // If the instance had already been started but the connection to it was |
| 69 // lost. This should make the instance restart. | 66 // lost. This should make the instance restart. |
| 70 bool reconnect_ = false; | 67 bool reconnect_ = false; |
| 71 | 68 |
| 72 // Delay the reconnection. | 69 // Delay the reconnection. |
| 73 bool use_delay_before_reconnecting_ = true; | 70 bool use_delay_before_reconnecting_ = true; |
| 74 | 71 |
| 72 // Delegate to inject a fake ArcBridgeBootstrap instance for testing. |
| 73 Delegate* delegate_ = nullptr; |
| 74 |
| 75 // WeakPtrFactory to use callbacks. | 75 // WeakPtrFactory to use callbacks. |
| 76 base::WeakPtrFactory<ArcBridgeServiceImpl> weak_factory_; | 76 base::WeakPtrFactory<ArcBridgeServiceImpl> weak_factory_; |
| 77 | 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(ArcBridgeServiceImpl); | 78 DISALLOW_COPY_AND_ASSIGN(ArcBridgeServiceImpl); |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 } // namespace arc | 81 } // namespace arc |
| 82 | 82 |
| 83 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_ | 83 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_ |
| OLD | NEW |