| 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 <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 std::string GetTruncatedPresentationRequestSourceName() const; | 130 std::string GetTruncatedPresentationRequestSourceName() const; |
| 131 bool HasPendingRouteRequest() const { | 131 bool HasPendingRouteRequest() const { |
| 132 return current_route_request_id_ != -1; | 132 return current_route_request_id_ != -1; |
| 133 } | 133 } |
| 134 const std::vector<MediaSinkWithCastModes>& sinks() const { return sinks_; } | 134 const std::vector<MediaSinkWithCastModes>& sinks() const { return sinks_; } |
| 135 const std::vector<MediaRoute>& routes() const { return routes_; } | 135 const std::vector<MediaRoute>& routes() const { return routes_; } |
| 136 const std::vector<MediaRoute::Id>& joinable_route_ids() const { | 136 const std::vector<MediaRoute::Id>& joinable_route_ids() const { |
| 137 return joinable_route_ids_; | 137 return joinable_route_ids_; |
| 138 } | 138 } |
| 139 const std::set<MediaCastMode>& cast_modes() const { return cast_modes_; } | 139 const std::set<MediaCastMode>& cast_modes() const { return cast_modes_; } |
| 140 const std::unordered_map<MediaRoute::Id, MediaCastMode>& current_cast_modes() |
| 141 const { |
| 142 return current_cast_modes_; |
| 143 } |
| 140 const content::WebContents* initiator() const { return initiator_; } | 144 const content::WebContents* initiator() const { return initiator_; } |
| 141 | 145 |
| 142 // Marked virtual for tests. | 146 // Marked virtual for tests. |
| 143 virtual const std::string& GetRouteProviderExtensionId() const; | 147 virtual const std::string& GetRouteProviderExtensionId() const; |
| 144 | 148 |
| 145 // Called to track UI metrics. | 149 // Called to track UI metrics. |
| 146 void SetUIInitializationTimer(const base::Time& start_time); | 150 void SetUIInitializationTimer(const base::Time& start_time); |
| 147 void OnUIInitiallyLoaded(); | 151 void OnUIInitiallyLoaded(); |
| 148 void OnUIInitialDataReceived(); | 152 void OnUIInitialDataReceived(); |
| 149 | 153 |
| 150 void UpdateMaxDialogHeight(int height); | 154 void UpdateMaxDialogHeight(int height); |
| 151 | 155 |
| 152 void InitForTest(MediaRouter* router, | 156 void InitForTest(MediaRouter* router, |
| 153 content::WebContents* initiator, | 157 content::WebContents* initiator, |
| 154 MediaRouterWebUIMessageHandler* handler); | 158 MediaRouterWebUIMessageHandler* handler); |
| 155 | 159 |
| 156 private: | 160 private: |
| 157 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SortedSinks); | 161 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, SortedSinks); |
| 158 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 162 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
| 159 UIMediaRoutesObserverFiltersNonDisplayRoutes); | 163 UIMediaRoutesObserverFiltersNonDisplayRoutes); |
| 160 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 164 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
| 161 UIMediaRoutesObserverFiltersNonDisplayJoinableRoutes); | 165 UIMediaRoutesObserverFiltersNonDisplayJoinableRoutes); |
| 166 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
| 167 UIMediaRoutesObserverAssignsCurrentCastModes); |
| 168 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
| 169 UIMediaRoutesObserverSkipsUnavailableCastModes); |
| 170 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
| 171 UIMediaRoutesObserverFiltersNonDisplayJoinableRoutes); |
| 162 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, GetExtensionNameExtensionPresent); | 172 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, GetExtensionNameExtensionPresent); |
| 163 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 173 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
| 164 GetExtensionNameEmptyWhenNotInstalled); | 174 GetExtensionNameEmptyWhenNotInstalled); |
| 165 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 175 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
| 166 GetExtensionNameEmptyWhenNotExtensionURL); | 176 GetExtensionNameEmptyWhenNotExtensionURL); |
| 167 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 177 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
| 168 RouteCreationTimeoutForPresentation); | 178 RouteCreationTimeoutForPresentation); |
| 169 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, RouteRequestFromIncognito); | 179 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, RouteRequestFromIncognito); |
| 170 | 180 |
| 171 class UIIssuesObserver; | 181 class UIIssuesObserver; |
| 172 | 182 |
| 173 class UIMediaRoutesObserver : public MediaRoutesObserver { | 183 class UIMediaRoutesObserver : public MediaRoutesObserver { |
| 174 public: | 184 public: |
| 175 using RoutesUpdatedCallback = | 185 using RoutesUpdatedCallback = base::Callback<void( |
| 176 base::Callback<void(const std::vector<MediaRoute>&, | 186 const std::vector<MediaRoute>&, |
| 177 const std::vector<MediaRoute::Id>&)>; | 187 const std::vector<MediaRoute::Id>&, |
| 178 UIMediaRoutesObserver(MediaRouter* router, const MediaSource::Id& source_id, | 188 const std::unordered_map<MediaRoute::Id, MediaCastMode>&)>; |
| 179 const RoutesUpdatedCallback& callback); | 189 using SourceCastModeMapCallback = |
| 190 base::Callback<std::unordered_map<MediaSource::Id, MediaCastMode>()>; |
| 191 UIMediaRoutesObserver( |
| 192 MediaRouter* router, |
| 193 const MediaSource::Id& source_id, |
| 194 const SourceCastModeMapCallback& source_cast_mode_callback, |
| 195 const RoutesUpdatedCallback& callback); |
| 180 ~UIMediaRoutesObserver() override; | 196 ~UIMediaRoutesObserver() override; |
| 181 | 197 |
| 182 // MediaRoutesObserver | 198 // MediaRoutesObserver |
| 183 void OnRoutesUpdated( | 199 void OnRoutesUpdated( |
| 184 const std::vector<MediaRoute>& routes, | 200 const std::vector<MediaRoute>& routes, |
| 185 const std::vector<MediaRoute::Id>& joinable_route_ids) override; | 201 const std::vector<MediaRoute::Id>& joinable_route_ids) override; |
| 186 | 202 |
| 187 private: | 203 private: |
| 188 // Callback to the owning MediaRouterUI instance. | 204 // Callbacks to the owning MediaRouterUI instance. |
| 205 SourceCastModeMapCallback source_cast_mode_callback_; |
| 189 RoutesUpdatedCallback callback_; | 206 RoutesUpdatedCallback callback_; |
| 190 | 207 |
| 191 DISALLOW_COPY_AND_ASSIGN(UIMediaRoutesObserver); | 208 DISALLOW_COPY_AND_ASSIGN(UIMediaRoutesObserver); |
| 192 }; | 209 }; |
| 193 | 210 |
| 194 static std::string GetExtensionName(const GURL& url, | 211 static std::string GetExtensionName(const GURL& url, |
| 195 extensions::ExtensionRegistry* registry); | 212 extensions::ExtensionRegistry* registry); |
| 196 | 213 |
| 197 // QueryResultManager::Observer | 214 // QueryResultManager::Observer |
| 198 void OnResultsUpdated( | 215 void OnResultsUpdated( |
| 199 const std::vector<MediaSinkWithCastModes>& sinks) override; | 216 const std::vector<MediaSinkWithCastModes>& sinks) override; |
| 200 | 217 |
| 201 // Called by |issues_observer_| when the top issue has changed. | 218 // Called by |issues_observer_| when the top issue has changed. |
| 202 // If the UI is already initialized, notifies |handler_| to update the UI. | 219 // If the UI is already initialized, notifies |handler_| to update the UI. |
| 203 // Ignored if the UI is not yet initialized. | 220 // Ignored if the UI is not yet initialized. |
| 204 void SetIssue(const Issue* issue); | 221 void SetIssue(const Issue* issue); |
| 205 | 222 |
| 223 // Called by |routes_observer_| to get an updated map from media sources to |
| 224 // their current cast mode. |
| 225 std::unordered_map<MediaSource::Id, MediaCastMode> GetAvailableSourceMap(); |
| 226 |
| 206 // Called by |routes_observer_| when the set of active routes has changed. | 227 // Called by |routes_observer_| when the set of active routes has changed. |
| 207 void OnRoutesUpdated(const std::vector<MediaRoute>& routes, | 228 void OnRoutesUpdated(const std::vector<MediaRoute>& routes, |
| 208 const std::vector<MediaRoute::Id>& joinable_route_ids); | 229 const std::vector<MediaRoute::Id>& joinable_route_ids, |
| 230 const std::unordered_map<MediaRoute::Id, MediaCastMode>& |
| 231 current_cast_modes); |
| 209 | 232 |
| 210 // Callback passed to MediaRouter to receive response to route creation | 233 // Callback passed to MediaRouter to receive response to route creation |
| 211 // requests. | 234 // requests. |
| 212 void OnRouteResponseReceived( | 235 void OnRouteResponseReceived( |
| 213 int route_request_id, | 236 int route_request_id, |
| 214 const MediaSink::Id& sink_id, | 237 const MediaSink::Id& sink_id, |
| 215 MediaCastMode cast_mode, | 238 MediaCastMode cast_mode, |
| 216 const base::string16& presentation_request_source_name, | 239 const base::string16& presentation_request_source_name, |
| 217 const RouteRequestResult& result); | 240 const RouteRequestResult& result); |
| 218 | 241 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 int route_request_counter_; | 299 int route_request_counter_; |
| 277 | 300 |
| 278 // Used for locale-aware sorting of sinks by name. Set during |InitCommon()| | 301 // Used for locale-aware sorting of sinks by name. Set during |InitCommon()| |
| 279 // using the current locale. Set to null | 302 // using the current locale. Set to null |
| 280 std::unique_ptr<icu::Collator> collator_; | 303 std::unique_ptr<icu::Collator> collator_; |
| 281 | 304 |
| 282 std::vector<MediaSinkWithCastModes> sinks_; | 305 std::vector<MediaSinkWithCastModes> sinks_; |
| 283 std::vector<MediaRoute> routes_; | 306 std::vector<MediaRoute> routes_; |
| 284 std::vector<MediaRoute::Id> joinable_route_ids_; | 307 std::vector<MediaRoute::Id> joinable_route_ids_; |
| 285 CastModeSet cast_modes_; | 308 CastModeSet cast_modes_; |
| 309 std::unordered_map<MediaRoute::Id, MediaCastMode> current_cast_modes_; |
| 286 | 310 |
| 287 std::unique_ptr<QueryResultManager> query_result_manager_; | 311 std::unique_ptr<QueryResultManager> query_result_manager_; |
| 288 | 312 |
| 289 // If set, then the result of the next presentation route request will | 313 // If set, then the result of the next presentation route request will |
| 290 // be handled by this object. | 314 // be handled by this object. |
| 291 std::unique_ptr<CreatePresentationConnectionRequest> create_session_request_; | 315 std::unique_ptr<CreatePresentationConnectionRequest> create_session_request_; |
| 292 | 316 |
| 293 // Set to the presentation request corresponding to the presentation cast | 317 // Set to the presentation request corresponding to the presentation cast |
| 294 // mode, if supported. Otherwise set to nullptr. | 318 // mode, if supported. Otherwise set to nullptr. |
| 295 std::unique_ptr<PresentationRequest> presentation_request_; | 319 std::unique_ptr<PresentationRequest> presentation_request_; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 315 // NOTE: Weak pointers must be invalidated before all other member variables. | 339 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 316 // Therefore |weak_factory_| must be placed at the end. | 340 // Therefore |weak_factory_| must be placed at the end. |
| 317 base::WeakPtrFactory<MediaRouterUI> weak_factory_; | 341 base::WeakPtrFactory<MediaRouterUI> weak_factory_; |
| 318 | 342 |
| 319 DISALLOW_COPY_AND_ASSIGN(MediaRouterUI); | 343 DISALLOW_COPY_AND_ASSIGN(MediaRouterUI); |
| 320 }; | 344 }; |
| 321 | 345 |
| 322 } // namespace media_router | 346 } // namespace media_router |
| 323 | 347 |
| 324 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ | 348 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ |
| OLD | NEW |