| 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 17 matching lines...) Expand all Loading... |
| 28 // communication channel (the ARC bridge) used to send and receive messages. | 28 // communication channel (the ARC bridge) used to send and receive messages. |
| 29 class ArcBridgeService { | 29 class ArcBridgeService { |
| 30 public: | 30 public: |
| 31 // The possible states of the bridge. In the normal flow, the state changes | 31 // The possible states of the bridge. In the normal flow, the state changes |
| 32 // in the following sequence: | 32 // in the following sequence: |
| 33 // | 33 // |
| 34 // STOPPED | 34 // STOPPED |
| 35 // PrerequisitesChanged() -> | 35 // PrerequisitesChanged() -> |
| 36 // CONNECTING | 36 // CONNECTING |
| 37 // OnConnectionEstablished() -> | 37 // OnConnectionEstablished() -> |
| 38 // CONNECTED | |
| 39 // OnInstanceBootPhase(INSTANCE_BOOT_PHASE_BRIDGE_READY) -> | |
| 40 // READY | 38 // READY |
| 41 // | 39 // |
| 42 // The ArcBridgeBootstrap state machine can be thought of being substates of | 40 // The ArcBridgeBootstrap state machine can be thought of being substates of |
| 43 // ArcBridgeService's CONNECTING state. | 41 // ArcBridgeService's CONNECTING state. |
| 44 // | 42 // |
| 45 // * | 43 // * |
| 46 // StopInstance() -> | 44 // StopInstance() -> |
| 47 // STOPPING | 45 // STOPPING |
| 48 // OnStopped() -> | 46 // OnStopped() -> |
| 49 // STOPPED | 47 // STOPPED |
| (...skipping 14 matching lines...) Expand all Loading... |
| 64 // The ARC instance has started shutting down. | 62 // The ARC instance has started shutting down. |
| 65 STOPPING, | 63 STOPPING, |
| 66 }; | 64 }; |
| 67 | 65 |
| 68 // Notifies life cycle events of ArcBridgeService. | 66 // Notifies life cycle events of ArcBridgeService. |
| 69 class Observer { | 67 class Observer { |
| 70 public: | 68 public: |
| 71 // Called whenever the state of the bridge has changed. | 69 // Called whenever the state of the bridge has changed. |
| 72 virtual void OnStateChanged(State state) {} | 70 virtual void OnStateChanged(State state) {} |
| 73 | 71 |
| 74 // Called when the instance has reached a boot phase | |
| 75 virtual void OnInstanceBootPhase(InstanceBootPhase phase) {} | |
| 76 | |
| 77 // Called whenever ARC's availability has changed for this system. | 72 // Called whenever ARC's availability has changed for this system. |
| 78 virtual void OnAvailableChanged(bool available) {} | 73 virtual void OnAvailableChanged(bool available) {} |
| 79 | 74 |
| 75 // Called whenever the ARC app list is ready. |
| 76 virtual void OnAppInstanceReady() {} |
| 77 |
| 78 // Called whenever the ARC input is ready. |
| 79 virtual void OnInputInstanceReady() {} |
| 80 |
| 81 // Called whenever the ARC notification is ready. |
| 82 virtual void OnNotificationsInstanceReady() {} |
| 83 |
| 84 // Called whenever the ARC power is ready. |
| 85 virtual void OnPowerInstanceReady() {} |
| 86 |
| 87 // Called whenever the ARC process list is ready. |
| 88 virtual void OnProcessListInstanceReady() {} |
| 89 |
| 80 protected: | 90 protected: |
| 81 virtual ~Observer() {} | 91 virtual ~Observer() {} |
| 82 }; | 92 }; |
| 83 | 93 |
| 84 class NotificationObserver { | |
| 85 public: | |
| 86 // Called whenever a notification has been posted on Android side. This | |
| 87 // event is used for both creation and update. | |
| 88 virtual void OnNotificationPostedFromAndroid( | |
| 89 const ArcNotificationData& data) {} | |
| 90 // Called whenever a notification has been removed on Android side. | |
| 91 virtual void OnNotificationRemovedFromAndroid(const std::string& key) {} | |
| 92 | |
| 93 protected: | |
| 94 virtual ~NotificationObserver() {} | |
| 95 }; | |
| 96 | |
| 97 // Notifies ARC apps related events. | |
| 98 class AppObserver { | |
| 99 public: | |
| 100 // Called whenever ARC sends information about available apps. | |
| 101 virtual void OnAppListRefreshed(const std::vector<AppInfo>& apps) {} | |
| 102 | |
| 103 // Called whenever ARC sends app icon data for specific scale factor. | |
| 104 virtual void OnAppIcon(const std::string& package, | |
| 105 const std::string& activity, | |
| 106 ScaleFactor scale_factor, | |
| 107 const std::vector<uint8_t>& icon_png_data) {} | |
| 108 | |
| 109 protected: | |
| 110 virtual ~AppObserver() {} | |
| 111 }; | |
| 112 | |
| 113 virtual ~ArcBridgeService(); | 94 virtual ~ArcBridgeService(); |
| 114 | 95 |
| 115 // Gets the global instance of the ARC Bridge Service. This can only be | 96 // Gets the global instance of the ARC Bridge Service. This can only be |
| 116 // called on the thread that this class was created on. | 97 // called on the thread that this class was created on. |
| 117 static ArcBridgeService* Get(); | 98 static ArcBridgeService* Get(); |
| 118 | 99 |
| 119 // Return true if ARC has been enabled through a commandline | 100 // Return true if ARC has been enabled through a commandline |
| 120 // switch. | 101 // switch. |
| 121 static bool GetEnabled(const base::CommandLine* command_line); | 102 static bool GetEnabled(const base::CommandLine* command_line); |
| 122 | 103 |
| 123 // DetectAvailability() should be called once D-Bus is available. It will | 104 // DetectAvailability() should be called once D-Bus is available. It will |
| 124 // call CheckArcAvailability() on the session_manager. This can only be | 105 // call CheckArcAvailability() on the session_manager. This can only be |
| 125 // called on the thread that this class was created on. | 106 // called on the thread that this class was created on. |
| 126 virtual void DetectAvailability() = 0; | 107 virtual void DetectAvailability() = 0; |
| 127 | 108 |
| 128 // HandleStartup() should be called upon profile startup. This will only | 109 // HandleStartup() should be called upon profile startup. This will only |
| 129 // launch an instance if the instance service is available and it is enabled. | 110 // launch an instance if the instance service is available and it is enabled. |
| 130 // This can only be called on the thread that this class was created on. | 111 // This can only be called on the thread that this class was created on. |
| 131 virtual void HandleStartup() = 0; | 112 virtual void HandleStartup() = 0; |
| 132 | 113 |
| 133 // Shutdown() should be called when the browser is shutting down. This can | 114 // Shutdown() should be called when the browser is shutting down. This can |
| 134 // only be called on the thread that this class was created on. | 115 // only be called on the thread that this class was created on. |
| 135 virtual void Shutdown() = 0; | 116 virtual void Shutdown() = 0; |
| 136 | 117 |
| 137 // Adds or removes observers. This can only be called on the thread that this | 118 // Adds or removes observers. This can only be called on the thread that this |
| 138 // class was created on. | 119 // class was created on. |
| 139 void AddObserver(Observer* observer); | 120 void AddObserver(Observer* observer); |
| 140 void RemoveObserver(Observer* observer); | 121 void RemoveObserver(Observer* observer); |
| 141 void AddNotificationObserver(NotificationObserver* observer); | |
| 142 void RemoveNotificationObserver(NotificationObserver* observer); | |
| 143 | 122 |
| 144 // Adds or removes ARC app observers. This can only be called on the thread | 123 // Gets the Mojo interface for all the instance services. This will return |
| 145 // that this class was created on. | 124 // nullptr if that particular service is not ready yet. Use an Observer if |
| 146 void AddAppObserver(AppObserver* observer); | 125 // you want to be notified when this is ready. This can only be called on the |
| 147 void RemoveAppObserver(AppObserver* observer); | 126 // thread that this class was created on. |
| 127 AppInstance* app_instance() { return app_ptr_.get(); } |
| 128 InputInstance* input_instance() { return input_ptr_.get(); } |
| 129 NotificationsInstance* notifications_instance() { |
| 130 return notifications_ptr_.get(); |
| 131 } |
| 132 PowerInstance* power_instance() { return power_ptr_.get(); } |
| 133 ProcessListInstance* process_list_instance() { |
| 134 return process_list_ptr_.get(); |
| 135 } |
| 148 | 136 |
| 149 // Gets the current state of the bridge service. | 137 // Gets the current state of the bridge service. |
| 150 State state() const { return state_; } | 138 State state() const { return state_; } |
| 151 | 139 |
| 152 // Gets if ARC is available in this system. | 140 // Gets if ARC is available in this system. |
| 153 bool available() const { return available_; } | 141 bool available() const { return available_; } |
| 154 | 142 |
| 155 // Requests registration of an input device on the ARC instance. | |
| 156 // TODO(denniskempin): Make this interface more typesafe. | |
| 157 // |name| should be the displayable name of the emulated device (e.g. "Chrome | |
| 158 // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard") | |
| 159 // and |fd| a file descriptor that emulates the kernel events of the device. | |
| 160 // This can only be called on the thread that this class was created on. | |
| 161 virtual bool RegisterInputDevice(const std::string& name, | |
| 162 const std::string& device_type, | |
| 163 base::ScopedFD fd) = 0; | |
| 164 | |
| 165 // Sends a notification event to Android side. | |
| 166 virtual bool SendNotificationEventToAndroid(const std::string& key, | |
| 167 ArcNotificationEvent event) = 0; | |
| 168 | |
| 169 // Requests to refresh an app list. | |
| 170 virtual bool RefreshAppList() = 0; | |
| 171 | |
| 172 // Requests to launch an app. | |
| 173 virtual bool LaunchApp(const std::string& package, | |
| 174 const std::string& activity) = 0; | |
| 175 | |
| 176 // Requests to load an icon of specific scale_factor. | |
| 177 virtual bool RequestAppIcon(const std::string& package, | |
| 178 const std::string& activity, | |
| 179 ScaleFactor scale_factor) = 0; | |
| 180 | |
| 181 protected: | 143 protected: |
| 182 ArcBridgeService(); | 144 ArcBridgeService(); |
| 183 | 145 |
| 184 // Changes the current state and notifies all observers. | 146 // Changes the current state and notifies all observers. |
| 185 void SetState(State state); | 147 void SetState(State state); |
| 186 | 148 |
| 187 // Changes the current availability and notifies all observers. | 149 // Changes the current availability and notifies all observers. |
| 188 void SetAvailable(bool availability); | 150 void SetAvailable(bool availability); |
| 189 | 151 |
| 190 base::ObserverList<Observer>& observer_list() { return observer_list_; } | 152 base::ObserverList<Observer>& observer_list() { return observer_list_; } |
| 191 base::ObserverList<NotificationObserver>& notification_observer_list() { | |
| 192 return notification_observer_list_; | |
| 193 } | |
| 194 | |
| 195 base::ObserverList<AppObserver>& app_observer_list() { | |
| 196 return app_observer_list_; | |
| 197 } | |
| 198 | 153 |
| 199 bool CalledOnValidThread(); | 154 bool CalledOnValidThread(); |
| 200 | 155 |
| 156 // Mojo interfaces. |
| 157 AppInstancePtr app_ptr_; |
| 158 InputInstancePtr input_ptr_; |
| 159 NotificationsInstancePtr notifications_ptr_; |
| 160 PowerInstancePtr power_ptr_; |
| 161 ProcessListInstancePtr process_list_ptr_; |
| 162 |
| 201 private: | 163 private: |
| 202 friend class ArcBridgeTest; | 164 friend class ArcBridgeTest; |
| 203 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); | 165 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); |
| 204 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites); | 166 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites); |
| 205 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup); | 167 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup); |
| 206 | 168 |
| 207 base::ObserverList<Observer> observer_list_; | 169 base::ObserverList<Observer> observer_list_; |
| 208 base::ObserverList<NotificationObserver> notification_observer_list_; | |
| 209 | |
| 210 base::ObserverList<AppObserver> app_observer_list_; | |
| 211 | 170 |
| 212 base::ThreadChecker thread_checker_; | 171 base::ThreadChecker thread_checker_; |
| 213 | 172 |
| 214 // If the ARC instance service is available. | 173 // If the ARC instance service is available. |
| 215 bool available_; | 174 bool available_; |
| 216 | 175 |
| 217 // The current state of the bridge. | 176 // The current state of the bridge. |
| 218 ArcBridgeService::State state_; | 177 ArcBridgeService::State state_; |
| 219 | 178 |
| 220 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); | 179 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); |
| 221 }; | 180 }; |
| 222 | 181 |
| 223 } // namespace arc | 182 } // namespace arc |
| 224 | 183 |
| 225 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ | 184 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ |
| OLD | NEW |