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/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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 MediaRouterMojoImpl::MediaSinksQuery::~MediaSinksQuery() = default; | 75 MediaRouterMojoImpl::MediaSinksQuery::~MediaSinksQuery() = default; |
| 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 current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT), | 82 current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT), |
| 82 weak_factory_(this) { | 83 weak_factory_(this) { |
| 83 DCHECK(event_page_tracker_); | 84 DCHECK(event_page_tracker_); |
| 85 #if defined(OS_WIN) | |
| 86 CanFirewallUseLocalPorts( | |
| 87 base::Bind(&MediaRouterMojoImpl::EnableMdnsFromFirewallCheck, | |
| 88 weak_factory_.GetWeakPtr())); | |
| 89 #endif | |
| 84 } | 90 } |
| 85 | 91 |
| 86 MediaRouterMojoImpl::~MediaRouterMojoImpl() { | 92 MediaRouterMojoImpl::~MediaRouterMojoImpl() { |
| 87 DCHECK(thread_checker_.CalledOnValidThread()); | 93 DCHECK(thread_checker_.CalledOnValidThread()); |
| 88 } | 94 } |
| 89 | 95 |
| 90 // static | 96 // static |
| 91 void MediaRouterMojoImpl::BindToRequest( | 97 void MediaRouterMojoImpl::BindToRequest( |
| 92 const extensions::Extension* extension, | 98 const extensions::Extension* extension, |
| 93 content::BrowserContext* context, | 99 content::BrowserContext* context, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 AttemptWakeEventPage(); | 139 AttemptWakeEventPage(); |
| 134 } | 140 } |
| 135 } | 141 } |
| 136 | 142 |
| 137 void MediaRouterMojoImpl::RegisterMediaRouteProvider( | 143 void MediaRouterMojoImpl::RegisterMediaRouteProvider( |
| 138 interfaces::MediaRouteProviderPtr media_route_provider_ptr, | 144 interfaces::MediaRouteProviderPtr media_route_provider_ptr, |
| 139 const interfaces::MediaRouter::RegisterMediaRouteProviderCallback& | 145 const interfaces::MediaRouter::RegisterMediaRouteProviderCallback& |
| 140 callback) { | 146 callback) { |
| 141 DCHECK(thread_checker_.CalledOnValidThread()); | 147 DCHECK(thread_checker_.CalledOnValidThread()); |
| 142 | 148 |
| 149 #if defined(OS_WIN) | |
| 150 // The MRPM may have been upgraded or otherwise reload such that we could be | |
| 151 // seeing an MRPM that doesn't know mDNS is enabled, even if we've told a | |
| 152 // previously registered MRPM it should be enabled. Furthermore, there may be | |
| 153 // a pending request to enable mDNS, so don't clear this flag after | |
| 154 // ExecutePendingRequests(). | |
| 155 is_mdns_enabled_ = false; | |
| 156 #endif | |
| 143 if (event_page_tracker_->IsEventPageSuspended( | 157 if (event_page_tracker_->IsEventPageSuspended( |
| 144 media_route_provider_extension_id_)) { | 158 media_route_provider_extension_id_)) { |
| 145 DVLOG_WITH_INSTANCE(1) | 159 DVLOG_WITH_INSTANCE(1) |
| 146 << "RegisterMediaRouteProvider was called while extension is " | 160 << "RegisterMediaRouteProvider was called while extension is " |
| 147 "suspended."; | 161 "suspended."; |
| 148 media_route_provider_.reset(); | 162 media_route_provider_.reset(); |
| 149 SetWakeReason(MediaRouteProviderWakeReason::REGISTER_MEDIA_ROUTE_PROVIDER); | 163 SetWakeReason(MediaRouteProviderWakeReason::REGISTER_MEDIA_ROUTE_PROVIDER); |
| 150 AttemptWakeEventPage(); | 164 AttemptWakeEventPage(); |
| 151 return; | 165 return; |
| 152 } | 166 } |
| 153 | 167 |
| 154 media_route_provider_ = std::move(media_route_provider_ptr); | 168 media_route_provider_ = std::move(media_route_provider_ptr); |
| 155 media_route_provider_.set_connection_error_handler(base::Bind( | 169 media_route_provider_.set_connection_error_handler(base::Bind( |
| 156 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); | 170 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); |
| 157 callback.Run(instance_id_); | 171 callback.Run(instance_id_); |
| 158 ExecutePendingRequests(); | 172 ExecutePendingRequests(); |
| 159 wakeup_attempt_count_ = 0; | 173 wakeup_attempt_count_ = 0; |
| 174 #if defined(OS_WIN) | |
| 175 // The MRPM extension already turns on mDNS discovery for platforms other than | |
| 176 // Windows. It only relies on this signalling from MR on Windows to avoid | |
| 177 // triggering a firewall prompt out of the context of MR from the user's | |
| 178 // perspective. This particular call reminds the extension to enable mDNS | |
| 179 // discovery when it wakes up, has been upgraded, etc. | |
| 180 if (should_enable_mdns_discovery_) { | |
| 181 DoEnsureMdnsDiscoveryEnabled(); | |
| 182 } | |
| 183 #endif | |
| 160 } | 184 } |
| 161 | 185 |
| 162 void MediaRouterMojoImpl::OnIssue(const interfaces::IssuePtr issue) { | 186 void MediaRouterMojoImpl::OnIssue(const interfaces::IssuePtr issue) { |
| 163 DCHECK(thread_checker_.CalledOnValidThread()); | 187 DCHECK(thread_checker_.CalledOnValidThread()); |
| 164 DVLOG_WITH_INSTANCE(1) << "OnIssue " << issue->title; | 188 DVLOG_WITH_INSTANCE(1) << "OnIssue " << issue->title; |
| 165 const Issue& issue_converted = issue.To<Issue>(); | 189 const Issue& issue_converted = issue.To<Issue>(); |
| 166 issue_manager_.AddIssue(issue_converted); | 190 issue_manager_.AddIssue(issue_converted); |
| 167 } | 191 } |
| 168 | 192 |
| 169 void MediaRouterMojoImpl::OnSinksReceived( | 193 void MediaRouterMojoImpl::OnSinksReceived( |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 void MediaRouterMojoImpl::AddIssue(const Issue& issue) { | 419 void MediaRouterMojoImpl::AddIssue(const Issue& issue) { |
| 396 DCHECK(thread_checker_.CalledOnValidThread()); | 420 DCHECK(thread_checker_.CalledOnValidThread()); |
| 397 issue_manager_.AddIssue(issue); | 421 issue_manager_.AddIssue(issue); |
| 398 } | 422 } |
| 399 | 423 |
| 400 void MediaRouterMojoImpl::ClearIssue(const Issue::Id& issue_id) { | 424 void MediaRouterMojoImpl::ClearIssue(const Issue::Id& issue_id) { |
| 401 DCHECK(thread_checker_.CalledOnValidThread()); | 425 DCHECK(thread_checker_.CalledOnValidThread()); |
| 402 issue_manager_.ClearIssue(issue_id); | 426 issue_manager_.ClearIssue(issue_id); |
| 403 } | 427 } |
| 404 | 428 |
| 429 void MediaRouterMojoImpl::OnUserInteraction() { | |
| 430 #if defined(OS_WIN) | |
| 431 EnsureMdnsDiscoveryEnabled(); | |
| 432 #endif | |
| 433 } | |
| 434 | |
| 405 bool MediaRouterMojoImpl::RegisterMediaSinksObserver( | 435 bool MediaRouterMojoImpl::RegisterMediaSinksObserver( |
| 406 MediaSinksObserver* observer) { | 436 MediaSinksObserver* observer) { |
| 407 DCHECK(thread_checker_.CalledOnValidThread()); | 437 DCHECK(thread_checker_.CalledOnValidThread()); |
| 408 | 438 |
| 409 // Create an observer list for the media source and add |observer| | 439 // Create an observer list for the media source and add |observer| |
| 410 // to it. Fail if |observer| is already registered. | 440 // to it. Fail if |observer| is already registered. |
| 411 const std::string& source_id = observer->source().id(); | 441 const std::string& source_id = observer->source().id(); |
| 412 auto* sinks_query = sinks_queries_.get(source_id); | 442 auto* sinks_query = sinks_queries_.get(source_id); |
| 413 bool new_query = false; | 443 bool new_query = false; |
| 414 if (!sinks_query) { | 444 if (!sinks_query) { |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 816 if (!routes_query || !routes_query->is_active || | 846 if (!routes_query || !routes_query->is_active || |
| 817 routes_query->observers.might_have_observers()) { | 847 routes_query->observers.might_have_observers()) { |
| 818 return; | 848 return; |
| 819 } | 849 } |
| 820 | 850 |
| 821 DVLOG_WITH_INSTANCE(1) << "MRPM.StopObservingMediaRoutes: " << source_id; | 851 DVLOG_WITH_INSTANCE(1) << "MRPM.StopObservingMediaRoutes: " << source_id; |
| 822 media_route_provider_->StopObservingMediaRoutes(source_id); | 852 media_route_provider_->StopObservingMediaRoutes(source_id); |
| 823 routes_queries_.erase(source_id); | 853 routes_queries_.erase(source_id); |
| 824 } | 854 } |
| 825 | 855 |
| 856 void MediaRouterMojoImpl::EnsureMdnsDiscoveryEnabled() { | |
|
mark a. foltz
2016/03/29 00:48:20
This code should only be called on Windows, so I h
| |
| 857 if (is_mdns_enabled_) | |
| 858 return; | |
| 859 | |
| 860 SetWakeReason(MediaRouteProviderWakeReason::ENABLE_MDNS_DISCOVERY); | |
| 861 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoEnsureMdnsDiscoveryEnabled, | |
| 862 base::Unretained(this))); | |
| 863 should_enable_mdns_discovery_ = true; | |
| 864 } | |
| 865 | |
| 866 void MediaRouterMojoImpl::DoEnsureMdnsDiscoveryEnabled() { | |
| 867 DVLOG_WITH_INSTANCE(1) << "DoEnsureMdnsDiscoveryEnabled"; | |
| 868 if (!is_mdns_enabled_) { | |
| 869 media_route_provider_->EnableMdnsDiscovery(); | |
| 870 is_mdns_enabled_ = true; | |
| 871 } | |
| 872 } | |
| 873 | |
| 826 void MediaRouterMojoImpl::EnqueueTask(const base::Closure& closure) { | 874 void MediaRouterMojoImpl::EnqueueTask(const base::Closure& closure) { |
| 827 pending_requests_.push_back(closure); | 875 pending_requests_.push_back(closure); |
| 828 if (pending_requests_.size() > kMaxPendingRequests) { | 876 if (pending_requests_.size() > kMaxPendingRequests) { |
| 829 DLOG_WITH_INSTANCE(ERROR) << "Reached max queue size. Dropping oldest " | 877 DLOG_WITH_INSTANCE(ERROR) << "Reached max queue size. Dropping oldest " |
| 830 << "request."; | 878 << "request."; |
| 831 pending_requests_.pop_front(); | 879 pending_requests_.pop_front(); |
| 832 } | 880 } |
| 833 DVLOG_WITH_INSTANCE(2) << "EnqueueTask (queue-length=" | 881 DVLOG_WITH_INSTANCE(2) << "EnqueueTask (queue-length=" |
| 834 << pending_requests_.size() << ")"; | 882 << pending_requests_.size() << ")"; |
| 835 } | 883 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 923 DCHECK(reason != MediaRouteProviderWakeReason::TOTAL_COUNT); | 971 DCHECK(reason != MediaRouteProviderWakeReason::TOTAL_COUNT); |
| 924 if (current_wake_reason_ == MediaRouteProviderWakeReason::TOTAL_COUNT) | 972 if (current_wake_reason_ == MediaRouteProviderWakeReason::TOTAL_COUNT) |
| 925 current_wake_reason_ = reason; | 973 current_wake_reason_ = reason; |
| 926 } | 974 } |
| 927 | 975 |
| 928 void MediaRouterMojoImpl::ClearWakeReason() { | 976 void MediaRouterMojoImpl::ClearWakeReason() { |
| 929 DCHECK(current_wake_reason_ != MediaRouteProviderWakeReason::TOTAL_COUNT); | 977 DCHECK(current_wake_reason_ != MediaRouteProviderWakeReason::TOTAL_COUNT); |
| 930 current_wake_reason_ = MediaRouteProviderWakeReason::TOTAL_COUNT; | 978 current_wake_reason_ = MediaRouteProviderWakeReason::TOTAL_COUNT; |
| 931 } | 979 } |
| 932 | 980 |
| 981 void MediaRouterMojoImpl::EnableMdnsFromFirewallCheck( | |
| 982 bool firewall_can_use_local_ports) { | |
| 983 if (firewall_can_use_local_ports) | |
| 984 EnsureMdnsDiscoveryEnabled(); | |
| 985 } | |
| 986 | |
| 933 } // namespace media_router | 987 } // namespace media_router |
| OLD | NEW |