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 193954cccff4583173a8804b348efe1d5018d476..9492f77bbbb3aa29597d7c02362990e58f30481b 100644 |
| --- a/chrome/browser/ui/webui/media_router/media_router_ui.cc |
| +++ b/chrome/browser/ui/webui/media_router/media_router_ui.cc |
| @@ -103,16 +103,25 @@ class MediaRouterUI::UIIssuesObserver : public IssuesObserver { |
| }; |
| MediaRouterUI::UIMediaRoutesObserver::UIMediaRoutesObserver( |
| - MediaRouter* router, const RoutesUpdatedCallback& callback) |
| - : MediaRoutesObserver(router), callback_(callback) { |
| + MediaRouter* router, |
| + const RoutesUpdatedCallback& callback) : |
| + UIMediaRoutesObserver(router, MediaSource::Id(), callback) { |
| +} |
| + |
| +MediaRouterUI::UIMediaRoutesObserver::UIMediaRoutesObserver( |
| + MediaRouter* router, const MediaSource::Id& source_id, |
| + const RoutesUpdatedCallback& callback) |
| + : MediaRoutesObserver(router, source_id), callback_(callback) { |
| DCHECK(!callback_.is_null()); |
| } |
| MediaRouterUI::UIMediaRoutesObserver::~UIMediaRoutesObserver() {} |
| void MediaRouterUI::UIMediaRoutesObserver::OnRoutesUpdated( |
| - const std::vector<MediaRoute>& routes) { |
| + 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 |
| @@ -125,11 +134,15 @@ void MediaRouterUI::UIMediaRoutesObserver::OnRoutesUpdated( |
| } |
| } |
| #endif |
| + if (ContainsValue(joinable_route_ids, route.media_route_id())) { |
|
imcheng
2015/12/17 02:30:57
Do we need to hide the join button if the route wa
matt.boetger
2015/12/18 23:37:15
Perhaps. Right now that is an implementation deta
|
| + joinable_route_ids_for_display.push_back(route.media_route_id()); |
|
mark a. foltz
2015/12/16 07:17:35
Since the only way to connect to a remote route is
matt.boetger
2015/12/18 23:37:15
No, the MRP should not, but how are we going to en
imcheng
2015/12/29 00:24:42
BTW Vadim and I talked about removing forDisplay f
matt.boetger
2016/01/05 00:19:47
Acknowledged.
|
| + } |
| + |
| routes_for_display.push_back(route); |
| } |
| } |
| - callback_.Run(routes_for_display); |
| + callback_.Run(routes_for_display, joinable_route_ids_for_display); |
| } |
| MediaRouterUI::MediaRouterUI(content::WebUI* web_ui) |
| @@ -220,11 +233,6 @@ void MediaRouterUI::InitCommon(content::WebContents* initiator) { |
| TRACE_EVENT_NESTABLE_ASYNC_INSTANT1("media_router", "UI", initiator, |
| "MediaRouterUI::InitCommon", this); |
| - // Register for MediaRoute updates. |
|
mark a. foltz
2015/12/16 07:17:35
How does the dialog get route updates when there i
matt.boetger
2015/12/18 23:37:15
Done.
|
| - routes_observer_.reset(new UIMediaRoutesObserver( |
| - router_, |
| - base::Bind(&MediaRouterUI::OnRoutesUpdated, base::Unretained(this)))); |
| - |
| // Create |collator_| before |query_result_manager_| so that |collator_| is |
| // already set up when we get a callback from |query_result_manager_|. |
| UErrorCode error = U_ZERO_ERROR; |
| @@ -252,15 +260,21 @@ void MediaRouterUI::InitCommon(content::WebContents* initiator) { |
| void MediaRouterUI::OnDefaultPresentationChanged( |
| const PresentationRequest& presentation_request) { |
| + MediaSource source = presentation_request.GetMediaSource(); |
| presentation_request_.reset(new PresentationRequest(presentation_request)); |
| - query_result_manager_->StartSinksQuery( |
| - MediaCastMode::DEFAULT, presentation_request_->GetMediaSource()); |
| + query_result_manager_->StartSinksQuery(MediaCastMode::DEFAULT, source); |
| + // Register for MediaRoute updates. |
| + routes_observer_.reset(new UIMediaRoutesObserver( |
| + router_, source.id(), |
| + base::Bind(&MediaRouterUI::OnRoutesUpdated, base::Unretained(this)))); |
| + |
| UpdateCastModes(); |
| } |
| void MediaRouterUI::OnDefaultPresentationRemoved() { |
| presentation_request_.reset(); |
| query_result_manager_->StopSinksQuery(MediaCastMode::DEFAULT); |
| + routes_observer_.reset(); |
|
mark a. foltz
2015/12/16 07:17:35
Don't you need to instantiate a routes observer wi
matt.boetger
2015/12/18 23:37:15
Done.
|
| UpdateCastModes(); |
| } |
| @@ -292,6 +306,12 @@ void MediaRouterUI::UIInitialized() { |
| bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id, |
| MediaCastMode cast_mode) { |
| + return CreateRouteOrConnectRoute(sink_id, cast_mode, MediaRoute::Id()); |
| +} |
| + |
| +bool MediaRouterUI::CreateRouteOrConnectRoute(const MediaSink::Id& sink_id, |
| + MediaCastMode cast_mode, |
| + const MediaRoute::Id& route_id) { |
| DCHECK(query_result_manager_.get()); |
| DCHECK(initiator_); |
| @@ -361,11 +381,21 @@ bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id, |
| FROM_HERE, base::TimeDelta::FromSeconds(kCreateRouteTimeoutSeconds), this, |
| &MediaRouterUI::RouteCreationTimeout); |
| - router_->CreateRoute(source.id(), sink_id, origin, initiator_, |
| - route_response_callbacks); |
| + if (route_id.empty()) { |
| + router_->CreateRoute(source.id(), sink_id, origin, initiator_, |
| + route_response_callbacks); |
|
apacible
2015/12/18 22:34:19
nit: fix indentation here and L389.
matt.boetger
2015/12/18 23:37:15
Fixed on L389. Not sure what the problem is here
|
| + } else { |
| + router_->ConnectRouteByRouteId(source.id(), route_id, origin, |
| + initiator_, route_response_callbacks); |
| + } |
| return true; |
| } |
| +bool MediaRouterUI::ConnectRemoteRoute(const MediaSink::Id& sink_id, |
| + const MediaRoute::Id& route_id) { |
|
apacible
2015/12/18 22:34:19
nit: fix indentation.
matt.boetger
2015/12/18 23:37:15
Done.
|
| + return CreateRouteOrConnectRoute(sink_id, MediaCastMode::DEFAULT, route_id); |
| +} |
| + |
| void MediaRouterUI::CloseRoute(const MediaRoute::Id& route_id) { |
| router_->CloseRoute(route_id); |
| } |
| @@ -410,9 +440,12 @@ void MediaRouterUI::SetIssue(const Issue* issue) { |
| if (ui_initialized_) handler_->UpdateIssue(issue); |
| } |
| -void MediaRouterUI::OnRoutesUpdated(const std::vector<MediaRoute>& routes) { |
| +void MediaRouterUI::OnRoutesUpdated( |
| + const std::vector<MediaRoute>& routes, |
| + const std::vector<MediaRoute::Id>& joinable_route_ids) { |
| routes_ = routes; |
| - if (ui_initialized_) handler_->UpdateRoutes(routes_); |
| + joinable_route_ids_ = joinable_route_ids; |
| + if (ui_initialized_) handler_->UpdateRoutes(routes_, joinable_route_ids_); |
| } |
| void MediaRouterUI::OnRouteResponseReceived(const int route_request_id, |