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 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/guid.h" | 12 #include "base/guid.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "chrome/browser/media/router/discovery/dial/dial_media_sink_service_pro xy.h" | |
| 18 #include "chrome/browser/media/router/issues_observer.h" | 19 #include "chrome/browser/media/router/issues_observer.h" |
| 19 #include "chrome/browser/media/router/media_router_factory.h" | 20 #include "chrome/browser/media/router/media_router_factory.h" |
| 20 #include "chrome/browser/media/router/media_router_feature.h" | 21 #include "chrome/browser/media/router/media_router_feature.h" |
| 21 #include "chrome/browser/media/router/media_routes_observer.h" | 22 #include "chrome/browser/media/router/media_routes_observer.h" |
| 22 #include "chrome/browser/media/router/media_sinks_observer.h" | 23 #include "chrome/browser/media/router/media_sinks_observer.h" |
| 23 #include "chrome/browser/media/router/mojo/media_route_controller.h" | 24 #include "chrome/browser/media/router/mojo/media_route_controller.h" |
| 24 #include "chrome/browser/media/router/mojo/media_route_provider_util_win.h" | 25 #include "chrome/browser/media/router/mojo/media_route_provider_util_win.h" |
| 25 #include "chrome/browser/media/router/mojo/media_router_mojo_metrics.h" | 26 #include "chrome/browser/media/router/mojo/media_router_mojo_metrics.h" |
| 26 #include "chrome/browser/media/router/route_message_observer.h" | 27 #include "chrome/browser/media/router/route_message_observer.h" |
| 28 #include "chrome/browser/profiles/profile.h" | |
| 27 #include "chrome/browser/sessions/session_tab_helper.h" | 29 #include "chrome/browser/sessions/session_tab_helper.h" |
| 28 #include "chrome/common/media_router/media_source_helper.h" | 30 #include "chrome/common/media_router/media_source_helper.h" |
| 29 #include "chrome/common/media_router/route_message.h" | 31 #include "chrome/common/media_router/route_message.h" |
| 30 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
| 31 #include "extensions/browser/process_manager.h" | 33 #include "extensions/browser/process_manager.h" |
| 32 | 34 |
| 33 #define DVLOG_WITH_INSTANCE(level) \ | 35 #define DVLOG_WITH_INSTANCE(level) \ |
| 34 DVLOG(level) << "MR #" << instance_id_ << ": " | 36 DVLOG(level) << "MR #" << instance_id_ << ": " |
| 35 | 37 |
| 36 #define DLOG_WITH_INSTANCE(level) DLOG(level) << "MR #" << instance_id_ << ": " | 38 #define DLOG_WITH_INSTANCE(level) DLOG(level) << "MR #" << instance_id_ << ": " |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 52 | 54 |
| 53 MediaRouterMojoImpl::MediaRoutesQuery::MediaRoutesQuery() = default; | 55 MediaRouterMojoImpl::MediaRoutesQuery::MediaRoutesQuery() = default; |
| 54 | 56 |
| 55 MediaRouterMojoImpl::MediaRoutesQuery::~MediaRoutesQuery() = default; | 57 MediaRouterMojoImpl::MediaRoutesQuery::~MediaRoutesQuery() = default; |
| 56 | 58 |
| 57 MediaRouterMojoImpl::MediaSinksQuery::MediaSinksQuery() = default; | 59 MediaRouterMojoImpl::MediaSinksQuery::MediaSinksQuery() = default; |
| 58 | 60 |
| 59 MediaRouterMojoImpl::MediaSinksQuery::~MediaSinksQuery() = default; | 61 MediaRouterMojoImpl::MediaSinksQuery::~MediaSinksQuery() = default; |
| 60 | 62 |
| 61 MediaRouterMojoImpl::MediaRouterMojoImpl( | 63 MediaRouterMojoImpl::MediaRouterMojoImpl( |
| 62 extensions::EventPageTracker* event_page_tracker) | 64 extensions::EventPageTracker* event_page_tracker, |
| 65 content::BrowserContext* context) | |
| 63 : event_page_tracker_(event_page_tracker), | 66 : event_page_tracker_(event_page_tracker), |
| 64 instance_id_(base::GenerateGUID()), | 67 instance_id_(base::GenerateGUID()), |
| 65 availability_(mojom::MediaRouter::SinkAvailability::UNAVAILABLE), | 68 availability_(mojom::MediaRouter::SinkAvailability::UNAVAILABLE), |
| 66 current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT), | 69 current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT), |
| 70 context_(context), | |
| 67 weak_factory_(this) { | 71 weak_factory_(this) { |
| 68 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 72 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 69 DCHECK(event_page_tracker_); | 73 DCHECK(event_page_tracker_); |
| 70 #if defined(OS_WIN) | 74 #if defined(OS_WIN) |
| 71 CanFirewallUseLocalPorts( | 75 CanFirewallUseLocalPorts( |
| 72 base::Bind(&MediaRouterMojoImpl::OnFirewallCheckComplete, | 76 base::Bind(&MediaRouterMojoImpl::OnFirewallCheckComplete, |
| 73 weak_factory_.GetWeakPtr())); | 77 weak_factory_.GetWeakPtr())); |
| 74 #endif | 78 #endif |
| 75 } | 79 } |
| 76 | 80 |
| 77 MediaRouterMojoImpl::~MediaRouterMojoImpl() { | 81 MediaRouterMojoImpl::~MediaRouterMojoImpl() { |
| 78 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 82 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 83 if (dial_media_sink_service_proxy_) | |
| 84 dial_media_sink_service_proxy_->Stop(); | |
| 79 } | 85 } |
| 80 | 86 |
| 81 // static | 87 // static |
| 82 void MediaRouterMojoImpl::BindToRequest( | 88 void MediaRouterMojoImpl::BindToRequest( |
| 83 const extensions::Extension* extension, | 89 const extensions::Extension* extension, |
| 84 content::BrowserContext* context, | 90 content::BrowserContext* context, |
| 85 const service_manager::BindSourceInfo& source_info, | 91 const service_manager::BindSourceInfo& source_info, |
| 86 mojom::MediaRouterRequest request) { | 92 mojom::MediaRouterRequest request) { |
| 87 MediaRouterMojoImpl* impl = static_cast<MediaRouterMojoImpl*>( | 93 MediaRouterMojoImpl* impl = static_cast<MediaRouterMojoImpl*>( |
| 88 MediaRouterFactory::GetApiForBrowserContext(context)); | 94 MediaRouterFactory::GetApiForBrowserContext(context)); |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 | 426 |
| 421 SetWakeReason(MediaRouteProviderWakeReason::CREATE_MEDIA_ROUTE_CONTROLLER); | 427 SetWakeReason(MediaRouteProviderWakeReason::CREATE_MEDIA_ROUTE_CONTROLLER); |
| 422 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoCreateMediaRouteController, | 428 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoCreateMediaRouteController, |
| 423 base::Unretained(this), route_id, | 429 base::Unretained(this), route_id, |
| 424 std::move(mojo_media_controller_request), | 430 std::move(mojo_media_controller_request), |
| 425 route_controller->BindObserverPtr())); | 431 route_controller->BindObserverPtr())); |
| 426 route_controllers_.emplace(route_id, route_controller.get()); | 432 route_controllers_.emplace(route_id, route_controller.get()); |
| 427 return route_controller; | 433 return route_controller; |
| 428 } | 434 } |
| 429 | 435 |
| 430 void MediaRouterMojoImpl::ProvideSinks( | 436 void MediaRouterMojoImpl::ProvideSinks(const std::string& provider_name, |
| 431 const std::string& provider_name, | 437 std::vector<MediaSinkInternal> sinks) { |
| 432 const std::vector<MediaSinkInternal>& sinks) { | |
| 433 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 438 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 439 DVLOG_WITH_INSTANCE(1) << "OnDialMediaSinkDiscovered found " << sinks.size() | |
| 440 << " devices..."; | |
| 434 | 441 |
| 435 SetWakeReason(MediaRouteProviderWakeReason::PROVIDE_SINKS); | 442 SetWakeReason(MediaRouteProviderWakeReason::PROVIDE_SINKS); |
| 436 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoProvideSinks, | 443 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoProvideSinks, |
| 437 base::Unretained(this), provider_name, sinks)); | 444 base::Unretained(this), provider_name, |
| 445 std::move(sinks))); | |
|
imcheng
2017/05/26 01:26:00
ditto on std::move.
zhaobin
2017/05/26 20:59:40
Use std::move to avoid copy as Mark suggested.
| |
| 438 } | 446 } |
| 439 | 447 |
| 440 bool MediaRouterMojoImpl::RegisterMediaSinksObserver( | 448 bool MediaRouterMojoImpl::RegisterMediaSinksObserver( |
| 441 MediaSinksObserver* observer) { | 449 MediaSinksObserver* observer) { |
| 442 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 450 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 443 | 451 |
| 444 // Create an observer list for the media source and add |observer| | 452 // Create an observer list for the media source and add |observer| |
| 445 // to it. Fail if |observer| is already registered. | 453 // to it. Fail if |observer| is already registered. |
| 446 const std::string& source_id = observer->source().id(); | 454 const std::string& source_id = observer->source().id(); |
| 447 std::unique_ptr<MediaSinksQuery>& sinks_query = sinks_queries_[source_id]; | 455 std::unique_ptr<MediaSinksQuery>& sinks_query = sinks_queries_[source_id]; |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 744 const std::string& domain, | 752 const std::string& domain, |
| 745 const MediaSinkSearchResponseCallback& sink_callback) { | 753 const MediaSinkSearchResponseCallback& sink_callback) { |
| 746 DVLOG_WITH_INSTANCE(1) << "SearchSinks"; | 754 DVLOG_WITH_INSTANCE(1) << "SearchSinks"; |
| 747 auto sink_search_criteria = mojom::SinkSearchCriteria::New(); | 755 auto sink_search_criteria = mojom::SinkSearchCriteria::New(); |
| 748 sink_search_criteria->input = search_input; | 756 sink_search_criteria->input = search_input; |
| 749 sink_search_criteria->domain = domain; | 757 sink_search_criteria->domain = domain; |
| 750 media_route_provider_->SearchSinks( | 758 media_route_provider_->SearchSinks( |
| 751 sink_id, source_id, std::move(sink_search_criteria), sink_callback); | 759 sink_id, source_id, std::move(sink_search_criteria), sink_callback); |
| 752 } | 760 } |
| 753 | 761 |
| 754 void MediaRouterMojoImpl::DoProvideSinks( | 762 void MediaRouterMojoImpl::DoProvideSinks(const std::string& provider_name, |
| 755 const std::string& provider_name, | 763 std::vector<MediaSinkInternal> sinks) { |
| 756 const std::vector<MediaSinkInternal>& sinks) { | |
| 757 DVLOG_WITH_INSTANCE(1) << "DoProvideSinks"; | 764 DVLOG_WITH_INSTANCE(1) << "DoProvideSinks"; |
| 758 media_route_provider_->ProvideSinks(provider_name, sinks); | 765 media_route_provider_->ProvideSinks(provider_name, sinks); |
| 759 } | 766 } |
| 760 | 767 |
| 761 void MediaRouterMojoImpl::DoCreateMediaRouteController( | 768 void MediaRouterMojoImpl::DoCreateMediaRouteController( |
| 762 const MediaRoute::Id& route_id, | 769 const MediaRoute::Id& route_id, |
| 763 mojom::MediaControllerRequest mojo_media_controller_request, | 770 mojom::MediaControllerRequest mojo_media_controller_request, |
| 764 mojom::MediaStatusObserverPtr mojo_observer) { | 771 mojom::MediaStatusObserverPtr mojo_observer) { |
| 765 DVLOG_WITH_INSTANCE(1) << "DoCreateMediaRouteController"; | 772 DVLOG_WITH_INSTANCE(1) << "DoCreateMediaRouteController"; |
| 766 if (!mojo_media_controller_request.is_pending() || !mojo_observer.is_bound()) | 773 if (!mojo_media_controller_request.is_pending() || !mojo_observer.is_bound()) |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 998 #if defined(OS_WIN) | 1005 #if defined(OS_WIN) |
| 999 // The MRPM extension already turns on mDNS discovery for platforms other than | 1006 // The MRPM extension already turns on mDNS discovery for platforms other than |
| 1000 // Windows. It only relies on this signalling from MR on Windows to avoid | 1007 // Windows. It only relies on this signalling from MR on Windows to avoid |
| 1001 // triggering a firewall prompt out of the context of MR from the user's | 1008 // triggering a firewall prompt out of the context of MR from the user's |
| 1002 // perspective. This particular call reminds the extension to enable mDNS | 1009 // perspective. This particular call reminds the extension to enable mDNS |
| 1003 // discovery when it wakes up, has been upgraded, etc. | 1010 // discovery when it wakes up, has been upgraded, etc. |
| 1004 if (should_enable_mdns_discovery_) { | 1011 if (should_enable_mdns_discovery_) { |
| 1005 DoEnsureMdnsDiscoveryEnabled(); | 1012 DoEnsureMdnsDiscoveryEnabled(); |
| 1006 } | 1013 } |
| 1007 #endif | 1014 #endif |
| 1015 | |
| 1016 if (media_router::DialLocalDiscoveryEnabled()) | |
| 1017 StartDiscovery(); | |
| 1008 } | 1018 } |
| 1009 | 1019 |
| 1010 void MediaRouterMojoImpl::EventPageWakeComplete(bool success) { | 1020 void MediaRouterMojoImpl::EventPageWakeComplete(bool success) { |
| 1011 if (success) { | 1021 if (success) { |
| 1012 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeReason( | 1022 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeReason( |
| 1013 current_wake_reason_); | 1023 current_wake_reason_); |
| 1014 ClearWakeReason(); | 1024 ClearWakeReason(); |
| 1015 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeup( | 1025 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeup( |
| 1016 MediaRouteProviderWakeup::SUCCESS); | 1026 MediaRouteProviderWakeup::SUCCESS); |
| 1017 return; | 1027 return; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1063 } | 1073 } |
| 1064 } | 1074 } |
| 1065 | 1075 |
| 1066 void MediaRouterMojoImpl::OnFirewallCheckComplete( | 1076 void MediaRouterMojoImpl::OnFirewallCheckComplete( |
| 1067 bool firewall_can_use_local_ports) { | 1077 bool firewall_can_use_local_ports) { |
| 1068 if (firewall_can_use_local_ports) | 1078 if (firewall_can_use_local_ports) |
| 1069 EnsureMdnsDiscoveryEnabled(); | 1079 EnsureMdnsDiscoveryEnabled(); |
| 1070 } | 1080 } |
| 1071 #endif | 1081 #endif |
| 1072 | 1082 |
| 1083 void MediaRouterMojoImpl::StartDiscovery() { | |
| 1084 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 1085 DVLOG_WITH_INSTANCE(1) << "StartDiscovery"; | |
| 1086 | |
| 1087 if (!dial_media_sink_service_proxy_) { | |
| 1088 dial_media_sink_service_proxy_ = new DialMediaSinkServiceProxy( | |
| 1089 base::Bind(&MediaRouterMojoImpl::ProvideSinks, | |
| 1090 weak_factory_.GetWeakPtr(), "dial"), | |
| 1091 context_); | |
| 1092 } | |
| 1093 | |
| 1094 dial_media_sink_service_proxy_->Start(); | |
| 1095 } | |
| 1096 | |
| 1073 void MediaRouterMojoImpl::UpdateMediaSinks( | 1097 void MediaRouterMojoImpl::UpdateMediaSinks( |
| 1074 const MediaSource::Id& source_id) { | 1098 const MediaSource::Id& source_id) { |
| 1075 SetWakeReason(MediaRouteProviderWakeReason::UPDATE_MEDIA_SINKS); | 1099 SetWakeReason(MediaRouteProviderWakeReason::UPDATE_MEDIA_SINKS); |
| 1076 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoUpdateMediaSinks, | 1100 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoUpdateMediaSinks, |
| 1077 base::Unretained(this), source_id)); | 1101 base::Unretained(this), source_id)); |
| 1078 } | 1102 } |
| 1079 | 1103 |
| 1080 void MediaRouterMojoImpl::DoUpdateMediaSinks( | 1104 void MediaRouterMojoImpl::DoUpdateMediaSinks( |
| 1081 const MediaSource::Id& source_id) { | 1105 const MediaSource::Id& source_id) { |
| 1082 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks: " << source_id; | 1106 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks: " << source_id; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1098 | 1122 |
| 1099 void MediaRouterMojoImpl::OnMediaControllerCreated( | 1123 void MediaRouterMojoImpl::OnMediaControllerCreated( |
| 1100 const MediaRoute::Id& route_id, | 1124 const MediaRoute::Id& route_id, |
| 1101 bool success) { | 1125 bool success) { |
| 1102 // TODO(takumif): Record success/failure with UMA. | 1126 // TODO(takumif): Record success/failure with UMA. |
| 1103 DVLOG_WITH_INSTANCE(1) << "OnMediaControllerCreated: " << route_id | 1127 DVLOG_WITH_INSTANCE(1) << "OnMediaControllerCreated: " << route_id |
| 1104 << (success ? " was successful." : " failed."); | 1128 << (success ? " was successful." : " failed."); |
| 1105 } | 1129 } |
| 1106 | 1130 |
| 1107 } // namespace media_router | 1131 } // namespace media_router |
| OLD | NEW |