| 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_H_ | 5 #ifndef COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ |
| 6 #define COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ | 6 #define COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/files/scoped_file.h" | 11 #include "base/files/scoped_file.h" |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "components/arc/common/arc_bridge.mojom.h" | 16 #include "components/arc/common/arc_bridge.mojom.h" |
| 17 #include "components/arc/instance_holder.h" | 17 #include "components/arc/instance_holder.h" |
| 18 | 18 |
| 19 namespace base { | 19 namespace base { |
| 20 class CommandLine; | 20 class CommandLine; |
| 21 } // namespace base | 21 } // namespace base |
| 22 | 22 |
| 23 namespace arc { | 23 namespace arc { |
| 24 | 24 |
| 25 class ArcBridgeBootstrap; | 25 class ArcBridgeBootstrap; |
| 26 | 26 |
| 27 // The Chrome-side service that handles ARC instances and ARC bridge creation. | 27 // The Chrome-side service that handles ARC instances and ARC bridge creation. |
| 28 // This service handles the lifetime of ARC instances and sets up the | 28 // This service handles the lifetime of ARC instances and sets up the |
| 29 // communication channel (the ARC bridge) used to send and receive messages. | 29 // communication channel (the ARC bridge) used to send and receive messages. |
| 30 class ArcBridgeService : public mojom::ArcBridgeHost { | 30 class ArcBridgeService { |
| 31 public: | 31 public: |
| 32 // The possible states of the bridge. In the normal flow, the state changes | 32 // The possible states of the bridge. In the normal flow, the state changes |
| 33 // in the following sequence: | 33 // in the following sequence: |
| 34 // | 34 // |
| 35 // STOPPED | 35 // STOPPED |
| 36 // PrerequisitesChanged() -> | 36 // PrerequisitesChanged() -> |
| 37 // CONNECTING | 37 // CONNECTING |
| 38 // OnConnectionEstablished() -> | 38 // OnConnectionEstablished() -> |
| 39 // READY | 39 // READY |
| 40 // | 40 // |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 virtual void OnBridgeReady() {} | 73 virtual void OnBridgeReady() {} |
| 74 virtual void OnBridgeStopped() {} | 74 virtual void OnBridgeStopped() {} |
| 75 | 75 |
| 76 // Called whenever ARC's availability has changed for this system. | 76 // Called whenever ARC's availability has changed for this system. |
| 77 virtual void OnAvailableChanged(bool available) {} | 77 virtual void OnAvailableChanged(bool available) {} |
| 78 | 78 |
| 79 protected: | 79 protected: |
| 80 virtual ~Observer() {} | 80 virtual ~Observer() {} |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 ~ArcBridgeService() override; | 83 virtual ~ArcBridgeService(); |
| 84 | 84 |
| 85 // Gets the global instance of the ARC Bridge Service. This can only be | 85 // Gets the global instance of the ARC Bridge Service. This can only be |
| 86 // called on the thread that this class was created on. | 86 // called on the thread that this class was created on. |
| 87 static ArcBridgeService* Get(); | 87 static ArcBridgeService* Get(); |
| 88 | 88 |
| 89 // Return true if ARC has been enabled through a commandline | 89 // Return true if ARC has been enabled through a commandline |
| 90 // switch. | 90 // switch. |
| 91 static bool GetEnabled(const base::CommandLine* command_line); | 91 static bool GetEnabled(const base::CommandLine* command_line); |
| 92 | 92 |
| 93 // SetDetectedAvailability() should be called once CheckArcAvailability() on | 93 // SetDetectedAvailability() should be called once CheckArcAvailability() on |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 InstanceHolder<mojom::PowerInstance>* power() { return &power_; } | 137 InstanceHolder<mojom::PowerInstance>* power() { return &power_; } |
| 138 InstanceHolder<mojom::ProcessInstance>* process() { return &process_; } | 138 InstanceHolder<mojom::ProcessInstance>* process() { return &process_; } |
| 139 InstanceHolder<mojom::StorageManagerInstance>* storage_manager() { | 139 InstanceHolder<mojom::StorageManagerInstance>* storage_manager() { |
| 140 return &storage_manager_; | 140 return &storage_manager_; |
| 141 } | 141 } |
| 142 InstanceHolder<mojom::VideoInstance>* video() { return &video_; } | 142 InstanceHolder<mojom::VideoInstance>* video() { return &video_; } |
| 143 InstanceHolder<mojom::WindowManagerInstance>* window_manager() { | 143 InstanceHolder<mojom::WindowManagerInstance>* window_manager() { |
| 144 return &window_manager_; | 144 return &window_manager_; |
| 145 } | 145 } |
| 146 | 146 |
| 147 // ArcHost: | |
| 148 void OnAppInstanceReady(mojom::AppInstancePtr app_ptr) override; | |
| 149 void OnAudioInstanceReady(mojom::AudioInstancePtr audio_ptr) override; | |
| 150 void OnAuthInstanceReady(mojom::AuthInstancePtr auth_ptr) override; | |
| 151 void OnBluetoothInstanceReady( | |
| 152 mojom::BluetoothInstancePtr bluetooth_ptr) override; | |
| 153 void OnClipboardInstanceReady( | |
| 154 mojom::ClipboardInstancePtr clipboard_ptr) override; | |
| 155 void OnCrashCollectorInstanceReady( | |
| 156 mojom::CrashCollectorInstancePtr crash_collector_ptr) override; | |
| 157 void OnFileSystemInstanceReady( | |
| 158 mojom::FileSystemInstancePtr file_system_ptr) override; | |
| 159 void OnImeInstanceReady(mojom::ImeInstancePtr ime_ptr) override; | |
| 160 void OnIntentHelperInstanceReady( | |
| 161 mojom::IntentHelperInstancePtr intent_helper_ptr) override; | |
| 162 void OnMetricsInstanceReady(mojom::MetricsInstancePtr metrics_ptr) override; | |
| 163 void OnNetInstanceReady(mojom::NetInstancePtr net_ptr) override; | |
| 164 void OnNotificationsInstanceReady( | |
| 165 mojom::NotificationsInstancePtr notifications_ptr) override; | |
| 166 void OnObbMounterInstanceReady( | |
| 167 mojom::ObbMounterInstancePtr obb_mounter_ptr) override; | |
| 168 void OnPolicyInstanceReady(mojom::PolicyInstancePtr policy_ptr) override; | |
| 169 void OnPowerInstanceReady(mojom::PowerInstancePtr power_ptr) override; | |
| 170 void OnProcessInstanceReady(mojom::ProcessInstancePtr process_ptr) override; | |
| 171 void OnStorageManagerInstanceReady( | |
| 172 mojom::StorageManagerInstancePtr storage_manager_ptr) override; | |
| 173 void OnVideoInstanceReady(mojom::VideoInstancePtr video_ptr) override; | |
| 174 void OnWindowManagerInstanceReady( | |
| 175 mojom::WindowManagerInstancePtr window_manager_ptr) override; | |
| 176 | |
| 177 // Gets the current state of the bridge service. | 147 // Gets the current state of the bridge service. |
| 178 State state() const { return state_; } | 148 State state() const { return state_; } |
| 179 | 149 |
| 180 // Gets if ARC is available in this system. | 150 // Gets if ARC is available in this system. |
| 181 bool available() const { return available_; } | 151 bool available() const { return available_; } |
| 182 | 152 |
| 183 protected: | 153 protected: |
| 184 ArcBridgeService(); | 154 ArcBridgeService(); |
| 185 | 155 |
| 186 // Changes the current state and notifies all observers. | |
| 187 void SetState(State state); | |
| 188 | |
| 189 // Changes the current availability and notifies all observers. | |
| 190 void SetAvailable(bool availability); | |
| 191 | |
| 192 base::ObserverList<Observer>& observer_list() { return observer_list_; } | |
| 193 | |
| 194 bool CalledOnValidThread(); | |
| 195 | |
| 196 // Closes all Mojo channels. | |
| 197 void CloseAllChannels(); | |
| 198 | |
| 199 private: | |
| 200 friend class ArcBridgeTest; | |
| 201 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); | |
| 202 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites); | |
| 203 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup); | |
| 204 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart); | |
| 205 | |
| 206 // Instance holders. | 156 // Instance holders. |
| 207 InstanceHolder<mojom::AppInstance> app_; | 157 InstanceHolder<mojom::AppInstance> app_; |
| 208 InstanceHolder<mojom::AudioInstance> audio_; | 158 InstanceHolder<mojom::AudioInstance> audio_; |
| 209 InstanceHolder<mojom::AuthInstance> auth_; | 159 InstanceHolder<mojom::AuthInstance> auth_; |
| 210 InstanceHolder<mojom::BluetoothInstance> bluetooth_; | 160 InstanceHolder<mojom::BluetoothInstance> bluetooth_; |
| 211 InstanceHolder<mojom::ClipboardInstance> clipboard_; | 161 InstanceHolder<mojom::ClipboardInstance> clipboard_; |
| 212 InstanceHolder<mojom::CrashCollectorInstance> crash_collector_; | 162 InstanceHolder<mojom::CrashCollectorInstance> crash_collector_; |
| 213 InstanceHolder<mojom::FileSystemInstance> file_system_; | 163 InstanceHolder<mojom::FileSystemInstance> file_system_; |
| 214 InstanceHolder<mojom::ImeInstance> ime_; | 164 InstanceHolder<mojom::ImeInstance> ime_; |
| 215 InstanceHolder<mojom::IntentHelperInstance> intent_helper_; | 165 InstanceHolder<mojom::IntentHelperInstance> intent_helper_; |
| 216 InstanceHolder<mojom::MetricsInstance> metrics_; | 166 InstanceHolder<mojom::MetricsInstance> metrics_; |
| 217 InstanceHolder<mojom::NetInstance> net_; | 167 InstanceHolder<mojom::NetInstance> net_; |
| 218 InstanceHolder<mojom::NotificationsInstance> notifications_; | 168 InstanceHolder<mojom::NotificationsInstance> notifications_; |
| 219 InstanceHolder<mojom::ObbMounterInstance> obb_mounter_; | 169 InstanceHolder<mojom::ObbMounterInstance> obb_mounter_; |
| 220 InstanceHolder<mojom::PolicyInstance> policy_; | 170 InstanceHolder<mojom::PolicyInstance> policy_; |
| 221 InstanceHolder<mojom::PowerInstance> power_; | 171 InstanceHolder<mojom::PowerInstance> power_; |
| 222 InstanceHolder<mojom::ProcessInstance> process_; | 172 InstanceHolder<mojom::ProcessInstance> process_; |
| 223 InstanceHolder<mojom::StorageManagerInstance> storage_manager_; | 173 InstanceHolder<mojom::StorageManagerInstance> storage_manager_; |
| 224 InstanceHolder<mojom::VideoInstance> video_; | 174 InstanceHolder<mojom::VideoInstance> video_; |
| 225 InstanceHolder<mojom::WindowManagerInstance> window_manager_; | 175 InstanceHolder<mojom::WindowManagerInstance> window_manager_; |
| 226 | 176 |
| 177 // Changes the current state and notifies all observers. |
| 178 void SetState(State state); |
| 179 |
| 180 // Changes the current availability and notifies all observers. |
| 181 void SetAvailable(bool availability); |
| 182 |
| 183 base::ObserverList<Observer>& observer_list() { return observer_list_; } |
| 184 |
| 185 bool CalledOnValidThread(); |
| 186 |
| 187 private: |
| 188 friend class ArcBridgeTest; |
| 189 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); |
| 190 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites); |
| 191 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup); |
| 192 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart); |
| 193 |
| 227 base::ObserverList<Observer> observer_list_; | 194 base::ObserverList<Observer> observer_list_; |
| 228 | 195 |
| 229 base::ThreadChecker thread_checker_; | 196 base::ThreadChecker thread_checker_; |
| 230 | 197 |
| 231 // If the ARC instance service is available. | 198 // If the ARC instance service is available. |
| 232 bool available_; | 199 bool available_; |
| 233 | 200 |
| 234 // The current state of the bridge. | 201 // The current state of the bridge. |
| 235 ArcBridgeService::State state_; | 202 ArcBridgeService::State state_; |
| 236 | 203 |
| 237 // WeakPtrFactory to use callbacks. | 204 // WeakPtrFactory to use callbacks. |
| 238 base::WeakPtrFactory<ArcBridgeService> weak_factory_; | 205 base::WeakPtrFactory<ArcBridgeService> weak_factory_; |
| 239 | 206 |
| 240 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); | 207 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); |
| 241 }; | 208 }; |
| 242 | 209 |
| 243 } // namespace arc | 210 } // namespace arc |
| 244 | 211 |
| 245 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ | 212 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ |
| OLD | NEW |