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/files/file_path.h" | |
| 11 #include "base/guid.h" | 12 #include "base/guid.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 14 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 16 #include "base/path_service.h" | |
| 15 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 16 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 19 #include "build/build_config.h" | |
| 17 #include "chrome/browser/media/router/issues_observer.h" | 20 #include "chrome/browser/media/router/issues_observer.h" |
| 18 #include "chrome/browser/media/router/media_router_factory.h" | 21 #include "chrome/browser/media/router/media_router_factory.h" |
| 19 #include "chrome/browser/media/router/media_router_metrics.h" | 22 #include "chrome/browser/media/router/media_router_metrics.h" |
| 20 #include "chrome/browser/media/router/media_router_type_converters.h" | 23 #include "chrome/browser/media/router/media_router_type_converters.h" |
| 21 #include "chrome/browser/media/router/media_routes_observer.h" | 24 #include "chrome/browser/media/router/media_routes_observer.h" |
| 22 #include "chrome/browser/media/router/media_sinks_observer.h" | 25 #include "chrome/browser/media/router/media_sinks_observer.h" |
| 23 #include "chrome/browser/media/router/presentation_session_messages_observer.h" | 26 #include "chrome/browser/media/router/presentation_session_messages_observer.h" |
| 24 #include "chrome/browser/sessions/session_tab_helper.h" | 27 #include "chrome/browser/sessions/session_tab_helper.h" |
| 28 #include "chrome/installer/util/browser_distribution.h" | |
| 29 #include "chrome/installer/util/firewall_manager_win.h" | |
| 25 #include "extensions/browser/process_manager.h" | 30 #include "extensions/browser/process_manager.h" |
| 26 | 31 |
| 32 | |
|
apacible
2016/03/23 22:04:45
nit: remove newline.
btolsch
2016/03/24 01:44:03
Done.
| |
| 27 #define DVLOG_WITH_INSTANCE(level) \ | 33 #define DVLOG_WITH_INSTANCE(level) \ |
| 28 DVLOG(level) << "MR #" << instance_id_ << ": " | 34 DVLOG(level) << "MR #" << instance_id_ << ": " |
| 29 | 35 |
| 30 #define DLOG_WITH_INSTANCE(level) DLOG(level) << "MR #" << instance_id_ << ": " | 36 #define DLOG_WITH_INSTANCE(level) DLOG(level) << "MR #" << instance_id_ << ": " |
| 31 | 37 |
| 32 namespace media_router { | 38 namespace media_router { |
| 33 | 39 |
| 34 using SinkAvailability = interfaces::MediaRouter::SinkAvailability; | 40 using SinkAvailability = interfaces::MediaRouter::SinkAvailability; |
| 35 | 41 |
| 36 namespace { | 42 namespace { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 MediaRouterMojoImpl::MediaSinksQuery::~MediaSinksQuery() = default; | 80 MediaRouterMojoImpl::MediaSinksQuery::~MediaSinksQuery() = default; |
| 75 | 81 |
| 76 MediaRouterMojoImpl::MediaRouterMojoImpl( | 82 MediaRouterMojoImpl::MediaRouterMojoImpl( |
| 77 extensions::EventPageTracker* event_page_tracker) | 83 extensions::EventPageTracker* event_page_tracker) |
| 78 : event_page_tracker_(event_page_tracker), | 84 : event_page_tracker_(event_page_tracker), |
| 79 instance_id_(base::GenerateGUID()), | 85 instance_id_(base::GenerateGUID()), |
| 80 availability_(interfaces::MediaRouter::SinkAvailability::UNAVAILABLE), | 86 availability_(interfaces::MediaRouter::SinkAvailability::UNAVAILABLE), |
| 81 current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT), | 87 current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT), |
| 82 weak_factory_(this) { | 88 weak_factory_(this) { |
| 83 DCHECK(event_page_tracker_); | 89 DCHECK(event_page_tracker_); |
| 90 #if defined(OS_WIN) | |
|
mark a. foltz
2016/03/24 00:04:41
Please put this into its own function in an anonym
btolsch
2016/03/24 01:44:03
Done.
| |
| 91 base::FilePath exe_path; | |
|
imcheng
2016/03/24 01:17:19
Ideally this check should happen in FILE thread, s
btolsch
2016/03/24 01:44:03
How do I run this from a file thread?
imcheng
2016/03/24 02:29:31
You can use BrowserThread::PostTask, see example h
btolsch
2016/03/24 21:32:26
Done but currently this is making tests on Windows
| |
| 92 if (base::PathService::Get(base::FILE_EXE, &exe_path)) { | |
| 93 auto firewall_manager = installer::FirewallManager::Create( | |
| 94 BrowserDistribution::GetDistribution(), exe_path); | |
| 95 if (firewall_manager) { | |
| 96 is_mdns_discovery_enabled_ = firewall_manager->CanUseLocalPorts(); | |
| 97 } | |
| 98 } | |
| 99 #endif | |
|
mark a. foltz
2016/03/24 00:04:41
What if !defined(OS_WIN)? Should we set the flag
btolsch
2016/03/24 01:44:03
If !defined(OS_WIN) then the extension will alread
| |
| 84 } | 100 } |
| 85 | 101 |
| 86 MediaRouterMojoImpl::~MediaRouterMojoImpl() { | 102 MediaRouterMojoImpl::~MediaRouterMojoImpl() { |
| 87 DCHECK(thread_checker_.CalledOnValidThread()); | 103 DCHECK(thread_checker_.CalledOnValidThread()); |
| 88 } | 104 } |
| 89 | 105 |
| 90 // static | 106 // static |
| 91 void MediaRouterMojoImpl::BindToRequest( | 107 void MediaRouterMojoImpl::BindToRequest( |
| 92 const extensions::Extension* extension, | 108 const extensions::Extension* extension, |
| 93 content::BrowserContext* context, | 109 content::BrowserContext* context, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 AttemptWakeEventPage(); | 166 AttemptWakeEventPage(); |
| 151 return; | 167 return; |
| 152 } | 168 } |
| 153 | 169 |
| 154 media_route_provider_ = std::move(media_route_provider_ptr); | 170 media_route_provider_ = std::move(media_route_provider_ptr); |
| 155 media_route_provider_.set_connection_error_handler(base::Bind( | 171 media_route_provider_.set_connection_error_handler(base::Bind( |
| 156 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); | 172 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); |
| 157 callback.Run(instance_id_); | 173 callback.Run(instance_id_); |
| 158 ExecutePendingRequests(); | 174 ExecutePendingRequests(); |
| 159 wakeup_attempt_count_ = 0; | 175 wakeup_attempt_count_ = 0; |
| 176 if (is_mdns_discovery_enabled_) { | |
|
mark a. foltz
2016/03/24 00:04:41
Did you mean !is_mdns_discovery_enabled_?
Nit: Re
imcheng
2016/03/24 01:17:19
I think this is correct. |is_mdns_discovery_enable
btolsch
2016/03/24 01:44:03
I think this (and the renaming) would be correct i
imcheng
2016/03/24 02:29:31
Actually, it does need to be reminded on every wak
| |
| 177 media_route_provider_->EnableMdnsDiscovery(); | |
|
imcheng
2016/03/24 01:17:19
Since we already enable mdns discovery on the exte
btolsch
2016/03/24 01:44:03
Yes, this could also be Windows-only. Done.
| |
| 178 } | |
| 160 } | 179 } |
| 161 | 180 |
| 162 void MediaRouterMojoImpl::OnIssue(const interfaces::IssuePtr issue) { | 181 void MediaRouterMojoImpl::OnIssue(const interfaces::IssuePtr issue) { |
| 163 DCHECK(thread_checker_.CalledOnValidThread()); | 182 DCHECK(thread_checker_.CalledOnValidThread()); |
| 164 DVLOG_WITH_INSTANCE(1) << "OnIssue " << issue->title; | 183 DVLOG_WITH_INSTANCE(1) << "OnIssue " << issue->title; |
| 165 const Issue& issue_converted = issue.To<Issue>(); | 184 const Issue& issue_converted = issue.To<Issue>(); |
| 166 issue_manager_.AddIssue(issue_converted); | 185 issue_manager_.AddIssue(issue_converted); |
| 167 } | 186 } |
| 168 | 187 |
| 169 void MediaRouterMojoImpl::OnSinksReceived( | 188 void MediaRouterMojoImpl::OnSinksReceived( |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 void MediaRouterMojoImpl::AddIssue(const Issue& issue) { | 414 void MediaRouterMojoImpl::AddIssue(const Issue& issue) { |
| 396 DCHECK(thread_checker_.CalledOnValidThread()); | 415 DCHECK(thread_checker_.CalledOnValidThread()); |
| 397 issue_manager_.AddIssue(issue); | 416 issue_manager_.AddIssue(issue); |
| 398 } | 417 } |
| 399 | 418 |
| 400 void MediaRouterMojoImpl::ClearIssue(const Issue::Id& issue_id) { | 419 void MediaRouterMojoImpl::ClearIssue(const Issue::Id& issue_id) { |
| 401 DCHECK(thread_checker_.CalledOnValidThread()); | 420 DCHECK(thread_checker_.CalledOnValidThread()); |
| 402 issue_manager_.ClearIssue(issue_id); | 421 issue_manager_.ClearIssue(issue_id); |
| 403 } | 422 } |
| 404 | 423 |
| 424 bool MediaRouterMojoImpl::is_mdns_discovery_enabled() const { | |
| 425 return is_mdns_discovery_enabled_; | |
| 426 } | |
| 427 | |
| 428 void MediaRouterMojoImpl::EnableMdnsDiscovery() { | |
| 429 if (media_route_provider_) { | |
|
mark a. foltz
2016/03/24 00:04:41
What if is_mdns_discovery_enabled_ is already true
btolsch
2016/03/24 01:44:03
I think I wrote this because the extension wasn't
btolsch
2016/03/24 21:32:26
Per Derek's comment about extension upgrade, this
| |
| 430 media_route_provider_->EnableMdnsDiscovery(); | |
| 431 } | |
| 432 is_mdns_discovery_enabled_ = true; | |
| 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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 924 if (current_wake_reason_ == MediaRouteProviderWakeReason::TOTAL_COUNT) | 954 if (current_wake_reason_ == MediaRouteProviderWakeReason::TOTAL_COUNT) |
| 925 current_wake_reason_ = reason; | 955 current_wake_reason_ = reason; |
| 926 } | 956 } |
| 927 | 957 |
| 928 void MediaRouterMojoImpl::ClearWakeReason() { | 958 void MediaRouterMojoImpl::ClearWakeReason() { |
| 929 DCHECK(current_wake_reason_ != MediaRouteProviderWakeReason::TOTAL_COUNT); | 959 DCHECK(current_wake_reason_ != MediaRouteProviderWakeReason::TOTAL_COUNT); |
| 930 current_wake_reason_ = MediaRouteProviderWakeReason::TOTAL_COUNT; | 960 current_wake_reason_ = MediaRouteProviderWakeReason::TOTAL_COUNT; |
| 931 } | 961 } |
| 932 | 962 |
| 933 } // namespace media_router | 963 } // namespace media_router |
| OLD | NEW |