Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: chrome/browser/ui/webui/media_router/media_router_ui.h

Issue 1363593003: [Media Router] Set timeout for route creation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes per imcheng@'s comments. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 {
126 return current_route_request_id_ != -1;
127 }
125 const GURL& frame_url() const { return frame_url_; } 128 const GURL& frame_url() const { return frame_url_; }
126 const std::vector<MediaSinkWithCastModes>& sinks() const { return sinks_; } 129 const std::vector<MediaSinkWithCastModes>& sinks() const { return sinks_; }
127 const std::vector<MediaRoute>& routes() const { return routes_; } 130 const std::vector<MediaRoute>& routes() const { return routes_; }
128 const std::set<MediaCastMode>& cast_modes() const { return cast_modes_; } 131 const std::set<MediaCastMode>& cast_modes() const { return cast_modes_; }
129 const content::WebContents* initiator() const { return initiator_; } 132 const content::WebContents* initiator() const { return initiator_; }
130 133
131 // Marked virtual for tests. 134 // Marked virtual for tests.
132 virtual const std::string& GetRouteProviderExtensionId() const; 135 virtual const std::string& GetRouteProviderExtensionId() const;
133 136
134 private: 137 private:
(...skipping 26 matching lines...) Expand all
161 // Called by |issues_observer_| when the top issue has changed. 164 // Called by |issues_observer_| when the top issue has changed.
162 // If the UI is already initialized, notifies |handler_| to update the UI. 165 // If the UI is already initialized, notifies |handler_| to update the UI.
163 // Ignored if the UI is not yet initialized. 166 // Ignored if the UI is not yet initialized.
164 void SetIssue(const Issue* issue); 167 void SetIssue(const Issue* issue);
165 168
166 // Called by |routes_observer_| when the set of active routes has changed. 169 // Called by |routes_observer_| when the set of active routes has changed.
167 void OnRoutesUpdated(const std::vector<MediaRoute>& routes); 170 void OnRoutesUpdated(const std::vector<MediaRoute>& routes);
168 171
169 // Callback passed to MediaRouter to receive response to route creation 172 // Callback passed to MediaRouter to receive response to route creation
170 // requests. 173 // requests.
171 void OnRouteResponseReceived(const MediaSink::Id& sink_id, 174 void OnRouteResponseReceived(const int route_request_id,
175 const MediaSink::Id& sink_id,
172 const MediaRoute* route, 176 const MediaRoute* route,
173 const std::string& presentation_id, 177 const std::string& presentation_id,
174 const std::string& error); 178 const std::string& error);
175 179
176 bool DoCreateRoute(const MediaSink::Id& sink_id, MediaCastMode cast_mode); 180 bool DoCreateRoute(const MediaSink::Id& sink_id, MediaCastMode cast_mode);
177 181
182 // Creates and sends an issue if route creation times out.
183 void RouteCreationTimeout();
184
178 // Sets the source host name to be displayed in the UI. 185 // Sets the source host name to be displayed in the UI.
179 // Gets cast modes from |query_result_manager_| and forwards it to UI. 186 // Gets cast modes from |query_result_manager_| and forwards it to UI.
180 // One of the Init* functions must have been called before. 187 // One of the Init* functions must have been called before.
181 void UpdateSourceHostAndCastModes(const GURL& frame_url); 188 void UpdateSourceHostAndCastModes(const GURL& frame_url);
182 189
183 // Initializes the dialog with mirroring sources derived from |initiator|, 190 // Initializes the dialog with mirroring sources derived from |initiator|,
184 // and optional |default_source| and |default_frame_url| if any. 191 // and optional |default_source| and |default_frame_url| if any.
185 void InitCommon(content::WebContents* initiator, 192 void InitCommon(content::WebContents* initiator,
186 const MediaSource& default_source, 193 const MediaSource& default_source,
187 const GURL& default_frame_url); 194 const GURL& default_frame_url);
188 195
189 // PresentationServiceDelegateImpl::DefaultMediaSourceObserver 196 // PresentationServiceDelegateImpl::DefaultMediaSourceObserver
190 void OnDefaultMediaSourceChanged(const MediaSource& source, 197 void OnDefaultMediaSourceChanged(const MediaSource& source,
191 const GURL& frame_url) override; 198 const GURL& frame_url) override;
192 199
193 // Owned by the |web_ui| passed in the ctor, and guaranteed to be deleted 200 // Owned by the |web_ui| passed in the ctor, and guaranteed to be deleted
194 // only after it has deleted |this|. 201 // only after it has deleted |this|.
195 MediaRouterWebUIMessageHandler* handler_; 202 MediaRouterWebUIMessageHandler* handler_;
196 203
197 // These are non-null while this instance is registered to receive 204 // These are non-null while this instance is registered to receive
198 // updates from them. 205 // updates from them.
199 scoped_ptr<IssuesObserver> issues_observer_; 206 scoped_ptr<IssuesObserver> issues_observer_;
200 scoped_ptr<MediaRoutesObserver> routes_observer_; 207 scoped_ptr<MediaRoutesObserver> routes_observer_;
201 208
202 // Set to true by |handler_| when the UI has been initialized. 209 // Set to true by |handler_| when the UI has been initialized.
203 bool ui_initialized_; 210 bool ui_initialized_;
204 211
205 // Set to |true| if there is a pending route request for this UI. 212 bool requesting_route_for_default_source_;
206 bool has_pending_route_request_;
207 213
208 bool requesting_route_for_default_source_; 214 // Set to -1 if not tracking a pending route request.
215 int current_route_request_id_;
216
217 // Sequential counter for route requests. Used to update
218 // |current_route_request_id_| when there is a new route request.
219 int route_request_counter_;
209 220
210 std::vector<MediaSinkWithCastModes> sinks_; 221 std::vector<MediaSinkWithCastModes> sinks_;
211 std::vector<MediaRoute> routes_; 222 std::vector<MediaRoute> routes_;
212 CastModeSet cast_modes_; 223 CastModeSet cast_modes_;
213 GURL frame_url_; 224 GURL frame_url_;
214 225
215 scoped_ptr<QueryResultManager> query_result_manager_; 226 scoped_ptr<QueryResultManager> query_result_manager_;
216 227
217 // If set, then the result of the next presentation route request will 228 // If set, then the result of the next presentation route request will
218 // be handled by this object. 229 // be handled by this object.
219 scoped_ptr<CreatePresentationSessionRequest> presentation_request_; 230 scoped_ptr<CreatePresentationSessionRequest> presentation_request_;
220 231
221 // It's possible for PresentationServiceDelegateImpl to be destroyed before 232 // It's possible for PresentationServiceDelegateImpl to be destroyed before
222 // this class. 233 // this class.
223 // (e.g. if a tab with the UI open is closed, then the tab WebContents will 234 // (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). 235 // be destroyed first momentarily before the UI WebContents).
225 // Holding a WeakPtr to PresentationServiceDelegateImpl is the cleanest way to 236 // Holding a WeakPtr to PresentationServiceDelegateImpl is the cleanest way to
226 // handle this. 237 // handle this.
227 // TODO(imcheng): hold a weak ptr to an abstract type instead. 238 // TODO(imcheng): hold a weak ptr to an abstract type instead.
228 base::WeakPtr<PresentationServiceDelegateImpl> presentation_service_delegate_; 239 base::WeakPtr<PresentationServiceDelegateImpl> presentation_service_delegate_;
229 240
230 content::WebContents* initiator_; 241 content::WebContents* initiator_;
231 242
232 // Pointer to the MediaRouter for this instance's BrowserContext. 243 // Pointer to the MediaRouter for this instance's BrowserContext.
233 MediaRouterMojoImpl* router_; 244 MediaRouterMojoImpl* router_;
234 245
246 // Timer used to implement a timeout on a create route request.
247 base::OneShotTimer route_creation_timer_;
248
235 // NOTE: Weak pointers must be invalidated before all other member variables. 249 // NOTE: Weak pointers must be invalidated before all other member variables.
236 // Therefore |weak_factory_| must be placed at the end. 250 // Therefore |weak_factory_| must be placed at the end.
237 base::WeakPtrFactory<MediaRouterUI> weak_factory_; 251 base::WeakPtrFactory<MediaRouterUI> weak_factory_;
238 252
239 DISALLOW_COPY_AND_ASSIGN(MediaRouterUI); 253 DISALLOW_COPY_AND_ASSIGN(MediaRouterUI);
240 }; 254 };
241 255
242 } // namespace media_router 256 } // namespace media_router
243 257
244 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_ 258 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_UI_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698