Chromium Code Reviews| 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 #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 Loading... | |
| 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 = std::find_if(sources.begin(), sources.end(), | |
| 96 [](const MediaSource& source) { | |
|
mark a. foltz
2016/12/02 20:59:09
Is the lambda function necessary, or can you pass
zhaobin
2016/12/02 22:50:57
Done.
| |
| 97 return CanConnectToMediaSource(source); | |
| 98 }); | |
| 99 return source_it != sources.end() ? *source_it : MediaSource(""); | |
| 100 } | |
| 101 | |
| 91 } // namespace | 102 } // namespace |
| 92 | 103 |
| 93 // static | 104 // static |
| 94 std::string MediaRouterUI::GetExtensionName( | 105 std::string MediaRouterUI::GetExtensionName( |
| 95 const GURL& gurl, extensions::ExtensionRegistry* registry) { | 106 const GURL& gurl, extensions::ExtensionRegistry* registry) { |
| 96 if (gurl.is_empty() || !registry) return std::string(); | 107 if (gurl.is_empty() || !registry) return std::string(); |
| 97 | 108 |
| 98 const extensions::Extension* extension = | 109 const extensions::Extension* extension = |
| 99 registry->enabled_extensions().GetExtensionOrAppByURL(gurl); | 110 registry->enabled_extensions().GetExtensionOrAppByURL(gurl); |
| 100 | 111 |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 } | 327 } |
| 317 } | 328 } |
| 318 | 329 |
| 319 void MediaRouterUI::OnDefaultPresentationChanged( | 330 void MediaRouterUI::OnDefaultPresentationChanged( |
| 320 const PresentationRequest& presentation_request) { | 331 const PresentationRequest& presentation_request) { |
| 321 std::vector<MediaSource> sources = presentation_request.GetMediaSources(); | 332 std::vector<MediaSource> sources = presentation_request.GetMediaSources(); |
| 322 presentation_request_.reset(new PresentationRequest(presentation_request)); | 333 presentation_request_.reset(new PresentationRequest(presentation_request)); |
| 323 query_result_manager_->SetSourcesForCastMode( | 334 query_result_manager_->SetSourcesForCastMode( |
| 324 MediaCastMode::DEFAULT, sources, | 335 MediaCastMode::DEFAULT, sources, |
| 325 presentation_request_->frame_url().GetOrigin()); | 336 presentation_request_->frame_url().GetOrigin()); |
| 326 // Register for MediaRoute updates. | 337 // Register for MediaRoute updates. NOTE(mfoltz): If there are multiple |
| 327 // TODO(crbug.com/627655): Use multiple URLs. | 338 // sources that can be connected to via the dialog, this will break. We will |
| 339 // need to observe multiple sources (keyed by sinks) in that case. As this is | |
| 340 // Cast-specific for the forseeable future, it may be simpler to plumb a new | |
| 341 // observer API for this case. | |
| 342 const MediaSource source_for_route_observer = | |
| 343 GetSourceForRouteObserver(sources); | |
| 328 routes_observer_.reset(new UIMediaRoutesObserver( | 344 routes_observer_.reset(new UIMediaRoutesObserver( |
| 329 router_, sources[0].id(), | 345 router_, source_for_route_observer.id(), |
| 330 base::Bind(&MediaRouterUI::OnRoutesUpdated, base::Unretained(this)))); | 346 base::Bind(&MediaRouterUI::OnRoutesUpdated, base::Unretained(this)))); |
| 331 | 347 |
| 332 UpdateCastModes(); | 348 UpdateCastModes(); |
| 333 } | 349 } |
| 334 | 350 |
| 335 void MediaRouterUI::OnDefaultPresentationRemoved() { | 351 void MediaRouterUI::OnDefaultPresentationRemoved() { |
| 336 presentation_request_.reset(); | 352 presentation_request_.reset(); |
| 337 query_result_manager_->RemoveSourcesForCastMode(MediaCastMode::DEFAULT); | 353 query_result_manager_->RemoveSourcesForCastMode(MediaCastMode::DEFAULT); |
| 338 // Register for MediaRoute updates without a media source. | 354 // Register for MediaRoute updates without a media source. |
| 339 routes_observer_.reset(new UIMediaRoutesObserver( | 355 routes_observer_.reset(new UIMediaRoutesObserver( |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 690 base::Time::Now() - start_time_); | 706 base::Time::Now() - start_time_); |
| 691 start_time_ = base::Time(); | 707 start_time_ = base::Time(); |
| 692 } | 708 } |
| 693 } | 709 } |
| 694 | 710 |
| 695 void MediaRouterUI::UpdateMaxDialogHeight(int height) { | 711 void MediaRouterUI::UpdateMaxDialogHeight(int height) { |
| 696 handler_->UpdateMaxDialogHeight(height); | 712 handler_->UpdateMaxDialogHeight(height); |
| 697 } | 713 } |
| 698 | 714 |
| 699 } // namespace media_router | 715 } // namespace media_router |
| OLD | NEW |