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.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_routes_observer.h" | 21 #include "chrome/browser/media/router/media_routes_observer.h" |
| 21 #include "chrome/browser/media/router/media_sinks_observer.h" | 22 #include "chrome/browser/media/router/media_sinks_observer.h" |
| 22 #include "chrome/browser/media/router/mojo/media_route_controller.h" | 23 #include "chrome/browser/media/router/mojo/media_route_controller.h" |
| 23 #include "chrome/browser/media/router/mojo/media_route_provider_util_win.h" | 24 #include "chrome/browser/media/router/mojo/media_route_provider_util_win.h" |
| 24 #include "chrome/browser/media/router/mojo/media_router_mojo_metrics.h" | 25 #include "chrome/browser/media/router/mojo/media_router_mojo_metrics.h" |
| 25 #include "chrome/browser/media/router/route_message_observer.h" | 26 #include "chrome/browser/media/router/route_message_observer.h" |
| 26 #include "chrome/browser/sessions/session_tab_helper.h" | 27 #include "chrome/browser/sessions/session_tab_helper.h" |
| 27 #include "chrome/common/media_router/media_source_helper.h" | 28 #include "chrome/common/media_router/media_source_helper.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 40 | 41 |
| 41 void RunRouteRequestCallbacks( | 42 void RunRouteRequestCallbacks( |
| 42 std::unique_ptr<RouteRequestResult> result, | 43 std::unique_ptr<RouteRequestResult> result, |
| 43 const std::vector<MediaRouteResponseCallback>& callbacks) { | 44 const std::vector<MediaRouteResponseCallback>& callbacks) { |
| 44 for (const MediaRouteResponseCallback& callback : callbacks) | 45 for (const MediaRouteResponseCallback& callback : callbacks) |
| 45 callback.Run(*result); | 46 callback.Run(*result); |
| 46 } | 47 } |
| 47 | 48 |
| 48 } // namespace | 49 } // namespace |
| 49 | 50 |
| 51 #if !defined(OS_ANDROID) | |
| 52 // Controls if browser side device discovery is enabled. | |
| 53 const base::Feature kEnableBrowserSideDiscovery{ | |
| 54 "EnableBrowserSideDiscovery", base::FEATURE_DISABLED_BY_DEFAULT}; | |
|
mark a. foltz
2017/04/26 23:52:55
EnableDialLocalDiscovery ?
zhaobin
2017/05/03 01:53:59
Done.
| |
| 55 #endif | |
| 56 | |
| 50 using SinkAvailability = mojom::MediaRouter::SinkAvailability; | 57 using SinkAvailability = mojom::MediaRouter::SinkAvailability; |
| 51 | 58 |
| 52 MediaRouterMojoImpl::MediaRoutesQuery::MediaRoutesQuery() = default; | 59 MediaRouterMojoImpl::MediaRoutesQuery::MediaRoutesQuery() = default; |
| 53 | 60 |
| 54 MediaRouterMojoImpl::MediaRoutesQuery::~MediaRoutesQuery() = default; | 61 MediaRouterMojoImpl::MediaRoutesQuery::~MediaRoutesQuery() = default; |
| 55 | 62 |
| 56 MediaRouterMojoImpl::MediaSinksQuery::MediaSinksQuery() = default; | 63 MediaRouterMojoImpl::MediaSinksQuery::MediaSinksQuery() = default; |
| 57 | 64 |
| 58 MediaRouterMojoImpl::MediaSinksQuery::~MediaSinksQuery() = default; | 65 MediaRouterMojoImpl::MediaSinksQuery::~MediaSinksQuery() = default; |
| 59 | 66 |
| 60 MediaRouterMojoImpl::MediaRouterMojoImpl( | 67 MediaRouterMojoImpl::MediaRouterMojoImpl( |
| 61 extensions::EventPageTracker* event_page_tracker) | 68 extensions::EventPageTracker* event_page_tracker, |
| 69 content::BrowserContext* context) | |
| 62 : event_page_tracker_(event_page_tracker), | 70 : event_page_tracker_(event_page_tracker), |
| 63 instance_id_(base::GenerateGUID()), | 71 instance_id_(base::GenerateGUID()), |
| 64 availability_(mojom::MediaRouter::SinkAvailability::UNAVAILABLE), | 72 availability_(mojom::MediaRouter::SinkAvailability::UNAVAILABLE), |
| 65 current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT), | 73 current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT), |
| 66 weak_factory_(this) { | 74 weak_factory_(this) { |
| 67 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 75 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 68 DCHECK(event_page_tracker_); | 76 DCHECK(event_page_tracker_); |
| 69 #if defined(OS_WIN) | 77 #if defined(OS_WIN) |
| 70 CanFirewallUseLocalPorts( | 78 CanFirewallUseLocalPorts( |
| 71 base::Bind(&MediaRouterMojoImpl::OnFirewallCheckComplete, | 79 base::Bind(&MediaRouterMojoImpl::OnFirewallCheckComplete, |
| 72 weak_factory_.GetWeakPtr())); | 80 weak_factory_.GetWeakPtr())); |
| 73 #endif | 81 #endif |
| 82 context_ = context; | |
| 83 enable_browser_side_discovery_ = | |
| 84 base::FeatureList::IsEnabled(kEnableBrowserSideDiscovery); | |
| 74 } | 85 } |
| 75 | 86 |
| 76 MediaRouterMojoImpl::~MediaRouterMojoImpl() { | 87 MediaRouterMojoImpl::~MediaRouterMojoImpl() { |
| 77 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 88 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 78 } | 89 } |
| 79 | 90 |
| 80 // static | 91 // static |
| 81 void MediaRouterMojoImpl::BindToRequest( | 92 void MediaRouterMojoImpl::BindToRequest( |
| 82 const extensions::Extension* extension, | 93 const extensions::Extension* extension, |
| 83 content::BrowserContext* context, | 94 content::BrowserContext* context, |
| 84 mojo::InterfaceRequest<mojom::MediaRouter> request) { | 95 mojo::InterfaceRequest<mojom::MediaRouter> request) { |
| 85 MediaRouterMojoImpl* impl = static_cast<MediaRouterMojoImpl*>( | 96 MediaRouterMojoImpl* impl = static_cast<MediaRouterMojoImpl*>( |
| 86 MediaRouterFactory::GetApiForBrowserContext(context)); | 97 MediaRouterFactory::GetApiForBrowserContext(context)); |
| 87 DCHECK(impl); | 98 DCHECK(impl); |
| 88 | 99 |
| 89 impl->BindToMojoRequest(std::move(request), *extension); | 100 impl->BindToMojoRequest(std::move(request), *extension); |
| 101 | |
| 102 #if !defined(OS_ANDROID) | |
| 103 if (impl->enable_browser_side_discovery_) | |
| 104 impl->StartBrowserSideDiscovery(); | |
| 105 #endif | |
| 90 } | 106 } |
| 91 | 107 |
| 92 void MediaRouterMojoImpl::BindToMojoRequest( | 108 void MediaRouterMojoImpl::BindToMojoRequest( |
| 93 mojo::InterfaceRequest<mojom::MediaRouter> request, | 109 mojo::InterfaceRequest<mojom::MediaRouter> request, |
| 94 const extensions::Extension& extension) { | 110 const extensions::Extension& extension) { |
| 95 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 111 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 96 | 112 |
| 97 binding_.reset( | 113 binding_.reset( |
| 98 new mojo::Binding<mojom::MediaRouter>(this, std::move(request))); | 114 new mojo::Binding<mojom::MediaRouter>(this, std::move(request))); |
| 99 binding_->set_connection_error_handler(base::Bind( | 115 binding_->set_connection_error_handler(base::Bind( |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 "suspended."; | 160 "suspended."; |
| 145 media_route_provider_.reset(); | 161 media_route_provider_.reset(); |
| 146 SetWakeReason(MediaRouteProviderWakeReason::REGISTER_MEDIA_ROUTE_PROVIDER); | 162 SetWakeReason(MediaRouteProviderWakeReason::REGISTER_MEDIA_ROUTE_PROVIDER); |
| 147 AttemptWakeEventPage(); | 163 AttemptWakeEventPage(); |
| 148 return; | 164 return; |
| 149 } | 165 } |
| 150 | 166 |
| 151 media_route_provider_ = std::move(media_route_provider_ptr); | 167 media_route_provider_ = std::move(media_route_provider_ptr); |
| 152 media_route_provider_.set_connection_error_handler(base::Bind( | 168 media_route_provider_.set_connection_error_handler(base::Bind( |
| 153 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); | 169 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); |
| 154 callback.Run(instance_id_); | 170 callback.Run(instance_id_, enable_browser_side_discovery_); |
| 155 ExecutePendingRequests(); | 171 ExecutePendingRequests(); |
| 156 wakeup_attempt_count_ = 0; | 172 wakeup_attempt_count_ = 0; |
| 157 #if defined(OS_WIN) | 173 #if defined(OS_WIN) |
| 158 // The MRPM extension already turns on mDNS discovery for platforms other than | 174 // The MRPM extension already turns on mDNS discovery for platforms other than |
| 159 // Windows. It only relies on this signalling from MR on Windows to avoid | 175 // Windows. It only relies on this signalling from MR on Windows to avoid |
| 160 // triggering a firewall prompt out of the context of MR from the user's | 176 // triggering a firewall prompt out of the context of MR from the user's |
| 161 // perspective. This particular call reminds the extension to enable mDNS | 177 // perspective. This particular call reminds the extension to enable mDNS |
| 162 // discovery when it wakes up, has been upgraded, etc. | 178 // discovery when it wakes up, has been upgraded, etc. |
| 163 if (should_enable_mdns_discovery_) { | 179 if (should_enable_mdns_discovery_) { |
| 164 DoEnsureMdnsDiscoveryEnabled(); | 180 DoEnsureMdnsDiscoveryEnabled(); |
| (...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1030 } | 1046 } |
| 1031 } | 1047 } |
| 1032 | 1048 |
| 1033 void MediaRouterMojoImpl::OnFirewallCheckComplete( | 1049 void MediaRouterMojoImpl::OnFirewallCheckComplete( |
| 1034 bool firewall_can_use_local_ports) { | 1050 bool firewall_can_use_local_ports) { |
| 1035 if (firewall_can_use_local_ports) | 1051 if (firewall_can_use_local_ports) |
| 1036 EnsureMdnsDiscoveryEnabled(); | 1052 EnsureMdnsDiscoveryEnabled(); |
| 1037 } | 1053 } |
| 1038 #endif | 1054 #endif |
| 1039 | 1055 |
| 1056 #if !defined(OS_ANDROID) | |
| 1057 void MediaRouterMojoImpl::StartBrowserSideDiscovery() { | |
| 1058 if (dial_media_sink_service_) | |
| 1059 return; | |
| 1060 | |
| 1061 dial_media_sink_service_.reset(new DialMediaSinkService( | |
| 1062 base::Bind(&MediaRouterMojoImpl::OnDialMediaSinkDiscovered, | |
| 1063 base::Unretained(this)), | |
| 1064 context_)); | |
| 1065 | |
| 1066 content::BrowserThread::PostTask( | |
| 1067 content::BrowserThread::IO, FROM_HERE, | |
| 1068 base::Bind(&DialMediaSinkService::Start, | |
| 1069 base::Unretained(dial_media_sink_service_.get()))); | |
| 1070 } | |
| 1071 | |
| 1072 void MediaRouterMojoImpl::OnDialMediaSinkDiscovered( | |
| 1073 const std::vector<MediaSinkInternal>& sinks) { | |
| 1074 DVLOG_WITH_INSTANCE(1) << "OnDialMediaSinkDiscovered found " << sinks.size() | |
| 1075 << " devices..."; | |
| 1076 content::BrowserThread::PostTask( | |
| 1077 content::BrowserThread::UI, FROM_HERE, | |
| 1078 base::Bind(&MediaRouterMojoImpl::ProvideSinks, base::Unretained(this), | |
| 1079 "dial", sinks)); | |
| 1080 } | |
| 1081 | |
| 1082 #endif | |
| 1083 | |
| 1040 void MediaRouterMojoImpl::UpdateMediaSinks( | 1084 void MediaRouterMojoImpl::UpdateMediaSinks( |
| 1041 const MediaSource::Id& source_id) { | 1085 const MediaSource::Id& source_id) { |
| 1042 SetWakeReason(MediaRouteProviderWakeReason::UPDATE_MEDIA_SINKS); | 1086 SetWakeReason(MediaRouteProviderWakeReason::UPDATE_MEDIA_SINKS); |
| 1043 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoUpdateMediaSinks, | 1087 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoUpdateMediaSinks, |
| 1044 base::Unretained(this), source_id)); | 1088 base::Unretained(this), source_id)); |
| 1045 } | 1089 } |
| 1046 | 1090 |
| 1047 void MediaRouterMojoImpl::DoUpdateMediaSinks( | 1091 void MediaRouterMojoImpl::DoUpdateMediaSinks( |
| 1048 const MediaSource::Id& source_id) { | 1092 const MediaSource::Id& source_id) { |
| 1049 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks: " << source_id; | 1093 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks: " << source_id; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1065 | 1109 |
| 1066 void MediaRouterMojoImpl::OnMediaControllerCreated( | 1110 void MediaRouterMojoImpl::OnMediaControllerCreated( |
| 1067 const MediaRoute::Id& route_id, | 1111 const MediaRoute::Id& route_id, |
| 1068 bool success) { | 1112 bool success) { |
| 1069 // TODO(takumif): Record success/failure with UMA. | 1113 // TODO(takumif): Record success/failure with UMA. |
| 1070 DVLOG_WITH_INSTANCE(1) << "OnMediaControllerCreated: " << route_id | 1114 DVLOG_WITH_INSTANCE(1) << "OnMediaControllerCreated: " << route_id |
| 1071 << (success ? " was successful." : " failed."); | 1115 << (success ? " was successful." : " failed."); |
| 1072 } | 1116 } |
| 1073 | 1117 |
| 1074 } // namespace media_router | 1118 } // namespace media_router |
| OLD | NEW |