Index: chrome/browser/media/router/mojo/media_router_mojo_impl.cc |
diff --git a/chrome/browser/media/router/mojo/media_router_mojo_impl.cc b/chrome/browser/media/router/mojo/media_router_mojo_impl.cc |
index 20d2f2748398fbd4a44a3a24e9e1bbff75186b8e..d192c333a9b34755f75d731b34f54634979488ce 100644 |
--- a/chrome/browser/media/router/mojo/media_router_mojo_impl.cc |
+++ b/chrome/browser/media/router/mojo/media_router_mojo_impl.cc |
@@ -234,6 +234,20 @@ void MediaRouterMojoImpl::OnSinksReceived( |
} |
} |
+void MediaRouterMojoImpl::OnSearchSinkIdReceived( |
+ const mojo::String& pseudo_sink_id, |
+ const mojo::String& sink_id) { |
+ auto sink_id_callback_entry = search_callbacks_.find(pseudo_sink_id); |
+ if (sink_id_callback_entry == search_callbacks_.end()) { |
amp
2016/04/06 21:29:36
Is this scenario expected? Is it possible to get
btolsch
2016/04/08 09:31:24
This isn't expected, it is just a generic guard. I
|
+ DVLOG_WITH_INSTANCE(1) |
+ << "Received sink id for a search that is not in progress: " |
+ << pseudo_sink_id; |
+ return; |
+ } |
+ sink_id_callback_entry->second.Run(sink_id); |
+ search_callbacks_.erase(sink_id_callback_entry); |
+} |
+ |
void MediaRouterMojoImpl::OnRoutesUpdated( |
mojo::Array<interfaces::MediaRoutePtr> routes, |
const mojo::String& media_source, |
@@ -296,6 +310,31 @@ void MediaRouterMojoImpl::RouteResponseReceived( |
callback.Run(*result); |
} |
+void MediaRouterMojoImpl::SearchAndCreateResponseReceived( |
+ const std::string& presentation_id, |
+ const std::vector<MediaRouteResponseCallback>& route_callbacks, |
+ interfaces::MediaRoutePtr media_route, |
+ const mojo::String& error_text, |
+ interfaces::RouteRequestResultCode result_code) { |
+ scoped_ptr<RouteRequestResult> result; |
+ if (media_route.is_null()) { |
+ // An error occurred. |
+ DCHECK(!error_text.is_null()); |
+ std::string error = |
+ !error_text.get().empty() ? error_text.get() : "Unknown error."; |
+ |
+ result = RouteRequestResult::FromError( |
amp
2016/04/06 21:29:36
Does this result in an issue being shown in the UI
btolsch
2016/04/08 09:31:24
This shows an issue in the UI like other route cre
|
+ error, mojo::RouteRequestResultCodeFromMojo(result_code)); |
+ } else { |
+ result = RouteRequestResult::FromSuccess( |
+ media_route.To<scoped_ptr<MediaRoute>>(), presentation_id); |
+ } |
+ |
+ for (const auto& route_callback : route_callbacks) { |
+ route_callback.Run(*result); |
+ } |
+} |
+ |
void MediaRouterMojoImpl::CreateRoute( |
const MediaSource::Id& source_id, |
const MediaSink::Id& sink_id, |
@@ -432,6 +471,28 @@ void MediaRouterMojoImpl::OnUserGesture() { |
#endif |
} |
+void MediaRouterMojoImpl::SearchSinksAndCreateRoute( |
+ const MediaSink::Id& sink_id, |
+ const MediaSource::Id& source_id, |
+ const std::string& search_input, |
+ const std::string& domain, |
+ const GURL& origin, |
+ content::WebContents* web_contents, |
+ const std::vector<MediaRouteResponseCallback>& route_callbacks, |
+ const MediaSinkSearchResponseCallback& sink_callback, |
+ base::TimeDelta timeout, |
+ bool off_the_record) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ |
+ int tab_id = SessionTabHelper::IdForTab(web_contents); |
+ SetWakeReason(MediaRouteProviderWakeReason::SEARCH_SINKS); |
+ RunOrDefer( |
+ base::Bind(&MediaRouterMojoImpl::DoSearchSinksAndCreateRoute, |
+ base::Unretained(this), sink_id, source_id, search_input, |
+ domain, origin.is_empty() ? "" : origin.spec(), tab_id, |
+ route_callbacks, sink_callback, timeout, off_the_record)); |
+} |
+ |
bool MediaRouterMojoImpl::RegisterMediaSinksObserver( |
MediaSinksObserver* observer) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
@@ -702,6 +763,42 @@ void MediaRouterMojoImpl::DoStopListeningForRouteMessages( |
media_route_provider_->StopListeningForRouteMessages(route_id); |
} |
+void MediaRouterMojoImpl::DoSearchSinksAndCreateRoute( |
+ const MediaSink::Id& sink_id, |
+ const MediaSource::Id& source_id, |
+ const std::string& search_input, |
+ const std::string& domain, |
+ const std::string& origin, |
+ int tab_id, |
+ const std::vector<MediaRouteResponseCallback>& route_callbacks, |
+ const MediaSinkSearchResponseCallback& sink_callback, |
+ base::TimeDelta timeout, |
+ bool off_the_record) { |
+ auto sink_callback_entry = search_callbacks_.find(sink_id); |
+ if (sink_callback_entry != search_callbacks_.end()) { |
+ LOG(WARNING) << "SearchSinksAndCreateRoute for pseudo sink " << sink_id |
+ << " already has a registered callback."; |
+ } else { |
+ bool insert_wil_succeed; |
amp
2016/04/06 21:29:36
s/wil/will/
Unless this is some kind of style/nam
btolsch
2016/04/08 09:31:24
Done.
|
+ std::tie(sink_callback_entry, insert_wil_succeed) = |
+ search_callbacks_.insert(std::make_pair(sink_id, sink_callback)); |
+ } |
+ |
+ std::string presentation_id("mr_"); |
+ presentation_id += base::GenerateGUID(); |
+ DVLOG_WITH_INSTANCE(1) << "SearchSinksAndCreateRoute"; |
+ auto sink_search_criteria = interfaces::SinkSearchCriteria::New(); |
+ sink_search_criteria->input = search_input; |
+ sink_search_criteria->domain = domain; |
+ media_route_provider_->SearchSinksAndCreateRoute( |
+ sink_id, source_id, std::move(sink_search_criteria), presentation_id, |
+ origin, tab_id, |
+ timeout > base::TimeDelta() ? timeout.InMilliseconds() : 0, |
+ off_the_record, |
+ base::Bind(&MediaRouterMojoImpl::SearchAndCreateResponseReceived, |
+ weak_factory_.GetWeakPtr(), presentation_id, route_callbacks)); |
+} |
+ |
void MediaRouterMojoImpl::OnRouteMessagesReceived( |
const MediaRoute::Id& route_id, |
mojo::Array<interfaces::RouteMessagePtr> messages, |