| 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 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 } // namespace base | 21 } // namespace base |
| 22 | 22 |
| 23 namespace arc { | 23 namespace arc { |
| 24 | 24 |
| 25 class ArcBridgeBootstrap; | 25 class ArcBridgeBootstrap; |
| 26 class ArcBridgeTest; | 26 class ArcBridgeTest; |
| 27 | 27 |
| 28 // The Chrome-side service that handles ARC instances and ARC bridge creation. | 28 // The Chrome-side service that handles ARC instances and ARC bridge creation. |
| 29 // This service handles the lifetime of ARC instances and sets up the | 29 // This service handles the lifetime of ARC instances and sets up the |
| 30 // communication channel (the ARC bridge) used to send and receive messages. | 30 // communication channel (the ARC bridge) used to send and receive messages. |
| 31 class ArcBridgeService : public mojom::ArcBridgeHost { | 31 class ArcBridgeService { |
| 32 public: | 32 public: |
| 33 // Notifies life cycle events of ArcBridgeService. | 33 // Notifies life cycle events of ArcBridgeService. |
| 34 class Observer { | 34 class Observer { |
| 35 public: | 35 public: |
| 36 // Called whenever the state of the bridge has changed. | 36 // Called whenever the state of the bridge has changed. |
| 37 virtual void OnBridgeReady() {} | 37 virtual void OnBridgeReady() {} |
| 38 virtual void OnBridgeStopped() {} | 38 virtual void OnBridgeStopped() {} |
| 39 | 39 |
| 40 // Called whenever ARC's availability has changed for this system. | 40 // Called whenever ARC's availability has changed for this system. |
| 41 virtual void OnAvailableChanged(bool available) {} | 41 virtual void OnAvailableChanged(bool available) {} |
| 42 | 42 |
| 43 protected: | 43 protected: |
| 44 virtual ~Observer() {} | 44 virtual ~Observer() {} |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 ~ArcBridgeService() override; | 47 virtual ~ArcBridgeService(); |
| 48 | 48 |
| 49 // Gets the global instance of the ARC Bridge Service. This can only be | 49 // Gets the global instance of the ARC Bridge Service. This can only be |
| 50 // called on the thread that this class was created on. | 50 // called on the thread that this class was created on. |
| 51 static ArcBridgeService* Get(); | 51 static ArcBridgeService* Get(); |
| 52 | 52 |
| 53 // Return true if ARC has been enabled through a commandline | 53 // Return true if ARC has been enabled through a commandline |
| 54 // switch. | 54 // switch. |
| 55 static bool GetEnabled(const base::CommandLine* command_line); | 55 static bool GetEnabled(const base::CommandLine* command_line); |
| 56 | 56 |
| 57 // SetDetectedAvailability() should be called once CheckArcAvailability() on | 57 // SetDetectedAvailability() should be called once CheckArcAvailability() on |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 InstanceHolder<mojom::PowerInstance>* power() { return &power_; } | 101 InstanceHolder<mojom::PowerInstance>* power() { return &power_; } |
| 102 InstanceHolder<mojom::ProcessInstance>* process() { return &process_; } | 102 InstanceHolder<mojom::ProcessInstance>* process() { return &process_; } |
| 103 InstanceHolder<mojom::StorageManagerInstance>* storage_manager() { | 103 InstanceHolder<mojom::StorageManagerInstance>* storage_manager() { |
| 104 return &storage_manager_; | 104 return &storage_manager_; |
| 105 } | 105 } |
| 106 InstanceHolder<mojom::VideoInstance>* video() { return &video_; } | 106 InstanceHolder<mojom::VideoInstance>* video() { return &video_; } |
| 107 InstanceHolder<mojom::WindowManagerInstance>* window_manager() { | 107 InstanceHolder<mojom::WindowManagerInstance>* window_manager() { |
| 108 return &window_manager_; | 108 return &window_manager_; |
| 109 } | 109 } |
| 110 | 110 |
| 111 // ArcHost: | |
| 112 void OnAppInstanceReady(mojom::AppInstancePtr app_ptr) override; | |
| 113 void OnAudioInstanceReady(mojom::AudioInstancePtr audio_ptr) override; | |
| 114 void OnAuthInstanceReady(mojom::AuthInstancePtr auth_ptr) override; | |
| 115 void OnBluetoothInstanceReady( | |
| 116 mojom::BluetoothInstancePtr bluetooth_ptr) override; | |
| 117 void OnClipboardInstanceReady( | |
| 118 mojom::ClipboardInstancePtr clipboard_ptr) override; | |
| 119 void OnCrashCollectorInstanceReady( | |
| 120 mojom::CrashCollectorInstancePtr crash_collector_ptr) override; | |
| 121 void OnFileSystemInstanceReady( | |
| 122 mojom::FileSystemInstancePtr file_system_ptr) override; | |
| 123 void OnImeInstanceReady(mojom::ImeInstancePtr ime_ptr) override; | |
| 124 void OnIntentHelperInstanceReady( | |
| 125 mojom::IntentHelperInstancePtr intent_helper_ptr) override; | |
| 126 void OnMetricsInstanceReady(mojom::MetricsInstancePtr metrics_ptr) override; | |
| 127 void OnNetInstanceReady(mojom::NetInstancePtr net_ptr) override; | |
| 128 void OnNotificationsInstanceReady( | |
| 129 mojom::NotificationsInstancePtr notifications_ptr) override; | |
| 130 void OnObbMounterInstanceReady( | |
| 131 mojom::ObbMounterInstancePtr obb_mounter_ptr) override; | |
| 132 void OnPolicyInstanceReady(mojom::PolicyInstancePtr policy_ptr) override; | |
| 133 void OnPowerInstanceReady(mojom::PowerInstancePtr power_ptr) override; | |
| 134 void OnProcessInstanceReady(mojom::ProcessInstancePtr process_ptr) override; | |
| 135 void OnStorageManagerInstanceReady( | |
| 136 mojom::StorageManagerInstancePtr storage_manager_ptr) override; | |
| 137 void OnVideoInstanceReady(mojom::VideoInstancePtr video_ptr) override; | |
| 138 void OnWindowManagerInstanceReady( | |
| 139 mojom::WindowManagerInstancePtr window_manager_ptr) override; | |
| 140 | |
| 141 // Gets if ARC is available in this system. | 111 // Gets if ARC is available in this system. |
| 142 bool available() const { return available_; } | 112 bool available() const { return available_; } |
| 143 | 113 |
| 144 // Gets if ARC is currently running. | 114 // Gets if ARC is currently running. |
| 145 bool ready() const { return state() == State::READY; } | 115 bool ready() const { return state() == State::READY; } |
| 146 | 116 |
| 147 // Gets if ARC is currently stopped. This is not exactly !ready() since there | 117 // Gets if ARC is currently stopped. This is not exactly !ready() since there |
| 148 // are transient states between ready() and stopped(). | 118 // are transient states between ready() and stopped(). |
| 149 bool stopped() const { return state() == State::STOPPED; } | 119 bool stopped() const { return state() == State::STOPPED; } |
| 150 | 120 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 179 // The ARC instance has finished initializing and is now ready for user | 149 // The ARC instance has finished initializing and is now ready for user |
| 180 // interaction. | 150 // interaction. |
| 181 READY, | 151 READY, |
| 182 | 152 |
| 183 // The ARC instance has started shutting down. | 153 // The ARC instance has started shutting down. |
| 184 STOPPING, | 154 STOPPING, |
| 185 }; | 155 }; |
| 186 | 156 |
| 187 ArcBridgeService(); | 157 ArcBridgeService(); |
| 188 | 158 |
| 189 // Gets the current state of the bridge service. | |
| 190 State state() const { return state_; } | |
| 191 | |
| 192 // Changes the current state and notifies all observers. | |
| 193 void SetState(State state); | |
| 194 | |
| 195 // Changes the current availability and notifies all observers. | |
| 196 void SetAvailable(bool availability); | |
| 197 | |
| 198 base::ObserverList<Observer>& observer_list() { return observer_list_; } | |
| 199 | |
| 200 bool CalledOnValidThread(); | |
| 201 | |
| 202 // Closes all Mojo channels. | |
| 203 void CloseAllChannels(); | |
| 204 | |
| 205 private: | |
| 206 friend class ArcBridgeTest; | |
| 207 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); | |
| 208 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites); | |
| 209 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup); | |
| 210 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart); | |
| 211 | |
| 212 // Instance holders. | 159 // Instance holders. |
| 213 InstanceHolder<mojom::AppInstance> app_; | 160 InstanceHolder<mojom::AppInstance> app_; |
| 214 InstanceHolder<mojom::AudioInstance> audio_; | 161 InstanceHolder<mojom::AudioInstance> audio_; |
| 215 InstanceHolder<mojom::AuthInstance> auth_; | 162 InstanceHolder<mojom::AuthInstance> auth_; |
| 216 InstanceHolder<mojom::BluetoothInstance> bluetooth_; | 163 InstanceHolder<mojom::BluetoothInstance> bluetooth_; |
| 217 InstanceHolder<mojom::ClipboardInstance> clipboard_; | 164 InstanceHolder<mojom::ClipboardInstance> clipboard_; |
| 218 InstanceHolder<mojom::CrashCollectorInstance> crash_collector_; | 165 InstanceHolder<mojom::CrashCollectorInstance> crash_collector_; |
| 219 InstanceHolder<mojom::FileSystemInstance> file_system_; | 166 InstanceHolder<mojom::FileSystemInstance> file_system_; |
| 220 InstanceHolder<mojom::ImeInstance> ime_; | 167 InstanceHolder<mojom::ImeInstance> ime_; |
| 221 InstanceHolder<mojom::IntentHelperInstance> intent_helper_; | 168 InstanceHolder<mojom::IntentHelperInstance> intent_helper_; |
| 222 InstanceHolder<mojom::MetricsInstance> metrics_; | 169 InstanceHolder<mojom::MetricsInstance> metrics_; |
| 223 InstanceHolder<mojom::NetInstance> net_; | 170 InstanceHolder<mojom::NetInstance> net_; |
| 224 InstanceHolder<mojom::NotificationsInstance> notifications_; | 171 InstanceHolder<mojom::NotificationsInstance> notifications_; |
| 225 InstanceHolder<mojom::ObbMounterInstance> obb_mounter_; | 172 InstanceHolder<mojom::ObbMounterInstance> obb_mounter_; |
| 226 InstanceHolder<mojom::PolicyInstance> policy_; | 173 InstanceHolder<mojom::PolicyInstance> policy_; |
| 227 InstanceHolder<mojom::PowerInstance> power_; | 174 InstanceHolder<mojom::PowerInstance> power_; |
| 228 InstanceHolder<mojom::ProcessInstance> process_; | 175 InstanceHolder<mojom::ProcessInstance> process_; |
| 229 InstanceHolder<mojom::StorageManagerInstance> storage_manager_; | 176 InstanceHolder<mojom::StorageManagerInstance> storage_manager_; |
| 230 InstanceHolder<mojom::VideoInstance> video_; | 177 InstanceHolder<mojom::VideoInstance> video_; |
| 231 InstanceHolder<mojom::WindowManagerInstance> window_manager_; | 178 InstanceHolder<mojom::WindowManagerInstance> window_manager_; |
| 232 | 179 |
| 180 // Gets the current state of the bridge service. |
| 181 State state() const { return state_; } |
| 182 |
| 183 // Changes the current state and notifies all observers. |
| 184 void SetState(State state); |
| 185 |
| 186 // Changes the current availability and notifies all observers. |
| 187 void SetAvailable(bool availability); |
| 188 |
| 189 base::ObserverList<Observer>& observer_list() { return observer_list_; } |
| 190 |
| 191 bool CalledOnValidThread(); |
| 192 |
| 193 private: |
| 194 friend class ArcBridgeTest; |
| 195 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); |
| 196 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites); |
| 197 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup); |
| 198 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart); |
| 199 |
| 233 base::ObserverList<Observer> observer_list_; | 200 base::ObserverList<Observer> observer_list_; |
| 234 | 201 |
| 235 base::ThreadChecker thread_checker_; | 202 base::ThreadChecker thread_checker_; |
| 236 | 203 |
| 237 // If the ARC instance service is available. | 204 // If the ARC instance service is available. |
| 238 bool available_; | 205 bool available_; |
| 239 | 206 |
| 240 // The current state of the bridge. | 207 // The current state of the bridge. |
| 241 ArcBridgeService::State state_; | 208 ArcBridgeService::State state_; |
| 242 | 209 |
| 243 // WeakPtrFactory to use callbacks. | 210 // WeakPtrFactory to use callbacks. |
| 244 base::WeakPtrFactory<ArcBridgeService> weak_factory_; | 211 base::WeakPtrFactory<ArcBridgeService> weak_factory_; |
| 245 | 212 |
| 246 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); | 213 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); |
| 247 }; | 214 }; |
| 248 | 215 |
| 249 } // namespace arc | 216 } // namespace arc |
| 250 | 217 |
| 251 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ | 218 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ |
| OLD | NEW |