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 CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 // Notifies this instance that the UI has been initialized. | 96 // Notifies this instance that the UI has been initialized. |
| 97 void UIInitialized(); | 97 void UIInitialized(); |
| 98 | 98 |
| 99 // Requests a route be created from the source mapped to | 99 // Requests a route be created from the source mapped to |
| 100 // |cast_mode|, to the sink given by |sink_id|. | 100 // |cast_mode|, to the sink given by |sink_id|. |
| 101 // Returns true if a route request is successfully submitted. | 101 // Returns true if a route request is successfully submitted. |
| 102 // |OnRouteResponseReceived()| will be invoked when the route request | 102 // |OnRouteResponseReceived()| will be invoked when the route request |
| 103 // completes. | 103 // completes. |
| 104 bool CreateRoute(const MediaSink::Id& sink_id, MediaCastMode cast_mode); | 104 bool CreateRoute(const MediaSink::Id& sink_id, MediaCastMode cast_mode); |
| 105 | 105 |
| 106 // Calls MediaRouter to join the given route. | |
| 107 bool ConnectRemoteRoute(const MediaSink::Id& sink_id, | |
| 108 const MediaRoute::Id& route_id); | |
| 109 | |
| 106 // Calls MediaRouter to close the given route. | 110 // Calls MediaRouter to close the given route. |
| 107 void CloseRoute(const MediaRoute::Id& route_id); | 111 void CloseRoute(const MediaRoute::Id& route_id); |
| 108 | 112 |
| 109 // Calls MediaRouter to add the given issue. | 113 // Calls MediaRouter to add the given issue. |
| 110 void AddIssue(const Issue& issue); | 114 void AddIssue(const Issue& issue); |
| 111 | 115 |
| 112 // Calls MediaRouter to clear the given issue. | 116 // Calls MediaRouter to clear the given issue. |
| 113 void ClearIssue(const Issue::Id& issue_id); | 117 void ClearIssue(const Issue::Id& issue_id); |
| 114 | 118 |
| 115 // Returns the hostname of the default source's parent frame URL. | 119 // Returns the hostname of the default source's parent frame URL. |
| 116 std::string GetPresentationRequestSourceName() const; | 120 std::string GetPresentationRequestSourceName() const; |
| 117 std::string GetTruncatedPresentationRequestSourceName() const; | 121 std::string GetTruncatedPresentationRequestSourceName() const; |
| 118 bool HasPendingRouteRequest() const { | 122 bool HasPendingRouteRequest() const { |
| 119 return current_route_request_id_ != -1; | 123 return current_route_request_id_ != -1; |
| 120 } | 124 } |
| 121 const std::vector<MediaSinkWithCastModes>& sinks() const { return sinks_; } | 125 const std::vector<MediaSinkWithCastModes>& sinks() const { return sinks_; } |
| 122 const std::vector<MediaRoute>& routes() const { return routes_; } | 126 const std::vector<MediaRoute>& routes() const { return routes_; } |
| 127 const std::vector<MediaRoute::Id>& joinable_route_ids() const { | |
| 128 return joinable_route_ids_; | |
| 129 } | |
| 123 const std::set<MediaCastMode>& cast_modes() const { return cast_modes_; } | 130 const std::set<MediaCastMode>& cast_modes() const { return cast_modes_; } |
| 124 const content::WebContents* initiator() const { return initiator_; } | 131 const content::WebContents* initiator() const { return initiator_; } |
| 125 | 132 |
| 126 // Marked virtual for tests. | 133 // Marked virtual for tests. |
| 127 virtual const std::string& GetRouteProviderExtensionId() const; | 134 virtual const std::string& GetRouteProviderExtensionId() const; |
| 128 | 135 |
| 129 // Called to track UI metrics. | 136 // Called to track UI metrics. |
| 130 void SetUIInitializationTimer(const base::Time& start_time); | 137 void SetUIInitializationTimer(const base::Time& start_time); |
| 131 void OnUIInitiallyLoaded(); | 138 void OnUIInitiallyLoaded(); |
| 132 void OnUIInitialDataReceived(); | 139 void OnUIInitialDataReceived(); |
| 133 | 140 |
| 134 private: | 141 private: |
| 135 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SortedSinks); | 142 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SortedSinks); |
| 136 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 143 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
| 137 UIMediaRoutesObserverFiltersNonDisplayRoutes); | 144 UIMediaRoutesObserverFiltersNonDisplayRoutes); |
| 145 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | |
| 146 UIMediaRoutesObserverFiltersNonDisplayJoinableRoutes); | |
| 138 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, GetExtensionNameExtensionPresent); | 147 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, GetExtensionNameExtensionPresent); |
| 139 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 148 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
| 140 GetExtensionNameEmptyWhenNotInstalled); | 149 GetExtensionNameEmptyWhenNotInstalled); |
| 141 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 150 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
| 142 GetExtensionNameEmptyWhenNotExtensionURL); | 151 GetExtensionNameEmptyWhenNotExtensionURL); |
| 143 | 152 |
| 144 class UIIssuesObserver; | 153 class UIIssuesObserver; |
| 154 | |
| 145 class UIMediaRoutesObserver : public MediaRoutesObserver { | 155 class UIMediaRoutesObserver : public MediaRoutesObserver { |
| 146 public: | 156 public: |
| 147 using RoutesUpdatedCallback = | 157 using RoutesUpdatedCallback = |
| 148 base::Callback<void(const std::vector<MediaRoute>&)>; | 158 base::Callback<void(const std::vector<MediaRoute>&, |
| 159 const std::vector<MediaRoute::Id>&)>; | |
| 149 UIMediaRoutesObserver(MediaRouter* router, | 160 UIMediaRoutesObserver(MediaRouter* router, |
| 150 const RoutesUpdatedCallback& callback); | 161 const RoutesUpdatedCallback& callback); |
| 162 UIMediaRoutesObserver(MediaRouter* router, const MediaSource::Id& source_id, | |
| 163 const RoutesUpdatedCallback& callback); | |
|
stevenjb
2016/01/05 20:10:23
We avoid multiple constructors in Chrome. Either u
matt.boetger
2016/01/06 22:49:07
Done.
| |
| 151 ~UIMediaRoutesObserver() override; | 164 ~UIMediaRoutesObserver() override; |
| 152 | 165 |
| 153 // MediaRoutesObserver | 166 // MediaRoutesObserver |
| 154 void OnRoutesUpdated(const std::vector<MediaRoute>& routes) override; | 167 void OnRoutesUpdated( |
| 168 const std::vector<MediaRoute>& routes, | |
| 169 const std::vector<MediaRoute::Id>& joinable_route_ids) override; | |
| 155 | 170 |
| 156 private: | 171 private: |
| 157 // Callback to the owning MediaRouterUI instance. | 172 // Callback to the owning MediaRouterUI instance. |
| 158 RoutesUpdatedCallback callback_; | 173 RoutesUpdatedCallback callback_; |
| 159 | 174 |
| 160 DISALLOW_COPY_AND_ASSIGN(UIMediaRoutesObserver); | 175 DISALLOW_COPY_AND_ASSIGN(UIMediaRoutesObserver); |
| 161 }; | 176 }; |
| 162 | 177 |
| 163 static std::string GetExtensionName(const GURL& url, | 178 static std::string GetExtensionName(const GURL& url, |
| 164 extensions::ExtensionRegistry* registry); | 179 extensions::ExtensionRegistry* registry); |
| 165 | 180 |
| 166 // QueryResultManager::Observer | 181 // QueryResultManager::Observer |
| 167 void OnResultsUpdated( | 182 void OnResultsUpdated( |
| 168 const std::vector<MediaSinkWithCastModes>& sinks) override; | 183 const std::vector<MediaSinkWithCastModes>& sinks) override; |
| 169 | 184 |
| 170 // Called by |issues_observer_| when the top issue has changed. | 185 // Called by |issues_observer_| when the top issue has changed. |
| 171 // If the UI is already initialized, notifies |handler_| to update the UI. | 186 // If the UI is already initialized, notifies |handler_| to update the UI. |
| 172 // Ignored if the UI is not yet initialized. | 187 // Ignored if the UI is not yet initialized. |
| 173 void SetIssue(const Issue* issue); | 188 void SetIssue(const Issue* issue); |
| 174 | 189 |
| 175 // Called by |routes_observer_| when the set of active routes has changed. | 190 // Called by |routes_observer_| when the set of active routes has changed. |
| 176 void OnRoutesUpdated(const std::vector<MediaRoute>& routes); | 191 void OnRoutesUpdated(const std::vector<MediaRoute>& routes, |
| 192 const std::vector<MediaRoute::Id>& joinable_route_ids); | |
| 177 | 193 |
| 178 // Callback passed to MediaRouter to receive response to route creation | 194 // Callback passed to MediaRouter to receive response to route creation |
| 179 // requests. | 195 // requests. |
| 180 void OnRouteResponseReceived(const int route_request_id, | 196 void OnRouteResponseReceived(const int route_request_id, |
| 181 const MediaSink::Id& sink_id, | 197 const MediaSink::Id& sink_id, |
| 182 const MediaRoute* route, | 198 const MediaRoute* route, |
| 183 const std::string& presentation_id, | 199 const std::string& presentation_id, |
| 184 const std::string& error); | 200 const std::string& error); |
| 185 | 201 |
| 186 // Creates and sends an issue if route creation times out. | 202 // Creates and sends an issue if route creation times out. |
| 187 void RouteCreationTimeout(); | 203 void RouteCreationTimeout(); |
| 188 | 204 |
| 189 // Initializes the dialog with mirroring sources derived from |initiator|. | 205 // Initializes the dialog with mirroring sources derived from |initiator|. |
| 190 void InitCommon(content::WebContents* initiator); | 206 void InitCommon(content::WebContents* initiator); |
| 191 | 207 |
| 192 // PresentationServiceDelegateImpl::DefaultPresentationObserver | 208 // PresentationServiceDelegateImpl::DefaultPresentationObserver |
| 193 void OnDefaultPresentationChanged( | 209 void OnDefaultPresentationChanged( |
| 194 const PresentationRequest& presentation_request) override; | 210 const PresentationRequest& presentation_request) override; |
| 195 void OnDefaultPresentationRemoved() override; | 211 void OnDefaultPresentationRemoved() override; |
| 196 | 212 |
| 213 // Creates a brand new route or, if a |route_id| is supplied, connects to a | |
| 214 // non-local route. This is used for connecting to a non-local route. | |
|
stevenjb
2016/01/05 20:10:23
s/ / /
matt.boetger
2016/01/06 22:49:07
Done.
| |
| 215 // Returns true if a route request is successfully submitted. | |
| 216 // |OnRouteResponseReceived()| will be invoked when the route request | |
| 217 // completed. | |
|
stevenjb
2016/01/05 20:10:23
'completes' or 'is completed'
matt.boetger
2016/01/06 22:49:07
Done.
| |
| 218 bool CreateOrConnectRoute(const MediaSink::Id& sink_id, | |
| 219 MediaCastMode cast_mode, | |
| 220 const MediaRoute::Id& route_id); | |
| 221 | |
| 197 // Updates the set of supported cast modes and sends the updated set to | 222 // Updates the set of supported cast modes and sends the updated set to |
| 198 // |handler_|. | 223 // |handler_|. |
| 199 void UpdateCastModes(); | 224 void UpdateCastModes(); |
| 200 | 225 |
| 201 // Returns the default presentation request's frame URL if there is one. | 226 // Returns the default presentation request's frame URL if there is one. |
| 202 // Otherwise returns an empty GURL. | 227 // Otherwise returns an empty GURL. |
| 203 GURL GetFrameURL() const; | 228 GURL GetFrameURL() const; |
| 204 | 229 |
| 205 // Owned by the |web_ui| passed in the ctor, and guaranteed to be deleted | 230 // Owned by the |web_ui| passed in the ctor, and guaranteed to be deleted |
| 206 // only after it has deleted |this|. | 231 // only after it has deleted |this|. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 222 // Sequential counter for route requests. Used to update | 247 // Sequential counter for route requests. Used to update |
| 223 // |current_route_request_id_| when there is a new route request. | 248 // |current_route_request_id_| when there is a new route request. |
| 224 int route_request_counter_; | 249 int route_request_counter_; |
| 225 | 250 |
| 226 // Used for locale-aware sorting of sinks by name. Set during |InitCommon()| | 251 // Used for locale-aware sorting of sinks by name. Set during |InitCommon()| |
| 227 // using the current locale. Set to null | 252 // using the current locale. Set to null |
| 228 scoped_ptr<icu::Collator> collator_; | 253 scoped_ptr<icu::Collator> collator_; |
| 229 | 254 |
| 230 std::vector<MediaSinkWithCastModes> sinks_; | 255 std::vector<MediaSinkWithCastModes> sinks_; |
| 231 std::vector<MediaRoute> routes_; | 256 std::vector<MediaRoute> routes_; |
| 257 std::vector<MediaRoute::Id> joinable_route_ids_; | |
| 232 CastModeSet cast_modes_; | 258 CastModeSet cast_modes_; |
| 233 | 259 |
| 234 scoped_ptr<QueryResultManager> query_result_manager_; | 260 scoped_ptr<QueryResultManager> query_result_manager_; |
| 235 | 261 |
| 236 // If set, then the result of the next presentation route request will | 262 // If set, then the result of the next presentation route request will |
| 237 // be handled by this object. | 263 // be handled by this object. |
| 238 scoped_ptr<CreatePresentationConnectionRequest> create_session_request_; | 264 scoped_ptr<CreatePresentationConnectionRequest> create_session_request_; |
| 239 | 265 |
| 240 // Set to the presentation request corresponding to the presentation cast | 266 // Set to the presentation request corresponding to the presentation cast |
| 241 // mode, if supported. Otherwise set to nullptr. | 267 // mode, if supported. Otherwise set to nullptr. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 265 // NOTE: Weak pointers must be invalidated before all other member variables. | 291 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 266 // Therefore |weak_factory_| must be placed at the end. | 292 // Therefore |weak_factory_| must be placed at the end. |
| 267 base::WeakPtrFactory<MediaRouterUI> weak_factory_; | 293 base::WeakPtrFactory<MediaRouterUI> weak_factory_; |
| 268 | 294 |
| 269 DISALLOW_COPY_AND_ASSIGN(MediaRouterUI); | 295 DISALLOW_COPY_AND_ASSIGN(MediaRouterUI); |
| 270 }; | 296 }; |
| 271 | 297 |
| 272 } // namespace media_router | 298 } // namespace media_router |
| 273 | 299 |
| 274 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ | 300 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ |
| OLD | NEW |