Index: chrome/browser/media/router/media_router_mojo_impl.cc |
diff --git a/chrome/browser/media/router/media_router_mojo_impl.cc b/chrome/browser/media/router/media_router_mojo_impl.cc |
index ace0a47cf560a2b629b2ea17e02d3435bb4dadb0..24cc6a3dbff4e60cc7dcc79cad0b1396ab6a3a34 100644 |
--- a/chrome/browser/media/router/media_router_mojo_impl.cc |
+++ b/chrome/browser/media/router/media_router_mojo_impl.cc |
@@ -25,26 +25,6 @@ |
namespace media_router { |
namespace { |
-// Converts the callback result of calling Mojo CreateRoute()/JoinRoute() |
-// into a local callback. |
-void RouteResponseReceived( |
- const std::vector<MediaRouteResponseCallback>& callbacks, |
- interfaces::MediaRoutePtr media_route, |
- const mojo::String& error_text) { |
- scoped_ptr<MediaRoute> route; |
- std::string error; |
- if (media_route.is_null()) { |
- // An error occurred. |
- DCHECK(!error_text.is_null()); |
- error = !error_text.get().empty() ? error_text.get() : "Unknown error."; |
- } else { |
- route = media_route.To<scoped_ptr<MediaRoute>>(); |
- } |
- |
- for (const MediaRouteResponseCallback& callback : callbacks) |
- callback.Run(route.get(), error); |
-} |
- |
// TODO(imcheng): We should handle failure in this case. One way is to invoke |
// all pending requests with failure. (crbug.com/490787) |
void EventPageWakeComplete(bool success) { |
@@ -204,6 +184,9 @@ void MediaRouterMojoImpl::CreateRoute( |
callback.Run(nullptr, "Invalid origin"); |
return; |
} |
+ |
+ sink_ids_in_launch_.insert(sink_id); |
+ |
RunOrDefer(base::Bind( |
&MediaRouterMojoImpl::DoCreateRoute, base::Unretained(this), source_id, |
sink_id, origin.is_empty() ? "" : origin.spec(), tab_id, callbacks)); |
@@ -362,7 +345,8 @@ void MediaRouterMojoImpl::DoCreateRoute( |
<< ", presentation ID: " << presentation_id; |
media_route_provider_->CreateRoute( |
source_id, sink_id, presentation_id, origin, tab_id, |
- base::Bind(&RouteResponseReceived, callbacks)); |
+ base::Bind(&MediaRouterMojoImpl::RouteResponseReceived, |
+ base::Unretained(this), callbacks, sink_id)); |
} |
void MediaRouterMojoImpl::DoJoinRoute( |
@@ -375,7 +359,8 @@ void MediaRouterMojoImpl::DoJoinRoute( |
<< ", presentation ID: " << presentation_id; |
media_route_provider_->JoinRoute( |
source_id, presentation_id, origin, tab_id, |
- base::Bind(&RouteResponseReceived, callbacks)); |
+ base::Bind(&MediaRouterMojoImpl::RouteResponseReceived, |
+ base::Unretained(this), callbacks, "")); |
} |
void MediaRouterMojoImpl::DoCloseRoute(const MediaRoute::Id& route_id) { |
@@ -501,4 +486,26 @@ void MediaRouterMojoImpl::ExecutePendingRequests() { |
pending_requests_.clear(); |
} |
+// Converts the callback result of calling Mojo CreateRoute()/JoinRoute() |
+// into a local callback. |
+void MediaRouterMojoImpl::RouteResponseReceived( |
+ const std::vector<MediaRouteResponseCallback>& callbacks, |
+ const MediaSink::Id& sink_id, |
+ interfaces::MediaRoutePtr media_route, |
+ const mojo::String& error_text) { |
+ sink_ids_in_launch_.erase(sink_id); |
+ scoped_ptr<MediaRoute> route; |
+ std::string error; |
+ if (media_route.is_null()) { |
+ // An error occurred. |
+ DCHECK(!error_text.is_null()); |
+ error = !error_text.get().empty() ? error_text.get() : "Unknown error."; |
+ } else { |
+ route = media_route.To<scoped_ptr<MediaRoute>>(); |
+ } |
+ |
+ for (const MediaRouteResponseCallback& callback : callbacks) |
+ callback.Run(route.get(), error); |
+} |
+ |
} // namespace media_router |