| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 // Notifies this instance that the UI has been initialized. | 91 // Notifies this instance that the UI has been initialized. |
| 92 void UIInitialized(); | 92 void UIInitialized(); |
| 93 | 93 |
| 94 // Requests a route be created from the source mapped to | 94 // Requests a route be created from the source mapped to |
| 95 // |cast_mode|, to the sink given by |sink_id|. | 95 // |cast_mode|, to the sink given by |sink_id|. |
| 96 // Returns true if a route request is successfully submitted. | 96 // Returns true if a route request is successfully submitted. |
| 97 // |OnRouteResponseReceived()| will be invoked when the route request | 97 // |OnRouteResponseReceived()| will be invoked when the route request |
| 98 // completes. | 98 // completes. |
| 99 bool CreateRoute(const MediaSink::Id& sink_id, MediaCastMode cast_mode); | 99 bool CreateRoute(const MediaSink::Id& sink_id, MediaCastMode cast_mode); |
| 100 | 100 |
| 101 // Calls MediaRouter to join the given route. |
| 102 bool JoinRoute(const MediaSink::Id& sink_id, const MediaRoute::Id& route_id); |
| 103 |
| 101 // Calls MediaRouter to close the given route. | 104 // Calls MediaRouter to close the given route. |
| 102 void CloseRoute(const MediaRoute::Id& route_id); | 105 void CloseRoute(const MediaRoute::Id& route_id); |
| 103 | 106 |
| 104 // Calls MediaRouter to add the given issue. | 107 // Calls MediaRouter to add the given issue. |
| 105 void AddIssue(const Issue& issue); | 108 void AddIssue(const Issue& issue); |
| 106 | 109 |
| 107 // Calls MediaRouter to clear the given issue. | 110 // Calls MediaRouter to clear the given issue. |
| 108 void ClearIssue(const Issue::Id& issue_id); | 111 void ClearIssue(const Issue::Id& issue_id); |
| 109 | 112 |
| 110 // Returns the hostname of the default source's parent frame URL. | 113 // Returns the hostname of the default source's parent frame URL. |
| 111 std::string GetPresentationRequestSourceName() const; | 114 std::string GetPresentationRequestSourceName() const; |
| 112 std::string GetTruncatedPresentationRequestSourceName() const; | 115 std::string GetTruncatedPresentationRequestSourceName() const; |
| 113 bool HasPendingRouteRequest() const { | 116 bool HasPendingRouteRequest() const { |
| 114 return current_route_request_id_ != -1; | 117 return current_route_request_id_ != -1; |
| 115 } | 118 } |
| 116 const std::vector<MediaSinkWithCastModes>& sinks() const { return sinks_; } | 119 const std::vector<MediaSinkWithCastModes>& sinks() const { return sinks_; } |
| 117 const std::vector<MediaRoute>& routes() const { return routes_; } | 120 const std::vector<MediaRoute>& routes() const { return routes_; } |
| 121 const std::vector<MediaRoute::Id>& joinable_route_ids() const { |
| 122 return joinable_route_ids_; |
| 123 } |
| 118 const std::set<MediaCastMode>& cast_modes() const { return cast_modes_; } | 124 const std::set<MediaCastMode>& cast_modes() const { return cast_modes_; } |
| 119 const content::WebContents* initiator() const { return initiator_; } | 125 const content::WebContents* initiator() const { return initiator_; } |
| 120 | 126 |
| 121 // Marked virtual for tests. | 127 // Marked virtual for tests. |
| 122 virtual const std::string& GetRouteProviderExtensionId() const; | 128 virtual const std::string& GetRouteProviderExtensionId() const; |
| 123 | 129 |
| 124 private: | 130 private: |
| 125 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 131 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
| 126 UIMediaRoutesObserverFiltersNonDisplayRoutes); | 132 UIMediaRoutesObserverFiltersNonDisplayRoutes); |
| 133 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
| 134 UIMediaRoutesObserverFiltersNonDisplayJoinableRoutes); |
| 127 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, GetExtensionNameExtensionPresent); | 135 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, GetExtensionNameExtensionPresent); |
| 128 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 136 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
| 129 GetExtensionNameEmptyWhenNotInstalled); | 137 GetExtensionNameEmptyWhenNotInstalled); |
| 130 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, | 138 FRIEND_TEST_ALL_PREFIXES(MediaRouterUITest, |
| 131 GetExtensionNameEmptyWhenNotExtensionURL); | 139 GetExtensionNameEmptyWhenNotExtensionURL); |
| 132 | 140 |
| 133 class UIIssuesObserver; | 141 class UIIssuesObserver; |
| 142 |
| 134 class UIMediaRoutesObserver : public MediaRoutesObserver { | 143 class UIMediaRoutesObserver : public MediaRoutesObserver { |
| 135 public: | 144 public: |
| 136 using RoutesUpdatedCallback = | 145 using RoutesUpdatedCallback = |
| 137 base::Callback<void(const std::vector<MediaRoute>&)>; | 146 base::Callback<void(const std::vector<MediaRoute>&, |
| 138 UIMediaRoutesObserver(MediaRouter* router, | 147 const std::vector<MediaRoute::Id>&)>; |
| 148 UIMediaRoutesObserver(MediaRouter* router, const MediaSource::Id& source_id, |
| 139 const RoutesUpdatedCallback& callback); | 149 const RoutesUpdatedCallback& callback); |
| 140 ~UIMediaRoutesObserver() override; | 150 ~UIMediaRoutesObserver() override; |
| 141 | 151 |
| 142 // MediaRoutesObserver | 152 // MediaRoutesObserver |
| 143 void OnRoutesUpdated(const std::vector<MediaRoute>& routes) override; | 153 void OnRoutesUpdated( |
| 154 const std::vector<MediaRoute>& routes, |
| 155 const std::vector<MediaRoute::Id>& joinable_route_ids) override; |
| 144 | 156 |
| 145 private: | 157 private: |
| 146 // Callback to the owning MediaRouterUI instance. | 158 // Callback to the owning MediaRouterUI instance. |
| 147 RoutesUpdatedCallback callback_; | 159 RoutesUpdatedCallback callback_; |
| 148 | 160 |
| 149 DISALLOW_COPY_AND_ASSIGN(UIMediaRoutesObserver); | 161 DISALLOW_COPY_AND_ASSIGN(UIMediaRoutesObserver); |
| 150 }; | 162 }; |
| 151 | 163 |
| 152 static std::string GetExtensionName(const GURL& url, | 164 static std::string GetExtensionName(const GURL& url, |
| 153 extensions::ExtensionRegistry* registry); | 165 extensions::ExtensionRegistry* registry); |
| 154 | 166 |
| 155 // QueryResultManager::Observer | 167 // QueryResultManager::Observer |
| 156 void OnResultsUpdated( | 168 void OnResultsUpdated( |
| 157 const std::vector<MediaSinkWithCastModes>& sinks) override; | 169 const std::vector<MediaSinkWithCastModes>& sinks) override; |
| 158 | 170 |
| 159 // Called by |issues_observer_| when the top issue has changed. | 171 // Called by |issues_observer_| when the top issue has changed. |
| 160 // If the UI is already initialized, notifies |handler_| to update the UI. | 172 // If the UI is already initialized, notifies |handler_| to update the UI. |
| 161 // Ignored if the UI is not yet initialized. | 173 // Ignored if the UI is not yet initialized. |
| 162 void SetIssue(const Issue* issue); | 174 void SetIssue(const Issue* issue); |
| 163 | 175 |
| 164 // Called by |routes_observer_| when the set of active routes has changed. | 176 // Called by |routes_observer_| when the set of active routes has changed. |
| 165 void OnRoutesUpdated(const std::vector<MediaRoute>& routes); | 177 void OnRoutesUpdated(const std::vector<MediaRoute>& routes, |
| 178 const std::vector<MediaRoute::Id>& joinable_route_ids); |
| 166 | 179 |
| 167 // Callback passed to MediaRouter to receive response to route creation | 180 // Callback passed to MediaRouter to receive response to route creation |
| 168 // requests. | 181 // requests. |
| 169 void OnRouteResponseReceived(const int route_request_id, | 182 void OnRouteResponseReceived(const int route_request_id, |
| 170 const MediaSink::Id& sink_id, | 183 const MediaSink::Id& sink_id, |
| 171 const MediaRoute* route, | 184 const MediaRoute* route, |
| 172 const std::string& presentation_id, | 185 const std::string& presentation_id, |
| 173 const std::string& error); | 186 const std::string& error); |
| 174 | 187 |
| 175 // Creates and sends an issue if route creation times out. | 188 // Creates and sends an issue if route creation times out. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 | 220 |
| 208 // Set to -1 if not tracking a pending route request. | 221 // Set to -1 if not tracking a pending route request. |
| 209 int current_route_request_id_; | 222 int current_route_request_id_; |
| 210 | 223 |
| 211 // Sequential counter for route requests. Used to update | 224 // Sequential counter for route requests. Used to update |
| 212 // |current_route_request_id_| when there is a new route request. | 225 // |current_route_request_id_| when there is a new route request. |
| 213 int route_request_counter_; | 226 int route_request_counter_; |
| 214 | 227 |
| 215 std::vector<MediaSinkWithCastModes> sinks_; | 228 std::vector<MediaSinkWithCastModes> sinks_; |
| 216 std::vector<MediaRoute> routes_; | 229 std::vector<MediaRoute> routes_; |
| 230 std::vector<MediaRoute::Id> joinable_route_ids_; |
| 217 CastModeSet cast_modes_; | 231 CastModeSet cast_modes_; |
| 218 | 232 |
| 219 scoped_ptr<QueryResultManager> query_result_manager_; | 233 scoped_ptr<QueryResultManager> query_result_manager_; |
| 220 | 234 |
| 221 // If set, then the result of the next presentation route request will | 235 // If set, then the result of the next presentation route request will |
| 222 // be handled by this object. | 236 // be handled by this object. |
| 223 scoped_ptr<CreatePresentationConnectionRequest> create_session_request_; | 237 scoped_ptr<CreatePresentationConnectionRequest> create_session_request_; |
| 224 | 238 |
| 225 // Set to the presentation request corresponding to the presentation cast | 239 // Set to the presentation request corresponding to the presentation cast |
| 226 // mode, if supported. Otherwise set to nullptr. | 240 // mode, if supported. Otherwise set to nullptr. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 246 // NOTE: Weak pointers must be invalidated before all other member variables. | 260 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 247 // Therefore |weak_factory_| must be placed at the end. | 261 // Therefore |weak_factory_| must be placed at the end. |
| 248 base::WeakPtrFactory<MediaRouterUI> weak_factory_; | 262 base::WeakPtrFactory<MediaRouterUI> weak_factory_; |
| 249 | 263 |
| 250 DISALLOW_COPY_AND_ASSIGN(MediaRouterUI); | 264 DISALLOW_COPY_AND_ASSIGN(MediaRouterUI); |
| 251 }; | 265 }; |
| 252 | 266 |
| 253 } // namespace media_router | 267 } // namespace media_router |
| 254 | 268 |
| 255 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ | 269 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ |
| OLD | NEW |