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" |
| 21 #include "chrome/browser/media/router/media_router_feature.h" | |
| 20 #include "chrome/browser/media/router/media_routes_observer.h" | 22 #include "chrome/browser/media/router/media_routes_observer.h" |
| 21 #include "chrome/browser/media/router/media_sinks_observer.h" | 23 #include "chrome/browser/media/router/media_sinks_observer.h" |
| 22 #include "chrome/browser/media/router/mojo/media_route_controller.h" | 24 #include "chrome/browser/media/router/mojo/media_route_controller.h" |
| 23 #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" |
| 24 #include "chrome/browser/media/router/mojo/media_router_mojo_metrics.h" | 26 #include "chrome/browser/media/router/mojo/media_router_mojo_metrics.h" |
| 25 #include "chrome/browser/media/router/route_message_observer.h" | 27 #include "chrome/browser/media/router/route_message_observer.h" |
| 26 #include "chrome/browser/sessions/session_tab_helper.h" | 28 #include "chrome/browser/sessions/session_tab_helper.h" |
| 27 #include "chrome/common/media_router/media_source_helper.h" | 29 #include "chrome/common/media_router/media_source_helper.h" |
| 28 #include "chrome/common/media_router/route_message.h" | 30 #include "chrome/common/media_router/route_message.h" |
| 29 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 51 | 53 |
| 52 MediaRouterMojoImpl::MediaRoutesQuery::MediaRoutesQuery() = default; | 54 MediaRouterMojoImpl::MediaRoutesQuery::MediaRoutesQuery() = default; |
| 53 | 55 |
| 54 MediaRouterMojoImpl::MediaRoutesQuery::~MediaRoutesQuery() = default; | 56 MediaRouterMojoImpl::MediaRoutesQuery::~MediaRoutesQuery() = default; |
| 55 | 57 |
| 56 MediaRouterMojoImpl::MediaSinksQuery::MediaSinksQuery() = default; | 58 MediaRouterMojoImpl::MediaSinksQuery::MediaSinksQuery() = default; |
| 57 | 59 |
| 58 MediaRouterMojoImpl::MediaSinksQuery::~MediaSinksQuery() = default; | 60 MediaRouterMojoImpl::MediaSinksQuery::~MediaSinksQuery() = default; |
| 59 | 61 |
| 60 MediaRouterMojoImpl::MediaRouterMojoImpl( | 62 MediaRouterMojoImpl::MediaRouterMojoImpl( |
| 61 extensions::EventPageTracker* event_page_tracker) | 63 extensions::EventPageTracker* event_page_tracker, |
| 64 content::BrowserContext* context) | |
| 62 : event_page_tracker_(event_page_tracker), | 65 : event_page_tracker_(event_page_tracker), |
| 63 instance_id_(base::GenerateGUID()), | 66 instance_id_(base::GenerateGUID()), |
| 64 availability_(mojom::MediaRouter::SinkAvailability::UNAVAILABLE), | 67 availability_(mojom::MediaRouter::SinkAvailability::UNAVAILABLE), |
| 65 current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT), | 68 current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT), |
| 66 weak_factory_(this) { | 69 weak_factory_(this) { |
| 67 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 68 DCHECK(event_page_tracker_); | 71 DCHECK(event_page_tracker_); |
| 69 #if defined(OS_WIN) | 72 #if defined(OS_WIN) |
| 70 CanFirewallUseLocalPorts( | 73 CanFirewallUseLocalPorts( |
| 71 base::Bind(&MediaRouterMojoImpl::OnFirewallCheckComplete, | 74 base::Bind(&MediaRouterMojoImpl::OnFirewallCheckComplete, |
| 72 weak_factory_.GetWeakPtr())); | 75 weak_factory_.GetWeakPtr())); |
| 73 #endif | 76 #endif |
| 77 context_ = context; | |
|
Kevin M
2017/05/03 21:07:27
Put this in the initialization list?
zhaobin
2017/05/04 23:52:36
Done.
| |
| 74 } | 78 } |
| 75 | 79 |
| 76 MediaRouterMojoImpl::~MediaRouterMojoImpl() { | 80 MediaRouterMojoImpl::~MediaRouterMojoImpl() { |
| 77 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 81 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 78 } | 82 } |
| 79 | 83 |
| 80 // static | 84 // static |
| 81 void MediaRouterMojoImpl::BindToRequest( | 85 void MediaRouterMojoImpl::BindToRequest( |
| 82 const extensions::Extension* extension, | 86 const extensions::Extension* extension, |
| 83 content::BrowserContext* context, | 87 content::BrowserContext* context, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 "suspended."; | 148 "suspended."; |
| 145 media_route_provider_.reset(); | 149 media_route_provider_.reset(); |
| 146 SetWakeReason(MediaRouteProviderWakeReason::REGISTER_MEDIA_ROUTE_PROVIDER); | 150 SetWakeReason(MediaRouteProviderWakeReason::REGISTER_MEDIA_ROUTE_PROVIDER); |
| 147 AttemptWakeEventPage(); | 151 AttemptWakeEventPage(); |
| 148 return; | 152 return; |
| 149 } | 153 } |
| 150 | 154 |
| 151 media_route_provider_ = std::move(media_route_provider_ptr); | 155 media_route_provider_ = std::move(media_route_provider_ptr); |
| 152 media_route_provider_.set_connection_error_handler(base::Bind( | 156 media_route_provider_.set_connection_error_handler(base::Bind( |
| 153 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); | 157 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); |
| 154 callback.Run(instance_id_); | 158 |
| 159 auto config = mojom::MediaRouteProviderConfig::New(); | |
| 160 config->enable_dial_discovery = !media_router::DialLocalDiscoveryEnabled(); | |
|
Kevin M
2017/05/03 21:07:27
Eh??? This doesn't make sense - you're setting an
zhaobin
2017/05/04 23:52:36
Yes. config->enable_dial_discovery controls extens
| |
| 161 config->enable_cast_discovery = !media_router::CastDiscoveryEnabled(); | |
| 162 callback.Run(instance_id_, std::move(config)); | |
| 155 ExecutePendingRequests(); | 163 ExecutePendingRequests(); |
| 156 wakeup_attempt_count_ = 0; | 164 wakeup_attempt_count_ = 0; |
| 157 #if defined(OS_WIN) | 165 #if defined(OS_WIN) |
| 158 // The MRPM extension already turns on mDNS discovery for platforms other than | 166 // 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 | 167 // 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 | 168 // 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 | 169 // perspective. This particular call reminds the extension to enable mDNS |
| 162 // discovery when it wakes up, has been upgraded, etc. | 170 // discovery when it wakes up, has been upgraded, etc. |
| 163 if (should_enable_mdns_discovery_) { | 171 if (should_enable_mdns_discovery_) { |
| 164 DoEnsureMdnsDiscoveryEnabled(); | 172 DoEnsureMdnsDiscoveryEnabled(); |
| 165 } | 173 } |
| 166 #endif | 174 #endif |
| 175 | |
| 176 if (media_router::DialLocalDiscoveryEnabled()) | |
| 177 StartDiscovery(); | |
| 167 } | 178 } |
| 168 | 179 |
| 169 void MediaRouterMojoImpl::OnIssue(const IssueInfo& issue) { | 180 void MediaRouterMojoImpl::OnIssue(const IssueInfo& issue) { |
| 170 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 181 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 171 DVLOG_WITH_INSTANCE(1) << "OnIssue " << issue.title; | 182 DVLOG_WITH_INSTANCE(1) << "OnIssue " << issue.title; |
| 172 issue_manager_.AddIssue(issue); | 183 issue_manager_.AddIssue(issue); |
| 173 } | 184 } |
| 174 | 185 |
| 175 void MediaRouterMojoImpl::OnSinksReceived( | 186 void MediaRouterMojoImpl::OnSinksReceived( |
| 176 const std::string& media_source, | 187 const std::string& media_source, |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 423 std::move(mojo_media_controller_request), | 434 std::move(mojo_media_controller_request), |
| 424 route_controller->BindObserverPtr())); | 435 route_controller->BindObserverPtr())); |
| 425 route_controllers_.emplace(route_id, route_controller.get()); | 436 route_controllers_.emplace(route_id, route_controller.get()); |
| 426 return route_controller; | 437 return route_controller; |
| 427 } | 438 } |
| 428 | 439 |
| 429 void MediaRouterMojoImpl::ProvideSinks( | 440 void MediaRouterMojoImpl::ProvideSinks( |
| 430 const std::string& provider_name, | 441 const std::string& provider_name, |
| 431 const std::vector<MediaSinkInternal>& sinks) { | 442 const std::vector<MediaSinkInternal>& sinks) { |
| 432 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 443 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 444 DVLOG_WITH_INSTANCE(1) << "OnDialMediaSinkDiscovered found " << sinks.size() | |
| 445 << " devices..."; | |
| 433 | 446 |
| 434 SetWakeReason(MediaRouteProviderWakeReason::PROVIDE_SINKS); | 447 SetWakeReason(MediaRouteProviderWakeReason::PROVIDE_SINKS); |
| 435 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoProvideSinks, | 448 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoProvideSinks, |
| 436 base::Unretained(this), provider_name, sinks)); | 449 base::Unretained(this), provider_name, sinks)); |
| 437 } | 450 } |
| 438 | 451 |
| 439 bool MediaRouterMojoImpl::RegisterMediaSinksObserver( | 452 bool MediaRouterMojoImpl::RegisterMediaSinksObserver( |
| 440 MediaSinksObserver* observer) { | 453 MediaSinksObserver* observer) { |
| 441 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 454 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 442 | 455 |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1030 } | 1043 } |
| 1031 } | 1044 } |
| 1032 | 1045 |
| 1033 void MediaRouterMojoImpl::OnFirewallCheckComplete( | 1046 void MediaRouterMojoImpl::OnFirewallCheckComplete( |
| 1034 bool firewall_can_use_local_ports) { | 1047 bool firewall_can_use_local_ports) { |
| 1035 if (firewall_can_use_local_ports) | 1048 if (firewall_can_use_local_ports) |
| 1036 EnsureMdnsDiscoveryEnabled(); | 1049 EnsureMdnsDiscoveryEnabled(); |
| 1037 } | 1050 } |
| 1038 #endif | 1051 #endif |
| 1039 | 1052 |
| 1053 void MediaRouterMojoImpl::StartDiscovery() { | |
| 1054 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 1055 DVLOG_WITH_INSTANCE(1) << "StartDiscovery"; | |
| 1056 | |
| 1057 if (dial_media_sink_service_) | |
| 1058 return; | |
| 1059 | |
| 1060 auto* profile = Profile::FromBrowserContext(context_); | |
| 1061 if (!profile) | |
| 1062 return; | |
| 1063 | |
| 1064 dial_media_sink_service_ = | |
| 1065 new DialMediaSinkService(base::Bind(&MediaRouterMojoImpl::ProvideSinks, | |
| 1066 base::Unretained(this), "dial"), | |
| 1067 profile->GetRequestContext()); | |
| 1068 dial_media_sink_service_->Start(); | |
| 1069 } | |
| 1070 | |
| 1040 void MediaRouterMojoImpl::UpdateMediaSinks( | 1071 void MediaRouterMojoImpl::UpdateMediaSinks( |
| 1041 const MediaSource::Id& source_id) { | 1072 const MediaSource::Id& source_id) { |
| 1042 SetWakeReason(MediaRouteProviderWakeReason::UPDATE_MEDIA_SINKS); | 1073 SetWakeReason(MediaRouteProviderWakeReason::UPDATE_MEDIA_SINKS); |
| 1043 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoUpdateMediaSinks, | 1074 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoUpdateMediaSinks, |
| 1044 base::Unretained(this), source_id)); | 1075 base::Unretained(this), source_id)); |
| 1045 } | 1076 } |
| 1046 | 1077 |
| 1047 void MediaRouterMojoImpl::DoUpdateMediaSinks( | 1078 void MediaRouterMojoImpl::DoUpdateMediaSinks( |
| 1048 const MediaSource::Id& source_id) { | 1079 const MediaSource::Id& source_id) { |
| 1049 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks: " << source_id; | 1080 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks: " << source_id; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1065 | 1096 |
| 1066 void MediaRouterMojoImpl::OnMediaControllerCreated( | 1097 void MediaRouterMojoImpl::OnMediaControllerCreated( |
| 1067 const MediaRoute::Id& route_id, | 1098 const MediaRoute::Id& route_id, |
| 1068 bool success) { | 1099 bool success) { |
| 1069 // TODO(takumif): Record success/failure with UMA. | 1100 // TODO(takumif): Record success/failure with UMA. |
| 1070 DVLOG_WITH_INSTANCE(1) << "OnMediaControllerCreated: " << route_id | 1101 DVLOG_WITH_INSTANCE(1) << "OnMediaControllerCreated: " << route_id |
| 1071 << (success ? " was successful." : " failed."); | 1102 << (success ? " was successful." : " failed."); |
| 1072 } | 1103 } |
| 1073 | 1104 |
| 1074 } // namespace media_router | 1105 } // namespace media_router |
| OLD | NEW |