Chromium Code Reviews| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 // Called whenever ARC sends app icon data for specific scale factor. | 107 // Called whenever ARC sends app icon data for specific scale factor. |
| 104 virtual void OnAppIcon(const std::string& package, | 108 virtual void OnAppIcon(const std::string& package, |
| 105 const std::string& activity, | 109 const std::string& activity, |
| 106 ScaleFactor scale_factor, | 110 ScaleFactor scale_factor, |
| 107 const std::vector<uint8_t>& icon_png_data) {} | 111 const std::vector<uint8_t>& icon_png_data) {} |
| 108 | 112 |
| 109 protected: | 113 protected: |
| 110 virtual ~AppObserver() {} | 114 virtual ~AppObserver() {} |
| 111 }; | 115 }; |
| 112 | 116 |
| 117 // Notifies ARC video service events. | |
| 118 class VideoServiceObserver { | |
| 119 public: | |
| 120 // Called whenever to create video accelerator connection. | |
| 121 virtual void OnRequestArcVideoAcceleratorChannel() {} | |
|
Owen Lin
2015/12/15 03:04:06
I still don't think we should use the name/pattern
Pawel Osciak
2015/12/16 10:17:58
+1, I'd prefer this as well.
kcwu
2015/12/16 14:05:32
Done.
| |
| 122 | |
| 123 protected: | |
| 124 virtual ~VideoServiceObserver() {} | |
| 125 }; | |
| 126 | |
| 113 virtual ~ArcBridgeService(); | 127 virtual ~ArcBridgeService(); |
| 114 | 128 |
| 115 // Gets the global instance of the ARC Bridge Service. This can only be | 129 // Gets the global instance of the ARC Bridge Service. This can only be |
| 116 // called on the thread that this class was created on. | 130 // called on the thread that this class was created on. |
| 117 static ArcBridgeService* Get(); | 131 static ArcBridgeService* Get(); |
| 118 | 132 |
| 119 // Return true if ARC has been enabled through a commandline | 133 // Return true if ARC has been enabled through a commandline |
| 120 // switch. | 134 // switch. |
| 121 static bool GetEnabled(const base::CommandLine* command_line); | 135 static bool GetEnabled(const base::CommandLine* command_line); |
| 122 | 136 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 133 // Shutdown() should be called when the browser is shutting down. This can | 147 // 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. | 148 // only be called on the thread that this class was created on. |
| 135 virtual void Shutdown() = 0; | 149 virtual void Shutdown() = 0; |
| 136 | 150 |
| 137 // Adds or removes observers. This can only be called on the thread that this | 151 // Adds or removes observers. This can only be called on the thread that this |
| 138 // class was created on. | 152 // class was created on. |
| 139 void AddObserver(Observer* observer); | 153 void AddObserver(Observer* observer); |
| 140 void RemoveObserver(Observer* observer); | 154 void RemoveObserver(Observer* observer); |
| 141 void AddNotificationObserver(NotificationObserver* observer); | 155 void AddNotificationObserver(NotificationObserver* observer); |
| 142 void RemoveNotificationObserver(NotificationObserver* observer); | 156 void RemoveNotificationObserver(NotificationObserver* observer); |
| 157 void AddVideoServiceObserver(VideoServiceObserver* observer); | |
| 158 void RemoveVideoServiceObserver(VideoServiceObserver* observer); | |
| 143 | 159 |
| 144 // Adds or removes ARC app observers. This can only be called on the thread | 160 // Adds or removes ARC app observers. This can only be called on the thread |
| 145 // that this class was created on. | 161 // that this class was created on. |
| 146 void AddAppObserver(AppObserver* observer); | 162 void AddAppObserver(AppObserver* observer); |
| 147 void RemoveAppObserver(AppObserver* observer); | 163 void RemoveAppObserver(AppObserver* observer); |
| 148 | 164 |
| 149 // Gets the current state of the bridge service. | 165 // Gets the current state of the bridge service. |
| 150 State state() const { return state_; } | 166 State state() const { return state_; } |
| 151 | 167 |
| 152 // Gets if ARC is available in this system. | 168 // Gets if ARC is available in this system. |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 171 | 187 |
| 172 // Requests to launch an app. | 188 // Requests to launch an app. |
| 173 virtual bool LaunchApp(const std::string& package, | 189 virtual bool LaunchApp(const std::string& package, |
| 174 const std::string& activity) = 0; | 190 const std::string& activity) = 0; |
| 175 | 191 |
| 176 // Requests to load an icon of specific scale_factor. | 192 // Requests to load an icon of specific scale_factor. |
| 177 virtual bool RequestAppIcon(const std::string& package, | 193 virtual bool RequestAppIcon(const std::string& package, |
| 178 const std::string& activity, | 194 const std::string& activity, |
| 179 ScaleFactor scale_factor) = 0; | 195 ScaleFactor scale_factor) = 0; |
| 180 | 196 |
| 197 virtual bool NotifyVideoAcceleratorChannelCreated( | |
| 198 const IPC::ChannelHandle& handle) = 0; | |
| 199 | |
| 181 protected: | 200 protected: |
| 182 ArcBridgeService(); | 201 ArcBridgeService(); |
| 183 | 202 |
| 184 // Changes the current state and notifies all observers. | 203 // Changes the current state and notifies all observers. |
| 185 void SetState(State state); | 204 void SetState(State state); |
| 186 | 205 |
| 187 // Changes the current availability and notifies all observers. | 206 // Changes the current availability and notifies all observers. |
| 188 void SetAvailable(bool availability); | 207 void SetAvailable(bool availability); |
| 189 | 208 |
| 190 base::ObserverList<Observer>& observer_list() { return observer_list_; } | 209 base::ObserverList<Observer>& observer_list() { return observer_list_; } |
| 191 base::ObserverList<NotificationObserver>& notification_observer_list() { | 210 base::ObserverList<NotificationObserver>& notification_observer_list() { |
| 192 return notification_observer_list_; | 211 return notification_observer_list_; |
| 193 } | 212 } |
| 194 | 213 |
| 195 base::ObserverList<AppObserver>& app_observer_list() { | 214 base::ObserverList<AppObserver>& app_observer_list() { |
| 196 return app_observer_list_; | 215 return app_observer_list_; |
| 197 } | 216 } |
| 198 | 217 |
| 218 base::ObserverList<VideoServiceObserver>& video_service_observer_list() { | |
| 219 return video_service_observer_list_; | |
| 220 } | |
| 221 | |
| 199 bool CalledOnValidThread(); | 222 bool CalledOnValidThread(); |
| 200 | 223 |
| 201 private: | 224 private: |
| 202 friend class ArcBridgeTest; | 225 friend class ArcBridgeTest; |
| 203 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); | 226 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); |
| 204 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites); | 227 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites); |
| 205 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup); | 228 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup); |
| 206 | 229 |
| 207 base::ObserverList<Observer> observer_list_; | 230 base::ObserverList<Observer> observer_list_; |
| 208 base::ObserverList<NotificationObserver> notification_observer_list_; | 231 base::ObserverList<NotificationObserver> notification_observer_list_; |
| 232 base::ObserverList<VideoServiceObserver> video_service_observer_list_; | |
| 209 | 233 |
| 210 base::ObserverList<AppObserver> app_observer_list_; | 234 base::ObserverList<AppObserver> app_observer_list_; |
| 211 | 235 |
| 212 base::ThreadChecker thread_checker_; | 236 base::ThreadChecker thread_checker_; |
| 213 | 237 |
| 214 // If the ARC instance service is available. | 238 // If the ARC instance service is available. |
| 215 bool available_; | 239 bool available_; |
| 216 | 240 |
| 217 // The current state of the bridge. | 241 // The current state of the bridge. |
| 218 ArcBridgeService::State state_; | 242 ArcBridgeService::State state_; |
| 219 | 243 |
| 220 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); | 244 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); |
| 221 }; | 245 }; |
| 222 | 246 |
| 223 } // namespace arc | 247 } // namespace arc |
| 224 | 248 |
| 225 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ | 249 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ |
| OLD | NEW |