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

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

Issue 2264153002: [Presentation API] Add support for multiple URLs in PresentationRequest on Media Router UI side (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Create CastModesWithMediaSources Created 4 years, 3 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 #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 <utility> 10 #include <utility>
10 11
11 #include "base/guid.h" 12 #include "base/guid.h"
12 #include "base/i18n/string_compare.h" 13 #include "base/i18n/string_compare.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
16 #include "base/trace_event/trace_event.h" 17 #include "base/trace_event/trace_event.h"
17 #include "build/build_config.h" 18 #include "build/build_config.h"
18 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 } 279 }
279 280
280 query_result_manager_.reset(new QueryResultManager(router_)); 281 query_result_manager_.reset(new QueryResultManager(router_));
281 query_result_manager_->AddObserver(this); 282 query_result_manager_->AddObserver(this);
282 283
283 // Use a placeholder URL as origin for mirroring. 284 // Use a placeholder URL as origin for mirroring.
284 GURL origin(chrome::kChromeUIMediaRouterURL); 285 GURL origin(chrome::kChromeUIMediaRouterURL);
285 286
286 // Desktop mirror mode is always available. 287 // Desktop mirror mode is always available.
287 query_result_manager_->StartSinksQuery(MediaCastMode::DESKTOP_MIRROR, 288 query_result_manager_->StartSinksQuery(MediaCastMode::DESKTOP_MIRROR,
288 MediaSourceForDesktop(), origin); 289 {MediaSourceForDesktop()}, origin);
289 initiator_ = initiator; 290 initiator_ = initiator;
290 SessionID::id_type tab_id = SessionTabHelper::IdForTab(initiator); 291 SessionID::id_type tab_id = SessionTabHelper::IdForTab(initiator);
291 if (tab_id != -1) { 292 if (tab_id != -1) {
292 MediaSource mirroring_source(MediaSourceForTab(tab_id)); 293 MediaSource mirroring_source(MediaSourceForTab(tab_id));
293 query_result_manager_->StartSinksQuery(MediaCastMode::TAB_MIRROR, 294 query_result_manager_->StartSinksQuery(MediaCastMode::TAB_MIRROR,
294 mirroring_source, origin); 295 {mirroring_source}, origin);
295 } 296 }
296 UpdateCastModes(); 297 UpdateCastModes();
297 } 298 }
298 299
299 void MediaRouterUI::InitForTest( 300 void MediaRouterUI::InitForTest(
300 MediaRouter* router, 301 MediaRouter* router,
301 content::WebContents* initiator, 302 content::WebContents* initiator,
302 MediaRouterWebUIMessageHandler* handler, 303 MediaRouterWebUIMessageHandler* handler,
303 std::unique_ptr<CreatePresentationConnectionRequest> 304 std::unique_ptr<CreatePresentationConnectionRequest>
304 create_session_request) { 305 create_session_request) {
305 router_ = router; 306 router_ = router;
306 handler_ = handler; 307 handler_ = handler;
307 create_session_request_ = std::move(create_session_request); 308 create_session_request_ = std::move(create_session_request);
308 InitCommon(initiator); 309 InitCommon(initiator);
309 if (create_session_request_) { 310 if (create_session_request_) {
310 OnDefaultPresentationChanged( 311 OnDefaultPresentationChanged(
311 create_session_request_->presentation_request()); 312 create_session_request_->presentation_request());
312 } 313 }
313 } 314 }
314 315
315 void MediaRouterUI::OnDefaultPresentationChanged( 316 void MediaRouterUI::OnDefaultPresentationChanged(
316 const PresentationRequest& presentation_request) { 317 const PresentationRequest& presentation_request) {
317 MediaSource source = presentation_request.GetMediaSource(); 318 std::vector<MediaSource> sources = presentation_request.GetMediaSources();
318 presentation_request_.reset(new PresentationRequest(presentation_request)); 319 presentation_request_.reset(new PresentationRequest(presentation_request));
319 query_result_manager_->StartSinksQuery( 320 query_result_manager_->StartSinksQuery(
320 MediaCastMode::DEFAULT, source, 321 MediaCastMode::DEFAULT, sources,
321 presentation_request_->frame_url().GetOrigin()); 322 presentation_request_->frame_url().GetOrigin());
322 // Register for MediaRoute updates. 323 // Register for MediaRoute updates.
324 // TODO(crbug.com/627655): Use multiple URLs.
mark a. foltz 2016/08/31 05:18:55 Sigh, this is not straightforward. The MediaRoute
takumif 2016/09/01 21:09:25 Yeah, I wasn't sure what to do here.
323 routes_observer_.reset(new UIMediaRoutesObserver( 325 routes_observer_.reset(new UIMediaRoutesObserver(
324 router_, source.id(), 326 router_, sources[0].id(),
325 base::Bind(&MediaRouterUI::OnRoutesUpdated, base::Unretained(this)))); 327 base::Bind(&MediaRouterUI::OnRoutesUpdated, base::Unretained(this))));
326 328
327 UpdateCastModes(); 329 UpdateCastModes();
328 } 330 }
329 331
330 void MediaRouterUI::OnDefaultPresentationRemoved() { 332 void MediaRouterUI::OnDefaultPresentationRemoved() {
331 presentation_request_.reset(); 333 presentation_request_.reset();
332 query_result_manager_->StopSinksQuery(MediaCastMode::DEFAULT); 334 query_result_manager_->StopSinksQuery(MediaCastMode::DEFAULT);
333 // Register for MediaRoute updates without a media source. 335 // Register for MediaRoute updates without a media source.
334 routes_observer_.reset(new UIMediaRoutesObserver( 336 routes_observer_.reset(new UIMediaRoutesObserver(
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 bool* incognito) { 392 bool* incognito) {
391 DCHECK(query_result_manager_.get()); 393 DCHECK(query_result_manager_.get());
392 DCHECK(initiator_); 394 DCHECK(initiator_);
393 395
394 // Note that there is a rarely-encountered bug, where the MediaCastMode to 396 // Note that there is a rarely-encountered bug, where the MediaCastMode to
395 // MediaSource mapping could have been updated, between when the user clicked 397 // MediaSource mapping could have been updated, between when the user clicked
396 // on the UI to start a create route request, and when this function is 398 // on the UI to start a create route request, and when this function is
397 // called. However, since the user does not have visibility into the 399 // called. However, since the user does not have visibility into the
398 // MediaSource, and that it occurs very rarely in practice, we leave it as-is 400 // MediaSource, and that it occurs very rarely in practice, we leave it as-is
399 // for now. 401 // for now.
400 MediaSource source = query_result_manager_->GetSourceForCastMode(cast_mode); 402 MediaSource source =
403 query_result_manager_->GetSourceForCastModeAndSink(cast_mode, sink_id);
401 if (source.Empty()) { 404 if (source.Empty()) {
402 LOG(ERROR) << "No corresponding MediaSource for cast mode " 405 LOG(ERROR) << "No corresponding MediaSource for cast mode "
403 << static_cast<int>(cast_mode); 406 << static_cast<int>(cast_mode) << " and sink " << sink_id;
404 return false; 407 return false;
405 } 408 }
406 *source_id = source.id(); 409 *source_id = source.id();
407 410
408 bool for_default_source = cast_mode == MediaCastMode::DEFAULT; 411 bool for_default_source = cast_mode == MediaCastMode::DEFAULT;
409 if (for_default_source && !presentation_request_) { 412 if (for_default_source && !presentation_request_) {
410 DLOG(ERROR) << "Requested to create a route for presentation, but " 413 DLOG(ERROR) << "Requested to create a route for presentation, but "
411 << "presentation request is missing."; 414 << "presentation request is missing.";
412 return false; 415 return false;
413 } 416 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 487
485 void MediaRouterUI::ClearIssue(const std::string& issue_id) { 488 void MediaRouterUI::ClearIssue(const std::string& issue_id) {
486 router_->ClearIssue(issue_id); 489 router_->ClearIssue(issue_id);
487 } 490 }
488 491
489 void MediaRouterUI::SearchSinksAndCreateRoute( 492 void MediaRouterUI::SearchSinksAndCreateRoute(
490 const MediaSink::Id& sink_id, 493 const MediaSink::Id& sink_id,
491 const std::string& search_criteria, 494 const std::string& search_criteria,
492 const std::string& domain, 495 const std::string& domain,
493 MediaCastMode cast_mode) { 496 MediaCastMode cast_mode) {
494 auto source_id = query_result_manager_->GetSourceForCastMode(cast_mode).id(); 497 auto source_id = query_result_manager_->
498 GetSourceForCastModeAndSink(cast_mode, sink_id).id();
495 // The CreateRoute() part of the function is accomplished in the callback 499 // The CreateRoute() part of the function is accomplished in the callback
496 // OnSearchSinkResponseReceived(). 500 // OnSearchSinkResponseReceived().
497 router_->SearchSinks( 501 router_->SearchSinks(
498 sink_id, source_id, search_criteria, domain, 502 sink_id, source_id, search_criteria, domain,
499 base::Bind(&MediaRouterUI::OnSearchSinkResponseReceived, 503 base::Bind(&MediaRouterUI::OnSearchSinkResponseReceived,
500 weak_factory_.GetWeakPtr(), cast_mode)); 504 weak_factory_.GetWeakPtr(), cast_mode));
501 } 505 }
502 506
503 void MediaRouterUI::OnResultsUpdated( 507 void MediaRouterUI::OnResultsUpdated(
504 const std::vector<MediaSinkWithCastModes>& sinks) { 508 const std::vector<MediaSinkWithCastModes>& sinks) {
(...skipping 30 matching lines...) Expand all
535 } 539 }
536 540
537 void MediaRouterUI::OnRoutesUpdated( 541 void MediaRouterUI::OnRoutesUpdated(
538 const std::vector<MediaRoute>& routes, 542 const std::vector<MediaRoute>& routes,
539 const std::vector<MediaRoute::Id>& joinable_route_ids) { 543 const std::vector<MediaRoute::Id>& joinable_route_ids) {
540 routes_ = routes; 544 routes_ = routes;
541 joinable_route_ids_ = joinable_route_ids; 545 joinable_route_ids_ = joinable_route_ids;
542 546
543 std::unordered_map<MediaSource::Id, MediaCastMode> available_source_map; 547 std::unordered_map<MediaSource::Id, MediaCastMode> available_source_map;
544 for (const auto& cast_mode : cast_modes_) { 548 for (const auto& cast_mode : cast_modes_) {
545 available_source_map.insert(std::make_pair( 549 for (const auto& source :
546 query_result_manager_->GetSourceForCastMode(cast_mode).id(), 550 query_result_manager_->GetSourcesForCastMode(cast_mode)) {
547 cast_mode)); 551 available_source_map.insert(std::make_pair(source.id(), cast_mode));
552 }
548 } 553 }
549 554
550 current_cast_modes_.clear(); 555 current_cast_modes_.clear();
551 for (const auto& route : routes) { 556 for (const auto& route : routes) {
552 auto source_entry = available_source_map.find(route.media_source().id()); 557 auto source_entry = available_source_map.find(route.media_source().id());
553 if (source_entry != available_source_map.end()) { 558 if (source_entry != available_source_map.end()) {
554 current_cast_modes_.insert( 559 current_cast_modes_.insert(
555 std::make_pair(route.media_route_id(), source_entry->second)); 560 std::make_pair(route.media_route_id(), source_entry->second));
556 } 561 }
557 } 562 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 base::Time::Now() - start_time_); 703 base::Time::Now() - start_time_);
699 start_time_ = base::Time(); 704 start_time_ = base::Time();
700 } 705 }
701 } 706 }
702 707
703 void MediaRouterUI::UpdateMaxDialogHeight(int height) { 708 void MediaRouterUI::UpdateMaxDialogHeight(int height) {
704 handler_->UpdateMaxDialogHeight(height); 709 handler_->UpdateMaxDialogHeight(height);
705 } 710 }
706 711
707 } // namespace media_router 712 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698