| 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/media_router_mojo_impl.h" | 5 #include "chrome/browser/media/router/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" |
| 11 #include "base/guid.h" | 11 #include "base/guid.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "chrome/browser/media/router/issues_observer.h" | 17 #include "chrome/browser/media/router/issues_observer.h" |
| 18 #include "chrome/browser/media/router/media_route_provider_util_win.h" |
| 18 #include "chrome/browser/media/router/media_router_factory.h" | 19 #include "chrome/browser/media/router/media_router_factory.h" |
| 19 #include "chrome/browser/media/router/media_router_metrics.h" | 20 #include "chrome/browser/media/router/media_router_metrics.h" |
| 20 #include "chrome/browser/media/router/media_router_type_converters.h" | 21 #include "chrome/browser/media/router/media_router_type_converters.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/presentation_session_messages_observer.h" | 24 #include "chrome/browser/media/router/presentation_session_messages_observer.h" |
| 24 #include "chrome/browser/sessions/session_tab_helper.h" | 25 #include "chrome/browser/sessions/session_tab_helper.h" |
| 25 #include "extensions/browser/process_manager.h" | 26 #include "extensions/browser/process_manager.h" |
| 26 | 27 |
| 27 #define DVLOG_WITH_INSTANCE(level) \ | 28 #define DVLOG_WITH_INSTANCE(level) \ |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 76 |
| 76 MediaRouterMojoImpl::MediaRouterMojoImpl( | 77 MediaRouterMojoImpl::MediaRouterMojoImpl( |
| 77 extensions::EventPageTracker* event_page_tracker) | 78 extensions::EventPageTracker* event_page_tracker) |
| 78 : event_page_tracker_(event_page_tracker), | 79 : event_page_tracker_(event_page_tracker), |
| 79 instance_id_(base::GenerateGUID()), | 80 instance_id_(base::GenerateGUID()), |
| 80 availability_(interfaces::MediaRouter::SinkAvailability::UNAVAILABLE), | 81 availability_(interfaces::MediaRouter::SinkAvailability::UNAVAILABLE), |
| 81 wakeup_attempt_count_(0), | 82 wakeup_attempt_count_(0), |
| 82 current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT), | 83 current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT), |
| 83 weak_factory_(this) { | 84 weak_factory_(this) { |
| 84 DCHECK(event_page_tracker_); | 85 DCHECK(event_page_tracker_); |
| 86 #if defined(OS_WIN) |
| 87 CanFirewallUseLocalPorts( |
| 88 base::Bind(&MediaRouterMojoImpl::OnFirewallCheckComplete, |
| 89 weak_factory_.GetWeakPtr())); |
| 90 #endif |
| 85 } | 91 } |
| 86 | 92 |
| 87 MediaRouterMojoImpl::~MediaRouterMojoImpl() { | 93 MediaRouterMojoImpl::~MediaRouterMojoImpl() { |
| 88 DCHECK(thread_checker_.CalledOnValidThread()); | 94 DCHECK(thread_checker_.CalledOnValidThread()); |
| 89 } | 95 } |
| 90 | 96 |
| 91 // static | 97 // static |
| 92 void MediaRouterMojoImpl::BindToRequest( | 98 void MediaRouterMojoImpl::BindToRequest( |
| 93 const std::string& extension_id, | 99 const std::string& extension_id, |
| 94 content::BrowserContext* context, | 100 content::BrowserContext* context, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 AttemptWakeEventPage(); | 136 AttemptWakeEventPage(); |
| 131 } | 137 } |
| 132 } | 138 } |
| 133 | 139 |
| 134 void MediaRouterMojoImpl::RegisterMediaRouteProvider( | 140 void MediaRouterMojoImpl::RegisterMediaRouteProvider( |
| 135 interfaces::MediaRouteProviderPtr media_route_provider_ptr, | 141 interfaces::MediaRouteProviderPtr media_route_provider_ptr, |
| 136 const interfaces::MediaRouter::RegisterMediaRouteProviderCallback& | 142 const interfaces::MediaRouter::RegisterMediaRouteProviderCallback& |
| 137 callback) { | 143 callback) { |
| 138 DCHECK(thread_checker_.CalledOnValidThread()); | 144 DCHECK(thread_checker_.CalledOnValidThread()); |
| 139 | 145 |
| 146 #if defined(OS_WIN) |
| 147 // The MRPM may have been upgraded or otherwise reload such that we could be |
| 148 // seeing an MRPM that doesn't know mDNS is enabled, even if we've told a |
| 149 // previously registered MRPM it should be enabled. Furthermore, there may be |
| 150 // a pending request to enable mDNS, so don't clear this flag after |
| 151 // ExecutePendingRequests(). |
| 152 is_mdns_enabled_ = false; |
| 153 #endif |
| 140 if (event_page_tracker_->IsEventPageSuspended( | 154 if (event_page_tracker_->IsEventPageSuspended( |
| 141 media_route_provider_extension_id_)) { | 155 media_route_provider_extension_id_)) { |
| 142 DVLOG_WITH_INSTANCE(1) | 156 DVLOG_WITH_INSTANCE(1) |
| 143 << "RegisterMediaRouteProvider was called while extension is " | 157 << "RegisterMediaRouteProvider was called while extension is " |
| 144 "suspended."; | 158 "suspended."; |
| 145 media_route_provider_.reset(); | 159 media_route_provider_.reset(); |
| 146 SetWakeReason(MediaRouteProviderWakeReason::REGISTER_MEDIA_ROUTE_PROVIDER); | 160 SetWakeReason(MediaRouteProviderWakeReason::REGISTER_MEDIA_ROUTE_PROVIDER); |
| 147 AttemptWakeEventPage(); | 161 AttemptWakeEventPage(); |
| 148 return; | 162 return; |
| 149 } | 163 } |
| 150 | 164 |
| 151 media_route_provider_ = std::move(media_route_provider_ptr); | 165 media_route_provider_ = std::move(media_route_provider_ptr); |
| 152 media_route_provider_.set_connection_error_handler(base::Bind( | 166 media_route_provider_.set_connection_error_handler(base::Bind( |
| 153 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); | 167 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); |
| 154 callback.Run(instance_id_); | 168 callback.Run(instance_id_); |
| 155 ExecutePendingRequests(); | 169 ExecutePendingRequests(); |
| 156 wakeup_attempt_count_ = 0; | 170 wakeup_attempt_count_ = 0; |
| 171 #if defined(OS_WIN) |
| 172 // The MRPM extension already turns on mDNS discovery for platforms other than |
| 173 // Windows. It only relies on this signalling from MR on Windows to avoid |
| 174 // triggering a firewall prompt out of the context of MR from the user's |
| 175 // perspective. This particular call reminds the extension to enable mDNS |
| 176 // discovery when it wakes up, has been upgraded, etc. |
| 177 if (should_enable_mdns_discovery_) { |
| 178 DoEnsureMdnsDiscoveryEnabled(); |
| 179 } |
| 180 #endif |
| 157 } | 181 } |
| 158 | 182 |
| 159 void MediaRouterMojoImpl::OnIssue(const interfaces::IssuePtr issue) { | 183 void MediaRouterMojoImpl::OnIssue(const interfaces::IssuePtr issue) { |
| 160 DCHECK(thread_checker_.CalledOnValidThread()); | 184 DCHECK(thread_checker_.CalledOnValidThread()); |
| 161 DVLOG_WITH_INSTANCE(1) << "OnIssue " << issue->title; | 185 DVLOG_WITH_INSTANCE(1) << "OnIssue " << issue->title; |
| 162 const Issue& issue_converted = issue.To<Issue>(); | 186 const Issue& issue_converted = issue.To<Issue>(); |
| 163 issue_manager_.AddIssue(issue_converted); | 187 issue_manager_.AddIssue(issue_converted); |
| 164 } | 188 } |
| 165 | 189 |
| 166 void MediaRouterMojoImpl::OnSinksReceived( | 190 void MediaRouterMojoImpl::OnSinksReceived( |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 void MediaRouterMojoImpl::AddIssue(const Issue& issue) { | 407 void MediaRouterMojoImpl::AddIssue(const Issue& issue) { |
| 384 DCHECK(thread_checker_.CalledOnValidThread()); | 408 DCHECK(thread_checker_.CalledOnValidThread()); |
| 385 issue_manager_.AddIssue(issue); | 409 issue_manager_.AddIssue(issue); |
| 386 } | 410 } |
| 387 | 411 |
| 388 void MediaRouterMojoImpl::ClearIssue(const Issue::Id& issue_id) { | 412 void MediaRouterMojoImpl::ClearIssue(const Issue::Id& issue_id) { |
| 389 DCHECK(thread_checker_.CalledOnValidThread()); | 413 DCHECK(thread_checker_.CalledOnValidThread()); |
| 390 issue_manager_.ClearIssue(issue_id); | 414 issue_manager_.ClearIssue(issue_id); |
| 391 } | 415 } |
| 392 | 416 |
| 417 void MediaRouterMojoImpl::OnUserGesture() { |
| 418 #if defined(OS_WIN) |
| 419 EnsureMdnsDiscoveryEnabled(); |
| 420 #endif |
| 421 } |
| 422 |
| 393 bool MediaRouterMojoImpl::RegisterMediaSinksObserver( | 423 bool MediaRouterMojoImpl::RegisterMediaSinksObserver( |
| 394 MediaSinksObserver* observer) { | 424 MediaSinksObserver* observer) { |
| 395 DCHECK(thread_checker_.CalledOnValidThread()); | 425 DCHECK(thread_checker_.CalledOnValidThread()); |
| 396 | 426 |
| 397 // Create an observer list for the media source and add |observer| | 427 // Create an observer list for the media source and add |observer| |
| 398 // to it. Fail if |observer| is already registered. | 428 // to it. Fail if |observer| is already registered. |
| 399 const std::string& source_id = observer->source().id(); | 429 const std::string& source_id = observer->source().id(); |
| 400 auto* sinks_query = sinks_queries_.get(source_id); | 430 auto* sinks_query = sinks_queries_.get(source_id); |
| 401 bool new_query = false; | 431 bool new_query = false; |
| 402 if (!sinks_query) { | 432 if (!sinks_query) { |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 DCHECK(reason != MediaRouteProviderWakeReason::TOTAL_COUNT); | 932 DCHECK(reason != MediaRouteProviderWakeReason::TOTAL_COUNT); |
| 903 if (current_wake_reason_ == MediaRouteProviderWakeReason::TOTAL_COUNT) | 933 if (current_wake_reason_ == MediaRouteProviderWakeReason::TOTAL_COUNT) |
| 904 current_wake_reason_ = reason; | 934 current_wake_reason_ = reason; |
| 905 } | 935 } |
| 906 | 936 |
| 907 void MediaRouterMojoImpl::ClearWakeReason() { | 937 void MediaRouterMojoImpl::ClearWakeReason() { |
| 908 DCHECK(current_wake_reason_ != MediaRouteProviderWakeReason::TOTAL_COUNT); | 938 DCHECK(current_wake_reason_ != MediaRouteProviderWakeReason::TOTAL_COUNT); |
| 909 current_wake_reason_ = MediaRouteProviderWakeReason::TOTAL_COUNT; | 939 current_wake_reason_ = MediaRouteProviderWakeReason::TOTAL_COUNT; |
| 910 } | 940 } |
| 911 | 941 |
| 942 #if defined(OS_WIN) |
| 943 void MediaRouterMojoImpl::EnsureMdnsDiscoveryEnabled() { |
| 944 if (is_mdns_enabled_) |
| 945 return; |
| 946 |
| 947 SetWakeReason(MediaRouteProviderWakeReason::ENABLE_MDNS_DISCOVERY); |
| 948 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoEnsureMdnsDiscoveryEnabled, |
| 949 base::Unretained(this))); |
| 950 should_enable_mdns_discovery_ = true; |
| 951 } |
| 952 |
| 953 void MediaRouterMojoImpl::DoEnsureMdnsDiscoveryEnabled() { |
| 954 DVLOG_WITH_INSTANCE(1) << "DoEnsureMdnsDiscoveryEnabled"; |
| 955 if (!is_mdns_enabled_) { |
| 956 media_route_provider_->EnableMdnsDiscovery(); |
| 957 is_mdns_enabled_ = true; |
| 958 } |
| 959 } |
| 960 |
| 961 void MediaRouterMojoImpl::OnFirewallCheckComplete( |
| 962 bool firewall_can_use_local_ports) { |
| 963 if (firewall_can_use_local_ports) |
| 964 EnsureMdnsDiscoveryEnabled(); |
| 965 } |
| 966 #endif |
| 967 |
| 912 } // namespace media_router | 968 } // namespace media_router |
| OLD | NEW |