Chromium Code Reviews| Index: chrome/browser/ui/webui/media_router/media_router_webui_message_handler.cc |
| diff --git a/chrome/browser/ui/webui/media_router/media_router_webui_message_handler.cc b/chrome/browser/ui/webui/media_router/media_router_webui_message_handler.cc |
| index c349ddbab20bd9d36ef8f69c20c6b386143c307c..b91cfbe9201cbec4fddd6f7697564f40ca0340c6 100644 |
| --- a/chrome/browser/ui/webui/media_router/media_router_webui_message_handler.cc |
| +++ b/chrome/browser/ui/webui/media_router/media_router_webui_message_handler.cc |
| @@ -141,13 +141,17 @@ std::unique_ptr<base::DictionaryValue> RouteToValue( |
| const MediaRoute& route, |
| bool can_join, |
| const std::string& extension_id, |
| - bool off_the_record) { |
| + bool off_the_record, |
| + int current_cast_mode) { |
| std::unique_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); |
| dictionary->SetString("id", route.media_route_id()); |
| dictionary->SetString("sinkId", route.media_sink_id()); |
| dictionary->SetString("description", route.description()); |
| dictionary->SetBoolean("isLocal", route.is_local()); |
| dictionary->SetBoolean("canJoin", can_join); |
| + if (current_cast_mode > 0) { |
| + dictionary->SetInteger("currentCastMode", current_cast_mode); |
| + } |
| const std::string& custom_path = route.custom_controller_path(); |
| if (!off_the_record && !custom_path.empty()) { |
| @@ -247,9 +251,11 @@ void MediaRouterWebUIMessageHandler::UpdateSinks( |
| void MediaRouterWebUIMessageHandler::UpdateRoutes( |
| const std::vector<MediaRoute>& routes, |
| - const std::vector<MediaRoute::Id>& joinable_route_ids) { |
| + const std::vector<MediaRoute::Id>& joinable_route_ids, |
| + const std::unordered_map<MediaRoute::Id, MediaCastMode>& |
| + current_cast_modes) { |
| std::unique_ptr<base::ListValue> routes_val( |
| - RoutesToValue(routes, joinable_route_ids)); |
| + RoutesToValue(routes, joinable_route_ids, current_cast_modes)); |
| web_ui()->CallJavascriptFunction(kSetRouteList, *routes_val); |
| } |
| @@ -267,9 +273,15 @@ void MediaRouterWebUIMessageHandler::OnCreateRouteResponseReceived( |
| const MediaRoute* route) { |
| DVLOG(2) << "OnCreateRouteResponseReceived"; |
| if (route) { |
| + const auto& current_cast_modes = media_router_ui_->current_cast_modes(); |
| + auto current_cast_mode_entry = |
| + current_cast_modes.find(route->media_route_id()); |
| + int current_cast_mode = current_cast_mode_entry != end(current_cast_modes) |
|
imcheng
2016/06/06 20:48:19
nit: current_cast_modes.end()
btolsch
2016/06/06 23:46:53
Removed.
|
| + ? current_cast_mode_entry->second |
| + : -1; |
| std::unique_ptr<base::DictionaryValue> route_value(RouteToValue( |
| *route, false, media_router_ui_->GetRouteProviderExtensionId(), |
| - off_the_record_)); |
| + off_the_record_, current_cast_mode)); |
|
imcheng
2016/06/06 20:48:19
Is the current_cast_mode value on the route respon
btolsch
2016/06/06 23:46:53
It's not used on the route response. I'll use -1
|
| web_ui()->CallJavascriptFunction( |
| kOnCreateRouteResponseReceived, |
| base::StringValue(sink_id), *route_value, |
| @@ -404,7 +416,8 @@ void MediaRouterWebUIMessageHandler::OnRequestInitialData( |
| initial_data.Set("sinksAndIdentity", sinks_and_identity.release()); |
| std::unique_ptr<base::ListValue> routes(RoutesToValue( |
| - media_router_ui_->routes(), media_router_ui_->joinable_route_ids())); |
| + media_router_ui_->routes(), media_router_ui_->joinable_route_ids(), |
| + media_router_ui_->current_cast_modes())); |
| initial_data.Set("routes", routes.release()); |
| const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes(); |
| @@ -852,15 +865,22 @@ AccountInfo MediaRouterWebUIMessageHandler::GetAccountInfo() { |
| std::unique_ptr<base::ListValue> MediaRouterWebUIMessageHandler::RoutesToValue( |
| const std::vector<MediaRoute>& routes, |
| - const std::vector<MediaRoute::Id>& joinable_route_ids) const { |
| + const std::vector<MediaRoute::Id>& joinable_route_ids, |
| + const std::unordered_map<MediaRoute::Id, MediaCastMode>& current_cast_modes) |
| + const { |
| std::unique_ptr<base::ListValue> value(new base::ListValue); |
| const std::string& extension_id = |
| media_router_ui_->GetRouteProviderExtensionId(); |
| for (const MediaRoute& route : routes) { |
| bool can_join = ContainsValue(joinable_route_ids, route.media_route_id()); |
| - std::unique_ptr<base::DictionaryValue> route_val( |
| - RouteToValue(route, can_join, extension_id, off_the_record_)); |
| + auto current_cast_mode_entry = |
|
apacible
2016/06/06 20:17:10
Pull out lines 877-881 (and 277-281) into a helper
btolsch
2016/06/06 23:46:53
Done. Only this instance remains in use but still
|
| + current_cast_modes.find(route.media_route_id()); |
| + int current_cast_mode = current_cast_mode_entry != end(current_cast_modes) |
| + ? current_cast_mode_entry->second |
| + : -1; |
| + std::unique_ptr<base::DictionaryValue> route_val(RouteToValue( |
| + route, can_join, extension_id, off_the_record_, current_cast_mode)); |
| value->Append(route_val.release()); |
| } |