| OLD | NEW |
| 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 #ifndef COMPONENTS_ARC_ARC_BRIDGE_HOST_IMPL_H_ | 5 #ifndef COMPONENTS_ARC_ARC_BRIDGE_HOST_IMPL_H_ |
| 6 #define COMPONENTS_ARC_ARC_BRIDGE_HOST_IMPL_H_ | 6 #define COMPONENTS_ARC_ARC_BRIDGE_HOST_IMPL_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/threading/thread_checker.h" | 12 #include "base/threading/thread_checker.h" |
| 13 #include "components/arc/common/arc_bridge.mojom.h" | 13 #include "components/arc/common/arc_bridge.mojom.h" |
| 14 #include "components/arc/instance_holder.h" | 14 #include "components/arc/instance_holder.h" |
| 15 #include "mojo/public/cpp/bindings/binding.h" | 15 #include "mojo/public/cpp/bindings/binding.h" |
| 16 #include "mojo/public/cpp/bindings/interface_ptr.h" | 16 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 17 | 17 |
| 18 namespace arc { | 18 namespace arc { |
| 19 | 19 |
| 20 class ArcBridgeService; |
| 21 |
| 20 // Implementation of the ArcBridgeHost. | 22 // Implementation of the ArcBridgeHost. |
| 21 // The lifetime of ArcBridgeHost and ArcBridgeInstance mojo channels are tied | 23 // The lifetime of ArcBridgeHost and ArcBridgeInstance mojo channels are tied |
| 22 // to this instance. Also, any ARC related Mojo channel will be closed if | 24 // to this instance. Also, any ARC related Mojo channel will be closed if |
| 23 // either ArcBridgeHost or ArcBridgeInstance Mojo channels is closed on error. | 25 // either ArcBridgeHost or ArcBridgeInstance Mojo channels is closed on error. |
| 24 // When ARC Instance (not Host) Mojo channel gets ready (= passed via | 26 // When ARC Instance (not Host) Mojo channel gets ready (= passed via |
| 25 // OnFooInstanceReady(), and the QueryVersion() gets completed), then this sets | 27 // OnFooInstanceReady(), and the QueryVersion() gets completed), then this sets |
| 26 // the raw pointer to the ArcBridgeService so that other services can access | 28 // the raw pointer to the ArcBridgeService so that other services can access |
| 27 // to the pointer, and resets it on channel closing. | 29 // to the pointer, and resets it on channel closing. |
| 28 // Note that ArcBridgeService must be alive while ArcBridgeHostImpl is alive. | 30 // Note that ArcBridgeService must be alive while ArcBridgeHostImpl is alive. |
| 29 class ArcBridgeHostImpl : public mojom::ArcBridgeHost { | 31 class ArcBridgeHostImpl : public mojom::ArcBridgeHost { |
| 30 public: | 32 public: |
| 31 // Interface to keep the Mojo channel InterfacePtr. | 33 // Interface to keep the Mojo channel InterfacePtr. |
| 32 class MojoChannel; | 34 class MojoChannel; |
| 33 | 35 |
| 34 explicit ArcBridgeHostImpl(mojom::ArcBridgeInstancePtr instance); | 36 ArcBridgeHostImpl(ArcBridgeService* arc_bridge_service, |
| 37 mojom::ArcBridgeInstancePtr instance); |
| 35 ~ArcBridgeHostImpl() override; | 38 ~ArcBridgeHostImpl() override; |
| 36 | 39 |
| 37 // ArcBridgeHost overrides. | 40 // ArcBridgeHost overrides. |
| 38 void OnAppInstanceReady(mojom::AppInstancePtr app_ptr) override; | 41 void OnAppInstanceReady(mojom::AppInstancePtr app_ptr) override; |
| 39 void OnAudioInstanceReady(mojom::AudioInstancePtr audio_ptr) override; | 42 void OnAudioInstanceReady(mojom::AudioInstancePtr audio_ptr) override; |
| 40 void OnAuthInstanceReady(mojom::AuthInstancePtr auth_ptr) override; | 43 void OnAuthInstanceReady(mojom::AuthInstancePtr auth_ptr) override; |
| 41 void OnBluetoothInstanceReady( | 44 void OnBluetoothInstanceReady( |
| 42 mojom::BluetoothInstancePtr bluetooth_ptr) override; | 45 mojom::BluetoothInstancePtr bluetooth_ptr) override; |
| 43 void OnBootPhaseMonitorInstanceReady( | 46 void OnBootPhaseMonitorInstanceReady( |
| 44 mojom::BootPhaseMonitorInstancePtr boot_phase_monitor_ptr) override; | 47 mojom::BootPhaseMonitorInstancePtr boot_phase_monitor_ptr) override; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 // The common implementation to handle ArcBridgeHost overrides. | 82 // The common implementation to handle ArcBridgeHost overrides. |
| 80 // |T| is a ARC Mojo Instance type. | 83 // |T| is a ARC Mojo Instance type. |
| 81 template <typename T> | 84 template <typename T> |
| 82 void OnInstanceReady(InstanceHolder<T>* holder, mojo::InterfacePtr<T> ptr); | 85 void OnInstanceReady(InstanceHolder<T>* holder, mojo::InterfacePtr<T> ptr); |
| 83 | 86 |
| 84 // Called if one of the established channels is closed. | 87 // Called if one of the established channels is closed. |
| 85 void OnChannelClosed(MojoChannel* channel); | 88 void OnChannelClosed(MojoChannel* channel); |
| 86 | 89 |
| 87 base::ThreadChecker thread_checker_; | 90 base::ThreadChecker thread_checker_; |
| 88 | 91 |
| 92 // Owned by ArcServiceManager. |
| 93 ArcBridgeService* const arc_bridge_service_; |
| 94 |
| 89 mojo::Binding<mojom::ArcBridgeHost> binding_; | 95 mojo::Binding<mojom::ArcBridgeHost> binding_; |
| 90 mojom::ArcBridgeInstancePtr instance_; | 96 mojom::ArcBridgeInstancePtr instance_; |
| 91 | 97 |
| 92 // Put as a last member to ensure that any callback tied to the elements | 98 // Put as a last member to ensure that any callback tied to the elements |
| 93 // is not invoked. | 99 // is not invoked. |
| 94 std::vector<std::unique_ptr<MojoChannel>> mojo_channels_; | 100 std::vector<std::unique_ptr<MojoChannel>> mojo_channels_; |
| 95 | 101 |
| 96 DISALLOW_COPY_AND_ASSIGN(ArcBridgeHostImpl); | 102 DISALLOW_COPY_AND_ASSIGN(ArcBridgeHostImpl); |
| 97 }; | 103 }; |
| 98 | 104 |
| 99 } // namespace arc | 105 } // namespace arc |
| 100 | 106 |
| 101 #endif // COMPONENTS_ARC_ARC_BRIDGE_HOST_IMPL_H_ | 107 #endif // COMPONENTS_ARC_ARC_BRIDGE_HOST_IMPL_H_ |
| OLD | NEW |