Chromium Code Reviews| Index: chrome/browser/ui/webui/media_router/media_router_ui.cc |
| diff --git a/chrome/browser/ui/webui/media_router/media_router_ui.cc b/chrome/browser/ui/webui/media_router/media_router_ui.cc |
| index 5689862f1704e120d14da803f8e211346740c02d..737608e6dce598b6af8c81a603e4329f4521d588 100644 |
| --- a/chrome/browser/ui/webui/media_router/media_router_ui.cc |
| +++ b/chrome/browser/ui/webui/media_router/media_router_ui.cc |
| @@ -139,29 +139,7 @@ MediaRouterUI::UIMediaRoutesObserver::~UIMediaRoutesObserver() {} |
| void MediaRouterUI::UIMediaRoutesObserver::OnRoutesUpdated( |
| const std::vector<MediaRoute>& routes, |
| const std::vector<MediaRoute::Id>& joinable_route_ids) { |
| - std::vector<MediaRoute> routes_for_display; |
| - std::vector<MediaRoute::Id> joinable_route_ids_for_display; |
| - for (const MediaRoute& route : routes) { |
| - if (route.for_display()) { |
| -#ifndef NDEBUG |
| - for (const MediaRoute& existing_route : routes_for_display) { |
| - if (existing_route.media_sink_id() == route.media_sink_id()) { |
| - DVLOG(2) << "Received another route for display with the same sink" |
| - << " id as an existing route. " << route.media_route_id() |
| - << " has the same sink id as " |
| - << existing_route.media_sink_id() << "."; |
| - } |
| - } |
| -#endif |
| - if (base::ContainsValue(joinable_route_ids, route.media_route_id())) { |
| - joinable_route_ids_for_display.push_back(route.media_route_id()); |
| - } |
| - |
| - routes_for_display.push_back(route); |
| - } |
| - } |
| - |
| - callback_.Run(routes_for_display, joinable_route_ids_for_display); |
| + callback_.Run(routes, joinable_route_ids); |
| } |
| MediaRouterUI::MediaRouterUI(content::WebUI* web_ui) |
| @@ -301,7 +279,12 @@ void MediaRouterUI::InitCommon(content::WebContents* initiator) { |
| query_result_manager_->SetSourcesForCastMode(MediaCastMode::TAB_MIRROR, |
| {mirroring_source}, origin); |
| } |
| + |
| UpdateCastModes(); |
| + |
| + // Get the current list of media routes, so that the WebUI will have routes |
| + // information at initialization. |
| + OnRoutesUpdated(router_->GetCurrentRoutes(), std::vector<MediaRoute::Id>()); |
| } |
| void MediaRouterUI::InitForTest( |
| @@ -354,6 +337,25 @@ void MediaRouterUI::UpdateCastModes() { |
| } |
| } |
| +void MediaRouterUI::UpdateRoutesToCastModesMapping() { |
| + std::unordered_map<MediaSource::Id, MediaCastMode> available_source_map; |
| + for (const auto& cast_mode : cast_modes_) { |
| + for (const auto& source : |
| + query_result_manager_->GetSourcesForCastMode(cast_mode)) { |
| + available_source_map.insert(std::make_pair(source.id(), cast_mode)); |
| + } |
| + } |
| + |
| + routes_and_cast_modes_.clear(); |
| + for (const auto& route : routes_) { |
| + auto source_entry = available_source_map.find(route.media_source().id()); |
| + if (source_entry != available_source_map.end()) { |
| + routes_and_cast_modes_.insert( |
|
mark a. foltz
2016/12/02 23:29:44
I see this is existing code refactored, I just don
takumif
2016/12/03 00:11:25
It's for hiding the "Cast" button in dialog if cli
|
| + std::make_pair(route.media_route_id(), source_entry->second)); |
| + } |
| + } |
| +} |
| + |
| void MediaRouterUI::Close() { |
| ConstrainedWebDialogDelegate* delegate = GetConstrainedDelegate(); |
| if (delegate) { |
| @@ -563,28 +565,33 @@ void MediaRouterUI::SetIssue(const Issue* issue) { |
| void MediaRouterUI::OnRoutesUpdated( |
| const std::vector<MediaRoute>& routes, |
| const std::vector<MediaRoute::Id>& joinable_route_ids) { |
| - routes_ = routes; |
| - joinable_route_ids_ = joinable_route_ids; |
| + routes_.clear(); |
| + joinable_route_ids_.clear(); |
| - std::unordered_map<MediaSource::Id, MediaCastMode> available_source_map; |
| - for (const auto& cast_mode : cast_modes_) { |
| - for (const auto& source : |
| - query_result_manager_->GetSourcesForCastMode(cast_mode)) { |
| - available_source_map.insert(std::make_pair(source.id(), cast_mode)); |
| - } |
| - } |
| + for (const MediaRoute& route : routes) { |
| + if (route.for_display()) { |
| +#ifndef NDEBUG |
| + for (const MediaRoute& existing_route : routes_) { |
| + if (existing_route.media_sink_id() == route.media_sink_id()) { |
| + DVLOG(2) << "Received another route for display with the same sink" |
| + << " id as an existing route. " << route.media_route_id() |
| + << " has the same sink id as " |
| + << existing_route.media_sink_id() << "."; |
| + } |
| + } |
| +#endif |
| + if (base::ContainsValue(joinable_route_ids, route.media_route_id())) { |
| + joinable_route_ids_.push_back(route.media_route_id()); |
| + } |
| - current_cast_modes_.clear(); |
| - for (const auto& route : routes) { |
| - auto source_entry = available_source_map.find(route.media_source().id()); |
| - if (source_entry != available_source_map.end()) { |
| - current_cast_modes_.insert( |
| - std::make_pair(route.media_route_id(), source_entry->second)); |
| + routes_.push_back(route); |
| } |
| } |
| + UpdateRoutesToCastModesMapping(); |
| if (ui_initialized_) |
| - handler_->UpdateRoutes(routes_, joinable_route_ids_, current_cast_modes_); |
| + handler_->UpdateRoutes(routes_, joinable_route_ids_, |
| + routes_and_cast_modes_); |
| } |
| void MediaRouterUI::OnRouteResponseReceived( |