| 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 <iosfwd> | 8 #include <iosfwd> | 
| 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 "base/observer_list.h" | 15 #include "base/observer_list.h" | 
| 16 #include "base/values.h" | 16 #include "base/values.h" | 
|  | 17 #include "components/arc/arc_session_observer.h" | 
| 17 #include "components/arc/instance_holder.h" | 18 #include "components/arc/instance_holder.h" | 
| 18 | 19 | 
| 19 namespace base { | 20 namespace base { | 
| 20 class CommandLine; | 21 class CommandLine; | 
| 21 }  // namespace base | 22 }  // namespace base | 
| 22 | 23 | 
| 23 namespace arc { | 24 namespace arc { | 
| 24 | 25 | 
| 25 class ArcBridgeTest; | 26 class ArcBridgeTest; | 
| 26 | 27 | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
| 53 class VideoInstance; | 54 class VideoInstance; | 
| 54 class WallpaperInstance; | 55 class WallpaperInstance; | 
| 55 | 56 | 
| 56 }  // namespace mojom | 57 }  // namespace mojom | 
| 57 | 58 | 
| 58 // The Chrome-side service that handles ARC instances and ARC bridge creation. | 59 // The Chrome-side service that handles ARC instances and ARC bridge creation. | 
| 59 // This service handles the lifetime of ARC instances and sets up the | 60 // This service handles the lifetime of ARC instances and sets up the | 
| 60 // communication channel (the ARC bridge) used to send and receive messages. | 61 // communication channel (the ARC bridge) used to send and receive messages. | 
| 61 class ArcBridgeService { | 62 class ArcBridgeService { | 
| 62  public: | 63  public: | 
| 63   // Describes the reason the bridge is stopped. |  | 
| 64   enum class StopReason { |  | 
| 65     // ARC instance has been gracefully shut down. |  | 
| 66     SHUTDOWN, |  | 
| 67 |  | 
| 68     // Errors occurred during the ARC instance boot. This includes any failures |  | 
| 69     // before the instance is actually attempted to be started, and also |  | 
| 70     // failures on bootstrapping IPC channels with Android. |  | 
| 71     GENERIC_BOOT_FAILURE, |  | 
| 72 |  | 
| 73     // The device is critically low on disk space. |  | 
| 74     LOW_DISK_SPACE, |  | 
| 75 |  | 
| 76     // ARC instance has crashed. |  | 
| 77     CRASH, |  | 
| 78   }; |  | 
| 79 |  | 
| 80   // Notifies life cycle events of ArcBridgeService. |  | 
| 81   class Observer { |  | 
| 82    public: |  | 
| 83     // Called whenever the state of the bridge has changed. |  | 
| 84     virtual void OnBridgeReady() {} |  | 
| 85     virtual void OnBridgeStopped(StopReason reason) {} |  | 
| 86 |  | 
| 87    protected: |  | 
| 88     virtual ~Observer() {} |  | 
| 89   }; |  | 
| 90 |  | 
| 91   virtual ~ArcBridgeService(); | 64   virtual ~ArcBridgeService(); | 
| 92 | 65 | 
| 93   // Return true if ARC has been enabled through a commandline | 66   // Return true if ARC has been enabled through a commandline | 
| 94   // switch. | 67   // switch. | 
| 95   static bool GetEnabled(const base::CommandLine* command_line); | 68   static bool GetEnabled(const base::CommandLine* command_line); | 
| 96 | 69 | 
| 97   // Return true if ARC is available on the current board. | 70   // Return true if ARC is available on the current board. | 
| 98   static bool GetAvailable(const base::CommandLine* command_line); | 71   static bool GetAvailable(const base::CommandLine* command_line); | 
| 99 | 72 | 
| 100   // HandleStartup() should be called upon profile startup.  This will only | 73   // HandleStartup() should be called upon profile startup.  This will only | 
| 101   // launch an instance if the instance is enabled. | 74   // launch an instance if the instance is enabled. | 
| 102   // This can only be called on the thread that this class was created on. | 75   // This can only be called on the thread that this class was created on. | 
| 103 | 76 | 
| 104   // Starts the ARC service, then it will connect the Mojo channel. When the | 77   // Starts the ARC service, then it will connect the Mojo channel. When the | 
| 105   // bridge becomes ready, OnBridgeReady() is called. | 78   // bridge becomes ready, OnBridgeReady() is called. | 
| 106   virtual void RequestStart() = 0; | 79   virtual void RequestStart() = 0; | 
| 107 | 80 | 
| 108   // Stops the ARC service. | 81   // Stops the ARC service. | 
| 109   virtual void RequestStop() = 0; | 82   virtual void RequestStop() = 0; | 
| 110 | 83 | 
| 111   // OnShutdown() should be called when the browser is shutting down. This can | 84   // OnShutdown() should be called when the browser is shutting down. This can | 
| 112   // only be called on the thread that this class was created on. We assume that | 85   // only be called on the thread that this class was created on. We assume that | 
| 113   // when this function is called, MessageLoop is no longer exists. | 86   // when this function is called, MessageLoop is no longer exists. | 
| 114   virtual void OnShutdown() = 0; | 87   virtual void OnShutdown() = 0; | 
| 115 | 88 | 
| 116   // Adds or removes observers. This can only be called on the thread that this | 89   // Adds or removes observers. This can only be called on the thread that this | 
| 117   // class was created on. RemoveObserver does nothing if |observer| is not in | 90   // class was created on. RemoveObserver does nothing if |observer| is not in | 
| 118   // the list. | 91   // the list. | 
| 119   void AddObserver(Observer* observer); | 92   void AddObserver(ArcSessionObserver* observer); | 
| 120   void RemoveObserver(Observer* observer); | 93   void RemoveObserver(ArcSessionObserver* observer); | 
| 121 | 94 | 
| 122   InstanceHolder<mojom::AppInstance>* app() { return &app_; } | 95   InstanceHolder<mojom::AppInstance>* app() { return &app_; } | 
| 123   InstanceHolder<mojom::AudioInstance>* audio() { return &audio_; } | 96   InstanceHolder<mojom::AudioInstance>* audio() { return &audio_; } | 
| 124   InstanceHolder<mojom::AuthInstance>* auth() { return &auth_; } | 97   InstanceHolder<mojom::AuthInstance>* auth() { return &auth_; } | 
| 125   InstanceHolder<mojom::BluetoothInstance>* bluetooth() { return &bluetooth_; } | 98   InstanceHolder<mojom::BluetoothInstance>* bluetooth() { return &bluetooth_; } | 
| 126   InstanceHolder<mojom::BootPhaseMonitorInstance>* boot_phase_monitor() { | 99   InstanceHolder<mojom::BootPhaseMonitorInstance>* boot_phase_monitor() { | 
| 127     return &boot_phase_monitor_; | 100     return &boot_phase_monitor_; | 
| 128   } | 101   } | 
| 129   InstanceHolder<mojom::ClipboardInstance>* clipboard() { return &clipboard_; } | 102   InstanceHolder<mojom::ClipboardInstance>* clipboard() { return &clipboard_; } | 
| 130   InstanceHolder<mojom::CrashCollectorInstance>* crash_collector() { | 103   InstanceHolder<mojom::CrashCollectorInstance>* crash_collector() { | 
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 233 | 206 | 
| 234   // Gets the current state of the bridge service. | 207   // Gets the current state of the bridge service. | 
| 235   State state() const { return state_; } | 208   State state() const { return state_; } | 
| 236 | 209 | 
| 237   // Changes the current state and notifies all observers. | 210   // Changes the current state and notifies all observers. | 
| 238   void SetState(State state); | 211   void SetState(State state); | 
| 239 | 212 | 
| 240   // Sets the reason the bridge is stopped. This function must be always called | 213   // Sets the reason the bridge is stopped. This function must be always called | 
| 241   // before SetState(State::STOPPED) to report a correct reason with | 214   // before SetState(State::STOPPED) to report a correct reason with | 
| 242   // Observer::OnBridgeStopped(). | 215   // Observer::OnBridgeStopped(). | 
| 243   void SetStopReason(StopReason stop_reason); | 216   void SetStopReason(ArcSessionObserver::StopReason stop_reason); | 
| 244 | 217 | 
| 245   base::ObserverList<Observer>& observer_list() { return observer_list_; } | 218   base::ObserverList<ArcSessionObserver>& observer_list() { | 
|  | 219     return observer_list_; | 
|  | 220   } | 
| 246 | 221 | 
| 247   bool CalledOnValidThread(); | 222   bool CalledOnValidThread(); | 
| 248 | 223 | 
| 249  private: | 224  private: | 
| 250   friend class ArcBridgeTest; | 225   friend class ArcBridgeTest; | 
| 251   FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); | 226   FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); | 
| 252   FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites); | 227   FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites); | 
| 253   FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, StopMidStartup); | 228   FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, StopMidStartup); | 
| 254   FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart); | 229   FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart); | 
| 255   FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, OnBridgeStopped); | 230   FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, OnBridgeStopped); | 
| 256   FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Shutdown); | 231   FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Shutdown); | 
| 257 | 232 | 
| 258   base::ObserverList<Observer> observer_list_; | 233   base::ObserverList<ArcSessionObserver> observer_list_; | 
| 259 | 234 | 
| 260   base::ThreadChecker thread_checker_; | 235   base::ThreadChecker thread_checker_; | 
| 261 | 236 | 
| 262   // The current state of the bridge. | 237   // The current state of the bridge. | 
| 263   ArcBridgeService::State state_; | 238   ArcBridgeService::State state_; | 
| 264 | 239 | 
| 265   // The reason the bridge is stopped. | 240   // The reason the bridge is stopped. | 
| 266   StopReason stop_reason_; | 241   ArcSessionObserver::StopReason stop_reason_; | 
| 267 | 242 | 
| 268   // WeakPtrFactory to use callbacks. | 243   // WeakPtrFactory to use callbacks. | 
| 269   base::WeakPtrFactory<ArcBridgeService> weak_factory_; | 244   base::WeakPtrFactory<ArcBridgeService> weak_factory_; | 
| 270 | 245 | 
| 271   DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); | 246   DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); | 
| 272 }; | 247 }; | 
| 273 | 248 | 
| 274 // Defines "<<" operator for LOGging purpose. |  | 
| 275 std::ostream& operator<<( |  | 
| 276     std::ostream& os, ArcBridgeService::StopReason reason); |  | 
| 277 |  | 
| 278 }  // namespace arc | 249 }  // namespace arc | 
| 279 | 250 | 
| 280 #endif  // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ | 251 #endif  // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ | 
| OLD | NEW | 
|---|