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 // Controls if browser side DIAL device discovery is enabled. | |
| 52 const base::Feature kEnableDialLocalDiscovery{ | |
| 53 "EnableDialLocalDiscovery", base::FEATURE_DISABLED_BY_DEFAULT}; | |
| 54 | |
| 55 // Controls if browser side Cast device discovery is enabled. | |
| 56 const base::Feature kEnableCastDiscovery{"EnableCastDiscovery", | |
| 57 base::FEATURE_DISABLED_BY_DEFAULT}; | |
| 58 | |
| 50 using SinkAvailability = mojom::MediaRouter::SinkAvailability; | 59 using SinkAvailability = mojom::MediaRouter::SinkAvailability; |
| 51 | 60 |
| 52 MediaRouterMojoImpl::MediaRoutesQuery::MediaRoutesQuery() = default; | 61 MediaRouterMojoImpl::MediaRoutesQuery::MediaRoutesQuery() = default; |
| 53 | 62 |
| 54 MediaRouterMojoImpl::MediaRoutesQuery::~MediaRoutesQuery() = default; | 63 MediaRouterMojoImpl::MediaRoutesQuery::~MediaRoutesQuery() = default; |
| 55 | 64 |
| 56 MediaRouterMojoImpl::MediaSinksQuery::MediaSinksQuery() = default; | 65 MediaRouterMojoImpl::MediaSinksQuery::MediaSinksQuery() = default; |
| 57 | 66 |
| 58 MediaRouterMojoImpl::MediaSinksQuery::~MediaSinksQuery() = default; | 67 MediaRouterMojoImpl::MediaSinksQuery::~MediaSinksQuery() = default; |
| 59 | 68 |
| 60 MediaRouterMojoImpl::MediaRouterMojoImpl( | 69 MediaRouterMojoImpl::MediaRouterMojoImpl( |
| 61 extensions::EventPageTracker* event_page_tracker) | 70 extensions::EventPageTracker* event_page_tracker, |
| 71 content::BrowserContext* context) | |
| 62 : event_page_tracker_(event_page_tracker), | 72 : event_page_tracker_(event_page_tracker), |
| 63 instance_id_(base::GenerateGUID()), | 73 instance_id_(base::GenerateGUID()), |
| 64 availability_(mojom::MediaRouter::SinkAvailability::UNAVAILABLE), | 74 availability_(mojom::MediaRouter::SinkAvailability::UNAVAILABLE), |
| 65 current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT), | 75 current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT), |
| 66 weak_factory_(this) { | 76 weak_factory_(this) { |
| 67 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 77 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 68 DCHECK(event_page_tracker_); | 78 DCHECK(event_page_tracker_); |
| 69 #if defined(OS_WIN) | 79 #if defined(OS_WIN) |
| 70 CanFirewallUseLocalPorts( | 80 CanFirewallUseLocalPorts( |
| 71 base::Bind(&MediaRouterMojoImpl::OnFirewallCheckComplete, | 81 base::Bind(&MediaRouterMojoImpl::OnFirewallCheckComplete, |
| 72 weak_factory_.GetWeakPtr())); | 82 weak_factory_.GetWeakPtr())); |
| 73 #endif | 83 #endif |
| 84 context_ = context; | |
| 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 (!base::FeatureList::IsEnabled(kEnableDialLocalDiscovery)) | |
| 103 return; | |
| 104 | |
| 105 auto* profile = Profile::FromBrowserContext(context); | |
|
mark a. foltz
2017/05/01 20:32:57
Can the rest of this method be factored into Start
zhaobin
2017/05/03 01:53:59
Done.
| |
| 106 auto* request_context = profile ? profile->GetRequestContext() : nullptr; | |
| 107 if (!request_context) | |
| 108 return; | |
| 109 | |
| 110 content::BrowserThread::PostTask( | |
| 111 content::BrowserThread::IO, FROM_HERE, | |
| 112 base::Bind(&MediaRouterMojoImpl::StartBrowserSideDiscovery, | |
| 113 base::Unretained(impl), request_context)); | |
| 90 } | 114 } |
| 91 | 115 |
| 92 void MediaRouterMojoImpl::BindToMojoRequest( | 116 void MediaRouterMojoImpl::BindToMojoRequest( |
| 93 mojo::InterfaceRequest<mojom::MediaRouter> request, | 117 mojo::InterfaceRequest<mojom::MediaRouter> request, |
| 94 const extensions::Extension& extension) { | 118 const extensions::Extension& extension) { |
| 95 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 119 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 96 | 120 |
| 97 binding_.reset( | 121 binding_.reset( |
| 98 new mojo::Binding<mojom::MediaRouter>(this, std::move(request))); | 122 new mojo::Binding<mojom::MediaRouter>(this, std::move(request))); |
| 99 binding_->set_connection_error_handler(base::Bind( | 123 binding_->set_connection_error_handler(base::Bind( |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 "suspended."; | 168 "suspended."; |
| 145 media_route_provider_.reset(); | 169 media_route_provider_.reset(); |
| 146 SetWakeReason(MediaRouteProviderWakeReason::REGISTER_MEDIA_ROUTE_PROVIDER); | 170 SetWakeReason(MediaRouteProviderWakeReason::REGISTER_MEDIA_ROUTE_PROVIDER); |
| 147 AttemptWakeEventPage(); | 171 AttemptWakeEventPage(); |
| 148 return; | 172 return; |
| 149 } | 173 } |
| 150 | 174 |
| 151 media_route_provider_ = std::move(media_route_provider_ptr); | 175 media_route_provider_ = std::move(media_route_provider_ptr); |
| 152 media_route_provider_.set_connection_error_handler(base::Bind( | 176 media_route_provider_.set_connection_error_handler(base::Bind( |
| 153 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); | 177 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); |
| 154 callback.Run(instance_id_); | 178 |
| 179 auto config = mojom::MediaRouteProviderConfig::New(); | |
| 180 config->enable_dial_discovery = | |
| 181 !base::FeatureList::IsEnabled(kEnableDialLocalDiscovery); | |
|
mark a. foltz
2017/05/01 20:32:57
Nice :)
zhaobin
2017/05/03 01:53:59
Acknowledged.
| |
| 182 config->enable_cast_discovery = | |
| 183 !base::FeatureList::IsEnabled(kEnableCastDiscovery); | |
| 184 callback.Run(instance_id_, std::move(config)); | |
| 155 ExecutePendingRequests(); | 185 ExecutePendingRequests(); |
| 156 wakeup_attempt_count_ = 0; | 186 wakeup_attempt_count_ = 0; |
| 157 #if defined(OS_WIN) | 187 #if defined(OS_WIN) |
| 158 // The MRPM extension already turns on mDNS discovery for platforms other than | 188 // 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 | 189 // 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 | 190 // 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 | 191 // perspective. This particular call reminds the extension to enable mDNS |
| 162 // discovery when it wakes up, has been upgraded, etc. | 192 // discovery when it wakes up, has been upgraded, etc. |
| 163 if (should_enable_mdns_discovery_) { | 193 if (should_enable_mdns_discovery_) { |
| 164 DoEnsureMdnsDiscoveryEnabled(); | 194 DoEnsureMdnsDiscoveryEnabled(); |
| (...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1030 } | 1060 } |
| 1031 } | 1061 } |
| 1032 | 1062 |
| 1033 void MediaRouterMojoImpl::OnFirewallCheckComplete( | 1063 void MediaRouterMojoImpl::OnFirewallCheckComplete( |
| 1034 bool firewall_can_use_local_ports) { | 1064 bool firewall_can_use_local_ports) { |
| 1035 if (firewall_can_use_local_ports) | 1065 if (firewall_can_use_local_ports) |
| 1036 EnsureMdnsDiscoveryEnabled(); | 1066 EnsureMdnsDiscoveryEnabled(); |
| 1037 } | 1067 } |
| 1038 #endif | 1068 #endif |
| 1039 | 1069 |
| 1070 void MediaRouterMojoImpl::StartBrowserSideDiscovery( | |
| 1071 net::URLRequestContextGetter* request_context) { | |
| 1072 DVLOG_WITH_INSTANCE(1) << "StartBrowserSideDiscovery"; | |
|
mark a. foltz
2017/05/01 20:32:57
DCHECK that this is running on the IO thread.
zhaobin
2017/05/03 01:53:59
Done.
| |
| 1073 | |
| 1074 if (dial_media_sink_service_) | |
| 1075 return; | |
| 1076 | |
| 1077 dial_media_sink_service_.reset(new DialMediaSinkService( | |
|
mark a. foltz
2017/05/01 20:32:57
= MakeUnique<>()
zhaobin
2017/05/03 01:53:59
dial_media_sink_service_ is a scoped_refptr now...
| |
| 1078 base::Bind(&MediaRouterMojoImpl::OnDialMediaSinkDiscovered, | |
| 1079 base::Unretained(this)), | |
| 1080 request_context)); | |
| 1081 dial_media_sink_service_->Start(); | |
| 1082 } | |
| 1083 | |
| 1084 void MediaRouterMojoImpl::OnDialMediaSinkDiscovered( | |
| 1085 const std::vector<MediaSinkInternal>& sinks) { | |
| 1086 DVLOG_WITH_INSTANCE(1) << "OnDialMediaSinkDiscovered found " << sinks.size() | |
| 1087 << " devices..."; | |
| 1088 content::BrowserThread::PostTask( | |
| 1089 content::BrowserThread::UI, FROM_HERE, | |
| 1090 base::Bind(&MediaRouterMojoImpl::ProvideSinks, base::Unretained(this), | |
| 1091 "dial", sinks)); | |
| 1092 } | |
| 1093 | |
| 1040 void MediaRouterMojoImpl::UpdateMediaSinks( | 1094 void MediaRouterMojoImpl::UpdateMediaSinks( |
| 1041 const MediaSource::Id& source_id) { | 1095 const MediaSource::Id& source_id) { |
| 1042 SetWakeReason(MediaRouteProviderWakeReason::UPDATE_MEDIA_SINKS); | 1096 SetWakeReason(MediaRouteProviderWakeReason::UPDATE_MEDIA_SINKS); |
| 1043 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoUpdateMediaSinks, | 1097 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoUpdateMediaSinks, |
| 1044 base::Unretained(this), source_id)); | 1098 base::Unretained(this), source_id)); |
| 1045 } | 1099 } |
| 1046 | 1100 |
| 1047 void MediaRouterMojoImpl::DoUpdateMediaSinks( | 1101 void MediaRouterMojoImpl::DoUpdateMediaSinks( |
| 1048 const MediaSource::Id& source_id) { | 1102 const MediaSource::Id& source_id) { |
| 1049 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks: " << source_id; | 1103 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks: " << source_id; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1065 | 1119 |
| 1066 void MediaRouterMojoImpl::OnMediaControllerCreated( | 1120 void MediaRouterMojoImpl::OnMediaControllerCreated( |
| 1067 const MediaRoute::Id& route_id, | 1121 const MediaRoute::Id& route_id, |
| 1068 bool success) { | 1122 bool success) { |
| 1069 // TODO(takumif): Record success/failure with UMA. | 1123 // TODO(takumif): Record success/failure with UMA. |
| 1070 DVLOG_WITH_INSTANCE(1) << "OnMediaControllerCreated: " << route_id | 1124 DVLOG_WITH_INSTANCE(1) << "OnMediaControllerCreated: " << route_id |
| 1071 << (success ? " was successful." : " failed."); | 1125 << (success ? " was successful." : " failed."); |
| 1072 } | 1126 } |
| 1073 | 1127 |
| 1074 } // namespace media_router | 1128 } // namespace media_router |
| OLD | NEW |