| 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/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 16 #include "components/arc/common/arc_bridge.mojom.h" | 16 #include "components/arc/common/arc_bridge.mojom.h" |
| 17 | 17 |
| 18 namespace base { | 18 namespace base { |
| 19 class CommandLine; | 19 class CommandLine; |
| 20 } // namespace base | 20 } // namespace base |
| 21 | 21 |
| 22 namespace IPC { |
| 23 class ChannelHandle; |
| 24 } // namespace IPC |
| 25 |
| 22 namespace arc { | 26 namespace arc { |
| 23 | 27 |
| 24 class ArcBridgeBootstrap; | 28 class ArcBridgeBootstrap; |
| 25 | 29 |
| 26 // The Chrome-side service that handles ARC instances and ARC bridge creation. | 30 // The Chrome-side service that handles ARC instances and ARC bridge creation. |
| 27 // This service handles the lifetime of ARC instances and sets up the | 31 // This service handles the lifetime of ARC instances and sets up the |
| 28 // communication channel (the ARC bridge) used to send and receive messages. | 32 // communication channel (the ARC bridge) used to send and receive messages. |
| 29 class ArcBridgeService { | 33 class ArcBridgeService { |
| 30 public: | 34 public: |
| 31 // The possible states of the bridge. In the normal flow, the state changes | 35 // The possible states of the bridge. In the normal flow, the state changes |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // Do not use the process list obtained here for security-sensitive purpose. | 125 // Do not use the process list obtained here for security-sensitive purpose. |
| 122 // Good news is that Android processes are designed to be ready to be killed | 126 // Good news is that Android processes are designed to be ready to be killed |
| 123 // at any time, so killing a wrong process is not a disaster. | 127 // at any time, so killing a wrong process is not a disaster. |
| 124 virtual void OnUpdateProcessList( | 128 virtual void OnUpdateProcessList( |
| 125 const std::vector<RunningAppProcessInfo>& processes) {} | 129 const std::vector<RunningAppProcessInfo>& processes) {} |
| 126 | 130 |
| 127 protected: | 131 protected: |
| 128 virtual ~ProcessObserver() {} | 132 virtual ~ProcessObserver() {} |
| 129 }; | 133 }; |
| 130 | 134 |
| 135 // Notifies ARC video service events. |
| 136 class VideoService { |
| 137 public: |
| 138 // Called whenever to create video accelerator connection. |
| 139 virtual void OnRequestArcVideoAcceleratorChannel() {} |
| 140 |
| 141 protected: |
| 142 virtual ~VideoService() {} |
| 143 }; |
| 144 |
| 131 virtual ~ArcBridgeService(); | 145 virtual ~ArcBridgeService(); |
| 132 | 146 |
| 133 // Gets the global instance of the ARC Bridge Service. This can only be | 147 // Gets the global instance of the ARC Bridge Service. This can only be |
| 134 // called on the thread that this class was created on. | 148 // called on the thread that this class was created on. |
| 135 static ArcBridgeService* Get(); | 149 static ArcBridgeService* Get(); |
| 136 | 150 |
| 137 // Return true if ARC has been enabled through a commandline | 151 // Return true if ARC has been enabled through a commandline |
| 138 // switch. | 152 // switch. |
| 139 static bool GetEnabled(const base::CommandLine* command_line); | 153 static bool GetEnabled(const base::CommandLine* command_line); |
| 140 | 154 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 162 // Adds or removes ARC app observers. This can only be called on the thread | 176 // Adds or removes ARC app observers. This can only be called on the thread |
| 163 // that this class was created on. | 177 // that this class was created on. |
| 164 void AddAppObserver(AppObserver* observer); | 178 void AddAppObserver(AppObserver* observer); |
| 165 void RemoveAppObserver(AppObserver* observer); | 179 void RemoveAppObserver(AppObserver* observer); |
| 166 | 180 |
| 167 // Adds or removes ARC process observers. This can only be called on the | 181 // Adds or removes ARC process observers. This can only be called on the |
| 168 // thread that this class was created on. | 182 // thread that this class was created on. |
| 169 void AddProcessObserver(ProcessObserver* observer); | 183 void AddProcessObserver(ProcessObserver* observer); |
| 170 void RemoveProcessObserver(ProcessObserver* observer); | 184 void RemoveProcessObserver(ProcessObserver* observer); |
| 171 | 185 |
| 186 // Set VideoService provider. This can only be called on the thread that |
| 187 // this class was created on. |
| 188 void SetVideoService(VideoService* service); |
| 189 |
| 172 // Gets the current state of the bridge service. | 190 // Gets the current state of the bridge service. |
| 173 State state() const { return state_; } | 191 State state() const { return state_; } |
| 174 | 192 |
| 175 // Gets if ARC is available in this system. | 193 // Gets if ARC is available in this system. |
| 176 bool available() const { return available_; } | 194 bool available() const { return available_; } |
| 177 | 195 |
| 178 // Requests registration of an input device on the ARC instance. | 196 // Requests registration of an input device on the ARC instance. |
| 179 // TODO(denniskempin): Make this interface more typesafe. | 197 // TODO(denniskempin): Make this interface more typesafe. |
| 180 // |name| should be the displayable name of the emulated device (e.g. "Chrome | 198 // |name| should be the displayable name of the emulated device (e.g. "Chrome |
| 181 // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard") | 199 // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard") |
| (...skipping 16 matching lines...) Expand all Loading... |
| 198 | 216 |
| 199 // Requests to load an icon of specific scale_factor. | 217 // Requests to load an icon of specific scale_factor. |
| 200 virtual bool RequestAppIcon(const std::string& package, | 218 virtual bool RequestAppIcon(const std::string& package, |
| 201 const std::string& activity, | 219 const std::string& activity, |
| 202 ScaleFactor scale_factor) = 0; | 220 ScaleFactor scale_factor) = 0; |
| 203 | 221 |
| 204 // Requests a list of processes from the ARC instance. | 222 // Requests a list of processes from the ARC instance. |
| 205 // When the result comes back, Observer::OnUpdateProcessList() is called. | 223 // When the result comes back, Observer::OnUpdateProcessList() is called. |
| 206 virtual bool RequestProcessList() = 0; | 224 virtual bool RequestProcessList() = 0; |
| 207 | 225 |
| 226 // Notify the ipc handle for video accelerator is created. |
| 227 virtual void NotifyVideoAcceleratorChannelCreated( |
| 228 const IPC::ChannelHandle& handle) = 0; |
| 229 |
| 208 protected: | 230 protected: |
| 209 ArcBridgeService(); | 231 ArcBridgeService(); |
| 210 | 232 |
| 211 // Changes the current state and notifies all observers. | 233 // Changes the current state and notifies all observers. |
| 212 void SetState(State state); | 234 void SetState(State state); |
| 213 | 235 |
| 214 // Changes the current availability and notifies all observers. | 236 // Changes the current availability and notifies all observers. |
| 215 void SetAvailable(bool availability); | 237 void SetAvailable(bool availability); |
| 216 | 238 |
| 217 base::ObserverList<Observer>& observer_list() { return observer_list_; } | 239 base::ObserverList<Observer>& observer_list() { return observer_list_; } |
| 218 | 240 |
| 219 base::ObserverList<NotificationObserver>& notification_observer_list() { | 241 base::ObserverList<NotificationObserver>& notification_observer_list() { |
| 220 return notification_observer_list_; | 242 return notification_observer_list_; |
| 221 } | 243 } |
| 222 | 244 |
| 223 base::ObserverList<AppObserver>& app_observer_list() { | 245 base::ObserverList<AppObserver>& app_observer_list() { |
| 224 return app_observer_list_; | 246 return app_observer_list_; |
| 225 } | 247 } |
| 226 | 248 |
| 227 base::ObserverList<ProcessObserver>& process_observer_list() { | 249 base::ObserverList<ProcessObserver>& process_observer_list() { |
| 228 return process_observer_list_; | 250 return process_observer_list_; |
| 229 } | 251 } |
| 230 | 252 |
| 253 VideoService* video_service() { return video_service_; } |
| 254 |
| 231 bool CalledOnValidThread(); | 255 bool CalledOnValidThread(); |
| 232 | 256 |
| 233 private: | 257 private: |
| 234 friend class ArcBridgeTest; | 258 friend class ArcBridgeTest; |
| 235 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); | 259 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); |
| 236 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites); | 260 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites); |
| 237 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup); | 261 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup); |
| 238 | 262 |
| 239 base::ObserverList<Observer> observer_list_; | 263 base::ObserverList<Observer> observer_list_; |
| 240 base::ObserverList<NotificationObserver> notification_observer_list_; | 264 base::ObserverList<NotificationObserver> notification_observer_list_; |
| 241 base::ObserverList<AppObserver> app_observer_list_; | 265 base::ObserverList<AppObserver> app_observer_list_; |
| 242 base::ObserverList<ProcessObserver> process_observer_list_; | 266 base::ObserverList<ProcessObserver> process_observer_list_; |
| 243 | 267 |
| 268 VideoService* video_service_; |
| 269 |
| 244 base::ThreadChecker thread_checker_; | 270 base::ThreadChecker thread_checker_; |
| 245 | 271 |
| 246 // If the ARC instance service is available. | 272 // If the ARC instance service is available. |
| 247 bool available_; | 273 bool available_; |
| 248 | 274 |
| 249 // The current state of the bridge. | 275 // The current state of the bridge. |
| 250 ArcBridgeService::State state_; | 276 ArcBridgeService::State state_; |
| 251 | 277 |
| 252 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); | 278 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); |
| 253 }; | 279 }; |
| 254 | 280 |
| 255 } // namespace arc | 281 } // namespace arc |
| 256 | 282 |
| 257 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ | 283 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ |
| OLD | NEW |