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> |
11 | 11 |
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/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/timer/timer.h" | |
16 #include "chrome/browser/media/router/issue.h" | 17 #include "chrome/browser/media/router/issue.h" |
17 #include "chrome/browser/media/router/media_source.h" | 18 #include "chrome/browser/media/router/media_source.h" |
18 #include "chrome/browser/media/router/presentation_service_delegate_impl.h" | 19 #include "chrome/browser/media/router/presentation_service_delegate_impl.h" |
19 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" | 20 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" |
20 #include "chrome/browser/ui/webui/media_router/media_cast_mode.h" | 21 #include "chrome/browser/ui/webui/media_router/media_cast_mode.h" |
21 #include "chrome/browser/ui/webui/media_router/media_sink_with_cast_modes.h" | 22 #include "chrome/browser/ui/webui/media_router/media_sink_with_cast_modes.h" |
22 #include "chrome/browser/ui/webui/media_router/query_result_manager.h" | 23 #include "chrome/browser/ui/webui/media_router/query_result_manager.h" |
23 #include "content/public/browser/web_ui_data_source.h" | 24 #include "content/public/browser/web_ui_data_source.h" |
24 | 25 |
25 namespace content { | 26 namespace content { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 // initially loaded. The header text is determined by the preferred cast mode. | 115 // initially loaded. The header text is determined by the preferred cast mode. |
115 std::string GetInitialHeaderText() const; | 116 std::string GetInitialHeaderText() const; |
116 | 117 |
117 // Returns the tooltip text for the header that should be displayed | 118 // Returns the tooltip text for the header that should be displayed |
118 // in the UI when it is initially loaded. At present, this text is | 119 // in the UI when it is initially loaded. At present, this text is |
119 // just the full hostname of the current site. | 120 // just the full hostname of the current site. |
120 std::string GetInitialHeaderTextTooltip() const; | 121 std::string GetInitialHeaderTextTooltip() const; |
121 | 122 |
122 // Returns the hostname of the default source's parent frame URL. | 123 // Returns the hostname of the default source's parent frame URL. |
123 std::string GetFrameURLHost() const; | 124 std::string GetFrameURLHost() const; |
124 bool has_pending_route_request() const { return has_pending_route_request_; } | 125 bool HasPendingRouteRequest() const { return !expected_route_guid_.empty(); } |
125 const GURL& frame_url() const { return frame_url_; } | 126 const GURL& frame_url() const { return frame_url_; } |
126 const std::vector<MediaSinkWithCastModes>& sinks() const { return sinks_; } | 127 const std::vector<MediaSinkWithCastModes>& sinks() const { return sinks_; } |
127 const std::vector<MediaRoute>& routes() const { return routes_; } | 128 const std::vector<MediaRoute>& routes() const { return routes_; } |
128 const std::set<MediaCastMode>& cast_modes() const { return cast_modes_; } | 129 const std::set<MediaCastMode>& cast_modes() const { return cast_modes_; } |
129 const content::WebContents* initiator() const { return initiator_; } | 130 const content::WebContents* initiator() const { return initiator_; } |
130 | 131 |
131 // Marked virtual for tests. | 132 // Marked virtual for tests. |
132 virtual const std::string& GetRouteProviderExtensionId() const; | 133 virtual const std::string& GetRouteProviderExtensionId() const; |
133 | 134 |
134 private: | 135 private: |
(...skipping 27 matching lines...) Expand all Loading... | |
162 // If the UI is already initialized, notifies |handler_| to update the UI. | 163 // If the UI is already initialized, notifies |handler_| to update the UI. |
163 // Ignored if the UI is not yet initialized. | 164 // Ignored if the UI is not yet initialized. |
164 void SetIssue(const Issue* issue); | 165 void SetIssue(const Issue* issue); |
165 | 166 |
166 // Called by |routes_observer_| when the set of active routes has changed. | 167 // Called by |routes_observer_| when the set of active routes has changed. |
167 void OnRoutesUpdated(const std::vector<MediaRoute>& routes); | 168 void OnRoutesUpdated(const std::vector<MediaRoute>& routes); |
168 | 169 |
169 // Callback passed to MediaRouter to receive response to route creation | 170 // Callback passed to MediaRouter to receive response to route creation |
170 // requests. | 171 // requests. |
171 void OnRouteResponseReceived(const MediaSink::Id& sink_id, | 172 void OnRouteResponseReceived(const MediaSink::Id& sink_id, |
173 const std::string& route_guid, | |
imcheng
2015/10/02 21:57:30
s/route_guid/route_request_id. I would also put th
apacible
2015/10/02 23:45:17
Done.
| |
172 const MediaRoute* route, | 174 const MediaRoute* route, |
173 const std::string& presentation_id, | 175 const std::string& presentation_id, |
174 const std::string& error); | 176 const std::string& error); |
175 | 177 |
176 bool DoCreateRoute(const MediaSink::Id& sink_id, MediaCastMode cast_mode); | 178 bool DoCreateRoute(const MediaSink::Id& sink_id, MediaCastMode cast_mode); |
177 | 179 |
180 // Creates and sends an issue if route creation times out. | |
181 void RouteCreationTimeout(); | |
182 | |
178 // Sets the source host name to be displayed in the UI. | 183 // Sets the source host name to be displayed in the UI. |
179 // Gets cast modes from |query_result_manager_| and forwards it to UI. | 184 // Gets cast modes from |query_result_manager_| and forwards it to UI. |
180 // One of the Init* functions must have been called before. | 185 // One of the Init* functions must have been called before. |
181 void UpdateSourceHostAndCastModes(const GURL& frame_url); | 186 void UpdateSourceHostAndCastModes(const GURL& frame_url); |
182 | 187 |
183 // Initializes the dialog with mirroring sources derived from |initiator|, | 188 // Initializes the dialog with mirroring sources derived from |initiator|, |
184 // and optional |default_source| and |default_frame_url| if any. | 189 // and optional |default_source| and |default_frame_url| if any. |
185 void InitCommon(content::WebContents* initiator, | 190 void InitCommon(content::WebContents* initiator, |
186 const MediaSource& default_source, | 191 const MediaSource& default_source, |
187 const GURL& default_frame_url); | 192 const GURL& default_frame_url); |
188 | 193 |
189 // PresentationServiceDelegateImpl::DefaultMediaSourceObserver | 194 // PresentationServiceDelegateImpl::DefaultMediaSourceObserver |
190 void OnDefaultMediaSourceChanged(const MediaSource& source, | 195 void OnDefaultMediaSourceChanged(const MediaSource& source, |
191 const GURL& frame_url) override; | 196 const GURL& frame_url) override; |
192 | 197 |
193 // Owned by the |web_ui| passed in the ctor, and guaranteed to be deleted | 198 // Owned by the |web_ui| passed in the ctor, and guaranteed to be deleted |
194 // only after it has deleted |this|. | 199 // only after it has deleted |this|. |
195 MediaRouterWebUIMessageHandler* handler_; | 200 MediaRouterWebUIMessageHandler* handler_; |
196 | 201 |
197 // These are non-null while this instance is registered to receive | 202 // These are non-null while this instance is registered to receive |
198 // updates from them. | 203 // updates from them. |
199 scoped_ptr<IssuesObserver> issues_observer_; | 204 scoped_ptr<IssuesObserver> issues_observer_; |
200 scoped_ptr<MediaRoutesObserver> routes_observer_; | 205 scoped_ptr<MediaRoutesObserver> routes_observer_; |
201 | 206 |
202 // Set to true by |handler_| when the UI has been initialized. | 207 // Set to true by |handler_| when the UI has been initialized. |
203 bool ui_initialized_; | 208 bool ui_initialized_; |
204 | 209 |
205 // Set to |true| if there is a pending route request for this UI. | 210 bool requesting_route_for_default_source_; |
206 bool has_pending_route_request_; | |
207 | 211 |
208 bool requesting_route_for_default_source_; | 212 // Set to a random GUID when expecting a route creation, or empty otherwise. |
imcheng
2015/10/02 21:57:30
suggestion: Set to non-empty if tracking a pending
apacible
2015/10/02 23:45:17
Done.
| |
213 // It's possible for a route request to time out in Media Router, then the | |
imcheng
2015/10/02 21:57:30
not sure if this comment is needed. Remove?
apacible
2015/10/02 23:45:17
Done.
| |
214 // provider sends a delayed route creation response. We check the GUIDs to | |
215 // determine if any action should be taken. | |
216 std::string expected_route_guid_; | |
imcheng
2015/10/02 21:57:30
I would just name this current_route_request_id_.
apacible
2015/10/02 23:45:17
Renamed. Switched to sequential counter.
| |
209 | 217 |
210 std::vector<MediaSinkWithCastModes> sinks_; | 218 std::vector<MediaSinkWithCastModes> sinks_; |
211 std::vector<MediaRoute> routes_; | 219 std::vector<MediaRoute> routes_; |
212 CastModeSet cast_modes_; | 220 CastModeSet cast_modes_; |
213 GURL frame_url_; | 221 GURL frame_url_; |
214 | 222 |
215 scoped_ptr<QueryResultManager> query_result_manager_; | 223 scoped_ptr<QueryResultManager> query_result_manager_; |
216 | 224 |
217 // If set, then the result of the next presentation route request will | 225 // If set, then the result of the next presentation route request will |
218 // be handled by this object. | 226 // be handled by this object. |
219 scoped_ptr<CreatePresentationSessionRequest> presentation_request_; | 227 scoped_ptr<CreatePresentationSessionRequest> presentation_request_; |
220 | 228 |
221 // It's possible for PresentationServiceDelegateImpl to be destroyed before | 229 // It's possible for PresentationServiceDelegateImpl to be destroyed before |
222 // this class. | 230 // this class. |
223 // (e.g. if a tab with the UI open is closed, then the tab WebContents will | 231 // (e.g. if a tab with the UI open is closed, then the tab WebContents will |
224 // be destroyed first momentarily before the UI WebContents). | 232 // be destroyed first momentarily before the UI WebContents). |
225 // Holding a WeakPtr to PresentationServiceDelegateImpl is the cleanest way to | 233 // Holding a WeakPtr to PresentationServiceDelegateImpl is the cleanest way to |
226 // handle this. | 234 // handle this. |
227 // TODO(imcheng): hold a weak ptr to an abstract type instead. | 235 // TODO(imcheng): hold a weak ptr to an abstract type instead. |
228 base::WeakPtr<PresentationServiceDelegateImpl> presentation_service_delegate_; | 236 base::WeakPtr<PresentationServiceDelegateImpl> presentation_service_delegate_; |
229 | 237 |
230 content::WebContents* initiator_; | 238 content::WebContents* initiator_; |
231 | 239 |
232 // Pointer to the MediaRouter for this instance's BrowserContext. | 240 // Pointer to the MediaRouter for this instance's BrowserContext. |
233 MediaRouterMojoImpl* router_; | 241 MediaRouterMojoImpl* router_; |
234 | 242 |
243 // Timer used to implement a timeout on a create route request. | |
244 base::OneShotTimer route_creation_timer_; | |
245 | |
235 // NOTE: Weak pointers must be invalidated before all other member variables. | 246 // NOTE: Weak pointers must be invalidated before all other member variables. |
236 // Therefore |weak_factory_| must be placed at the end. | 247 // Therefore |weak_factory_| must be placed at the end. |
237 base::WeakPtrFactory<MediaRouterUI> weak_factory_; | 248 base::WeakPtrFactory<MediaRouterUI> weak_factory_; |
238 | 249 |
239 DISALLOW_COPY_AND_ASSIGN(MediaRouterUI); | 250 DISALLOW_COPY_AND_ASSIGN(MediaRouterUI); |
240 }; | 251 }; |
241 | 252 |
242 } // namespace media_router | 253 } // namespace media_router |
243 | 254 |
244 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ | 255 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ |
OLD | NEW |