Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/media/router/mojo/media_router_mojo_impl.h" | 5 #include "chrome/browser/media/router/mojo/media_router_mojo_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 if (!sinks_query->observers.might_have_observers()) { | 227 if (!sinks_query->observers.might_have_observers()) { |
| 228 DVLOG_WITH_INSTANCE(1) | 228 DVLOG_WITH_INSTANCE(1) |
| 229 << "Received sink list without any active observers: " << media_source; | 229 << "Received sink list without any active observers: " << media_source; |
| 230 } else { | 230 } else { |
| 231 FOR_EACH_OBSERVER( | 231 FOR_EACH_OBSERVER( |
| 232 MediaSinksObserver, sinks_query->observers, | 232 MediaSinksObserver, sinks_query->observers, |
| 233 OnSinksUpdated(sinks_query->cached_sink_list, sinks_query->origins)); | 233 OnSinksUpdated(sinks_query->cached_sink_list, sinks_query->origins)); |
| 234 } | 234 } |
| 235 } | 235 } |
| 236 | 236 |
| 237 void MediaRouterMojoImpl::OnSearchSinkIdReceived( | |
| 238 const mojo::String& pseudo_sink_id, | |
| 239 const mojo::String& sink_id) { | |
| 240 auto sink_id_callback_entry = search_callbacks_.find(pseudo_sink_id); | |
| 241 if (sink_id_callback_entry == search_callbacks_.end()) { | |
| 242 DVLOG_WITH_INSTANCE(1) | |
| 243 << "Received sink id for a search that is not in progress: " | |
| 244 << pseudo_sink_id; | |
| 245 return; | |
| 246 } | |
| 247 sink_id_callback_entry->second.Run(sink_id); | |
| 248 search_callbacks_.erase(sink_id_callback_entry); | |
| 249 } | |
| 250 | |
| 237 void MediaRouterMojoImpl::OnRoutesUpdated( | 251 void MediaRouterMojoImpl::OnRoutesUpdated( |
| 238 mojo::Array<interfaces::MediaRoutePtr> routes, | 252 mojo::Array<interfaces::MediaRoutePtr> routes, |
| 239 const mojo::String& media_source, | 253 const mojo::String& media_source, |
| 240 mojo::Array<mojo::String> joinable_route_ids) { | 254 mojo::Array<mojo::String> joinable_route_ids) { |
| 241 DCHECK(thread_checker_.CalledOnValidThread()); | 255 DCHECK(thread_checker_.CalledOnValidThread()); |
| 242 | 256 |
| 243 DVLOG_WITH_INSTANCE(1) << "OnRoutesUpdated"; | 257 DVLOG_WITH_INSTANCE(1) << "OnRoutesUpdated"; |
| 244 auto it = routes_queries_.find(media_source); | 258 auto it = routes_queries_.find(media_source); |
| 245 if (it == routes_queries_.end() || | 259 if (it == routes_queries_.end() || |
| 246 !(it->second->observers.might_have_observers())) { | 260 !(it->second->observers.might_have_observers())) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 media_route.To<scoped_ptr<MediaRoute>>(), presentation_id); | 303 media_route.To<scoped_ptr<MediaRoute>>(), presentation_id); |
| 290 if (result->route()->off_the_record()) | 304 if (result->route()->off_the_record()) |
| 291 OnOffTheRecordRouteCreated(result->route()->media_route_id()); | 305 OnOffTheRecordRouteCreated(result->route()->media_route_id()); |
| 292 } | 306 } |
| 293 | 307 |
| 294 // TODO(imcheng): Add UMA histogram based on result code (crbug.com/583044). | 308 // TODO(imcheng): Add UMA histogram based on result code (crbug.com/583044). |
| 295 for (const MediaRouteResponseCallback& callback : callbacks) | 309 for (const MediaRouteResponseCallback& callback : callbacks) |
| 296 callback.Run(*result); | 310 callback.Run(*result); |
| 297 } | 311 } |
| 298 | 312 |
| 313 void MediaRouterMojoImpl::SearchAndCreateResponseReceived( | |
|
imcheng
2016/04/18 23:15:46
So this is very similar to RouteResponseReceived e
btolsch
2016/04/19 01:39:42
No, removed.
| |
| 314 const std::string& presentation_id, | |
| 315 const std::vector<MediaRouteResponseCallback>& route_callbacks, | |
| 316 interfaces::MediaRoutePtr media_route, | |
| 317 const mojo::String& error_text, | |
| 318 interfaces::RouteRequestResultCode result_code) { | |
| 319 scoped_ptr<RouteRequestResult> result; | |
| 320 if (media_route.is_null()) { | |
| 321 // An error occurred. | |
| 322 DCHECK(!error_text.is_null()); | |
| 323 std::string error = | |
| 324 !error_text.get().empty() ? error_text.get() : "Unknown error."; | |
| 325 | |
| 326 result = RouteRequestResult::FromError( | |
| 327 error, mojo::RouteRequestResultCodeFromMojo(result_code)); | |
| 328 } else { | |
| 329 result = RouteRequestResult::FromSuccess( | |
| 330 media_route.To<scoped_ptr<MediaRoute>>(), presentation_id); | |
| 331 } | |
| 332 | |
| 333 for (const auto& route_callback : route_callbacks) { | |
| 334 route_callback.Run(*result); | |
| 335 } | |
| 336 } | |
| 337 | |
| 299 void MediaRouterMojoImpl::CreateRoute( | 338 void MediaRouterMojoImpl::CreateRoute( |
| 300 const MediaSource::Id& source_id, | 339 const MediaSource::Id& source_id, |
| 301 const MediaSink::Id& sink_id, | 340 const MediaSink::Id& sink_id, |
| 302 const GURL& origin, | 341 const GURL& origin, |
| 303 content::WebContents* web_contents, | 342 content::WebContents* web_contents, |
| 304 const std::vector<MediaRouteResponseCallback>& callbacks, | 343 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 305 base::TimeDelta timeout, | 344 base::TimeDelta timeout, |
| 306 bool off_the_record) { | 345 bool off_the_record) { |
| 307 DCHECK(thread_checker_.CalledOnValidThread()); | 346 DCHECK(thread_checker_.CalledOnValidThread()); |
| 308 | 347 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 DCHECK(thread_checker_.CalledOnValidThread()); | 464 DCHECK(thread_checker_.CalledOnValidThread()); |
| 426 issue_manager_.ClearIssue(issue_id); | 465 issue_manager_.ClearIssue(issue_id); |
| 427 } | 466 } |
| 428 | 467 |
| 429 void MediaRouterMojoImpl::OnUserGesture() { | 468 void MediaRouterMojoImpl::OnUserGesture() { |
| 430 #if defined(OS_WIN) | 469 #if defined(OS_WIN) |
| 431 EnsureMdnsDiscoveryEnabled(); | 470 EnsureMdnsDiscoveryEnabled(); |
| 432 #endif | 471 #endif |
| 433 } | 472 } |
| 434 | 473 |
| 474 void MediaRouterMojoImpl::SearchSinksAndCreateRoute( | |
| 475 const MediaSink::Id& sink_id, | |
| 476 const MediaSource::Id& source_id, | |
| 477 const std::string& search_input, | |
| 478 const std::string& domain, | |
| 479 const GURL& origin, | |
| 480 content::WebContents* web_contents, | |
| 481 const std::vector<MediaRouteResponseCallback>& route_callbacks, | |
| 482 const MediaSinkSearchResponseCallback& sink_callback, | |
| 483 base::TimeDelta timeout, | |
| 484 bool off_the_record) { | |
| 485 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 486 | |
| 487 int tab_id = SessionTabHelper::IdForTab(web_contents); | |
| 488 SetWakeReason(MediaRouteProviderWakeReason::SEARCH_SINKS); | |
| 489 RunOrDefer( | |
| 490 base::Bind(&MediaRouterMojoImpl::DoSearchSinksAndCreateRoute, | |
| 491 base::Unretained(this), sink_id, source_id, search_input, | |
| 492 domain, origin.is_empty() ? "" : origin.spec(), tab_id, | |
| 493 route_callbacks, sink_callback, timeout, off_the_record)); | |
| 494 } | |
| 495 | |
| 435 bool MediaRouterMojoImpl::RegisterMediaSinksObserver( | 496 bool MediaRouterMojoImpl::RegisterMediaSinksObserver( |
| 436 MediaSinksObserver* observer) { | 497 MediaSinksObserver* observer) { |
| 437 DCHECK(thread_checker_.CalledOnValidThread()); | 498 DCHECK(thread_checker_.CalledOnValidThread()); |
| 438 | 499 |
| 439 // Create an observer list for the media source and add |observer| | 500 // Create an observer list for the media source and add |observer| |
| 440 // to it. Fail if |observer| is already registered. | 501 // to it. Fail if |observer| is already registered. |
| 441 const std::string& source_id = observer->source().id(); | 502 const std::string& source_id = observer->source().id(); |
| 442 auto* sinks_query = sinks_queries_.get(source_id); | 503 auto* sinks_query = sinks_queries_.get(source_id); |
| 443 bool new_query = false; | 504 bool new_query = false; |
| 444 if (!sinks_query) { | 505 if (!sinks_query) { |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 695 void MediaRouterMojoImpl::DoStopListeningForRouteMessages( | 756 void MediaRouterMojoImpl::DoStopListeningForRouteMessages( |
| 696 const MediaRoute::Id& route_id) { | 757 const MediaRoute::Id& route_id) { |
| 697 DVLOG_WITH_INSTANCE(1) << "StopListeningForRouteMessages"; | 758 DVLOG_WITH_INSTANCE(1) << "StopListeningForRouteMessages"; |
| 698 | 759 |
| 699 // No need to erase |route_ids_listening_for_messages_| entry here. | 760 // No need to erase |route_ids_listening_for_messages_| entry here. |
| 700 // It will be removed when there are no more observers by the time | 761 // It will be removed when there are no more observers by the time |
| 701 // |OnRouteMessagesReceived| is invoked. | 762 // |OnRouteMessagesReceived| is invoked. |
| 702 media_route_provider_->StopListeningForRouteMessages(route_id); | 763 media_route_provider_->StopListeningForRouteMessages(route_id); |
| 703 } | 764 } |
| 704 | 765 |
| 766 void MediaRouterMojoImpl::DoSearchSinksAndCreateRoute( | |
| 767 const MediaSink::Id& sink_id, | |
| 768 const MediaSource::Id& source_id, | |
| 769 const std::string& search_input, | |
| 770 const std::string& domain, | |
| 771 const std::string& origin, | |
| 772 int tab_id, | |
| 773 const std::vector<MediaRouteResponseCallback>& route_callbacks, | |
| 774 const MediaSinkSearchResponseCallback& sink_callback, | |
| 775 base::TimeDelta timeout, | |
| 776 bool off_the_record) { | |
| 777 auto sink_callback_entry = search_callbacks_.find(sink_id); | |
| 778 if (sink_callback_entry != search_callbacks_.end()) { | |
| 779 LOG(WARNING) << "SearchSinksAndCreateRoute for pseudo sink " << sink_id | |
| 780 << " already has a registered callback."; | |
| 781 } else { | |
| 782 bool insert_will_succeed; | |
|
imcheng
2016/04/18 23:15:46
this variable is not used?
btolsch
2016/04/19 01:39:42
This was convenient when |sink_callback_entry| was
| |
| 783 std::tie(sink_callback_entry, insert_will_succeed) = | |
| 784 search_callbacks_.insert(std::make_pair(sink_id, sink_callback)); | |
| 785 } | |
| 786 | |
| 787 std::string presentation_id("mr_"); | |
| 788 presentation_id += base::GenerateGUID(); | |
| 789 DVLOG_WITH_INSTANCE(1) << "SearchSinksAndCreateRoute"; | |
| 790 auto sink_search_criteria = interfaces::SinkSearchCriteria::New(); | |
| 791 sink_search_criteria->input = search_input; | |
| 792 sink_search_criteria->domain = domain; | |
| 793 media_route_provider_->SearchSinksAndCreateRoute( | |
| 794 sink_id, source_id, std::move(sink_search_criteria), presentation_id, | |
| 795 origin, tab_id, | |
| 796 timeout > base::TimeDelta() ? timeout.InMilliseconds() : 0, | |
| 797 off_the_record, | |
| 798 base::Bind(&MediaRouterMojoImpl::SearchAndCreateResponseReceived, | |
| 799 weak_factory_.GetWeakPtr(), presentation_id, route_callbacks)); | |
| 800 } | |
| 801 | |
| 705 void MediaRouterMojoImpl::OnRouteMessagesReceived( | 802 void MediaRouterMojoImpl::OnRouteMessagesReceived( |
| 706 const MediaRoute::Id& route_id, | 803 const MediaRoute::Id& route_id, |
| 707 mojo::Array<interfaces::RouteMessagePtr> messages, | 804 mojo::Array<interfaces::RouteMessagePtr> messages, |
| 708 bool error) { | 805 bool error) { |
| 709 DVLOG(1) << "OnRouteMessagesReceived"; | 806 DVLOG(1) << "OnRouteMessagesReceived"; |
| 710 | 807 |
| 711 // If |messages| is null, then no more messages will come from this route. | 808 // If |messages| is null, then no more messages will come from this route. |
| 712 // We can stop listening. | 809 // We can stop listening. |
| 713 if (error) { | 810 if (error) { |
| 714 DVLOG(2) << "Encountered error in OnRouteMessagesReceived for " << route_id; | 811 DVLOG(2) << "Encountered error in OnRouteMessagesReceived for " << route_id; |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 980 } | 1077 } |
| 981 | 1078 |
| 982 void MediaRouterMojoImpl::OnFirewallCheckComplete( | 1079 void MediaRouterMojoImpl::OnFirewallCheckComplete( |
| 983 bool firewall_can_use_local_ports) { | 1080 bool firewall_can_use_local_ports) { |
| 984 if (firewall_can_use_local_ports) | 1081 if (firewall_can_use_local_ports) |
| 985 EnsureMdnsDiscoveryEnabled(); | 1082 EnsureMdnsDiscoveryEnabled(); |
| 986 } | 1083 } |
| 987 #endif | 1084 #endif |
| 988 | 1085 |
| 989 } // namespace media_router | 1086 } // namespace media_router |
| OLD | NEW |