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

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

Issue 2547703002: [Media Router] Handle multiple Presentation URLs when creating routes (Closed)
Patch Set: resolve code review comments from Mark Created 4 years 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 #include "chrome/browser/ui/webui/media_router/media_router_ui.h" 5 #include "chrome/browser/ui/webui/media_router/media_router_ui.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <unordered_map> 9 #include <unordered_map>
10 #include <utility> 10 #include <utility>
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 case TAB_MIRROR: 81 case TAB_MIRROR:
82 return base::TimeDelta::FromSeconds(kCreateRouteTimeoutSecondsForTab); 82 return base::TimeDelta::FromSeconds(kCreateRouteTimeoutSecondsForTab);
83 case DESKTOP_MIRROR: 83 case DESKTOP_MIRROR:
84 return base::TimeDelta::FromSeconds(kCreateRouteTimeoutSecondsForDesktop); 84 return base::TimeDelta::FromSeconds(kCreateRouteTimeoutSecondsForDesktop);
85 default: 85 default:
86 NOTREACHED(); 86 NOTREACHED();
87 return base::TimeDelta(); 87 return base::TimeDelta();
88 } 88 }
89 } 89 }
90 90
91 // Returns the first source in |sources| that can be connected to by using the
92 // "Cast" button in the dialog, or an empty source if there is none. This is
93 // used by the Media Router to find such a matching route if it exists.
94 MediaSource GetSourceForRouteObserver(const std::vector<MediaSource>& sources) {
95 auto source_it =
96 std::find_if(sources.begin(), sources.end(), CanConnectToMediaSource);
97 return source_it != sources.end() ? *source_it : MediaSource("");
98 }
99
91 } // namespace 100 } // namespace
92 101
93 // static 102 // static
94 std::string MediaRouterUI::GetExtensionName( 103 std::string MediaRouterUI::GetExtensionName(
95 const GURL& gurl, extensions::ExtensionRegistry* registry) { 104 const GURL& gurl, extensions::ExtensionRegistry* registry) {
96 if (gurl.is_empty() || !registry) return std::string(); 105 if (gurl.is_empty() || !registry) return std::string();
97 106
98 const extensions::Extension* extension = 107 const extensions::Extension* extension =
99 registry->enabled_extensions().GetExtensionOrAppByURL(gurl); 108 registry->enabled_extensions().GetExtensionOrAppByURL(gurl);
100 109
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 } 325 }
317 } 326 }
318 327
319 void MediaRouterUI::OnDefaultPresentationChanged( 328 void MediaRouterUI::OnDefaultPresentationChanged(
320 const PresentationRequest& presentation_request) { 329 const PresentationRequest& presentation_request) {
321 std::vector<MediaSource> sources = presentation_request.GetMediaSources(); 330 std::vector<MediaSource> sources = presentation_request.GetMediaSources();
322 presentation_request_.reset(new PresentationRequest(presentation_request)); 331 presentation_request_.reset(new PresentationRequest(presentation_request));
323 query_result_manager_->SetSourcesForCastMode( 332 query_result_manager_->SetSourcesForCastMode(
324 MediaCastMode::DEFAULT, sources, 333 MediaCastMode::DEFAULT, sources,
325 presentation_request_->frame_url().GetOrigin()); 334 presentation_request_->frame_url().GetOrigin());
326 // Register for MediaRoute updates. 335 // Register for MediaRoute updates. NOTE(mfoltz): If there are multiple
327 // TODO(crbug.com/627655): Use multiple URLs. 336 // sources that can be connected to via the dialog, this will break. We will
337 // need to observe multiple sources (keyed by sinks) in that case. As this is
338 // Cast-specific for the forseeable future, it may be simpler to plumb a new
339 // observer API for this case.
imcheng 2016/12/05 21:58:39 +1, A specific API to query routes joinable with a
zhaobin 2016/12/06 20:06:37 Acknowledged.
340 const MediaSource source_for_route_observer =
341 GetSourceForRouteObserver(sources);
328 routes_observer_.reset(new UIMediaRoutesObserver( 342 routes_observer_.reset(new UIMediaRoutesObserver(
329 router_, sources[0].id(), 343 router_, source_for_route_observer.id(),
330 base::Bind(&MediaRouterUI::OnRoutesUpdated, base::Unretained(this)))); 344 base::Bind(&MediaRouterUI::OnRoutesUpdated, base::Unretained(this))));
331 345
332 UpdateCastModes(); 346 UpdateCastModes();
333 } 347 }
334 348
335 void MediaRouterUI::OnDefaultPresentationRemoved() { 349 void MediaRouterUI::OnDefaultPresentationRemoved() {
336 presentation_request_.reset(); 350 presentation_request_.reset();
337 query_result_manager_->RemoveSourcesForCastMode(MediaCastMode::DEFAULT); 351 query_result_manager_->RemoveSourcesForCastMode(MediaCastMode::DEFAULT);
338 // Register for MediaRoute updates without a media source. 352 // Register for MediaRoute updates without a media source.
339 routes_observer_.reset(new UIMediaRoutesObserver( 353 routes_observer_.reset(new UIMediaRoutesObserver(
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 base::Time::Now() - start_time_); 704 base::Time::Now() - start_time_);
691 start_time_ = base::Time(); 705 start_time_ = base::Time();
692 } 706 }
693 } 707 }
694 708
695 void MediaRouterUI::UpdateMaxDialogHeight(int height) { 709 void MediaRouterUI::UpdateMaxDialogHeight(int height) {
696 handler_->UpdateMaxDialogHeight(height); 710 handler_->UpdateMaxDialogHeight(height);
697 } 711 }
698 712
699 } // namespace media_router 713 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698