| 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_pro
xy.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_router_feature.h" | 21 #include "chrome/browser/media/router/media_router_feature.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/mojo/media_route_controller.h" | 24 #include "chrome/browser/media/router/mojo/media_route_controller.h" |
| 24 #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" |
| 25 #include "chrome/browser/media/router/mojo/media_router_mojo_metrics.h" | 26 #include "chrome/browser/media/router/mojo/media_router_mojo_metrics.h" |
| 26 #include "chrome/browser/media/router/route_message_observer.h" | 27 #include "chrome/browser/media/router/route_message_observer.h" |
| 28 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/browser/sessions/session_tab_helper.h" | 29 #include "chrome/browser/sessions/session_tab_helper.h" |
| 28 #include "chrome/common/media_router/media_source_helper.h" | 30 #include "chrome/common/media_router/media_source_helper.h" |
| 29 #include "chrome/common/media_router/route_message.h" | 31 #include "chrome/common/media_router/route_message.h" |
| 30 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
| 31 #include "extensions/browser/process_manager.h" | 33 #include "extensions/browser/process_manager.h" |
| 32 | 34 |
| 33 #define DVLOG_WITH_INSTANCE(level) \ | 35 #define DVLOG_WITH_INSTANCE(level) \ |
| 34 DVLOG(level) << "MR #" << instance_id_ << ": " | 36 DVLOG(level) << "MR #" << instance_id_ << ": " |
| 35 | 37 |
| 36 #define DLOG_WITH_INSTANCE(level) DLOG(level) << "MR #" << instance_id_ << ": " | 38 #define DLOG_WITH_INSTANCE(level) DLOG(level) << "MR #" << instance_id_ << ": " |
| (...skipping 15 matching lines...) Expand all Loading... |
| 52 | 54 |
| 53 MediaRouterMojoImpl::MediaRoutesQuery::MediaRoutesQuery() = default; | 55 MediaRouterMojoImpl::MediaRoutesQuery::MediaRoutesQuery() = default; |
| 54 | 56 |
| 55 MediaRouterMojoImpl::MediaRoutesQuery::~MediaRoutesQuery() = default; | 57 MediaRouterMojoImpl::MediaRoutesQuery::~MediaRoutesQuery() = default; |
| 56 | 58 |
| 57 MediaRouterMojoImpl::MediaSinksQuery::MediaSinksQuery() = default; | 59 MediaRouterMojoImpl::MediaSinksQuery::MediaSinksQuery() = default; |
| 58 | 60 |
| 59 MediaRouterMojoImpl::MediaSinksQuery::~MediaSinksQuery() = default; | 61 MediaRouterMojoImpl::MediaSinksQuery::~MediaSinksQuery() = default; |
| 60 | 62 |
| 61 MediaRouterMojoImpl::MediaRouterMojoImpl( | 63 MediaRouterMojoImpl::MediaRouterMojoImpl( |
| 62 extensions::EventPageTracker* event_page_tracker) | 64 extensions::EventPageTracker* event_page_tracker, |
| 65 content::BrowserContext* context) |
| 63 : event_page_tracker_(event_page_tracker), | 66 : event_page_tracker_(event_page_tracker), |
| 64 instance_id_(base::GenerateGUID()), | 67 instance_id_(base::GenerateGUID()), |
| 65 availability_(mojom::MediaRouter::SinkAvailability::UNAVAILABLE), | 68 availability_(mojom::MediaRouter::SinkAvailability::UNAVAILABLE), |
| 66 current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT), | 69 current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT), |
| 70 context_(context), |
| 67 weak_factory_(this) { | 71 weak_factory_(this) { |
| 68 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 72 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 69 DCHECK(event_page_tracker_); | 73 DCHECK(event_page_tracker_); |
| 70 #if defined(OS_WIN) | 74 #if defined(OS_WIN) |
| 71 CanFirewallUseLocalPorts( | 75 CanFirewallUseLocalPorts( |
| 72 base::Bind(&MediaRouterMojoImpl::OnFirewallCheckComplete, | 76 base::Bind(&MediaRouterMojoImpl::OnFirewallCheckComplete, |
| 73 weak_factory_.GetWeakPtr())); | 77 weak_factory_.GetWeakPtr())); |
| 74 #endif | 78 #endif |
| 75 } | 79 } |
| 76 | 80 |
| 77 MediaRouterMojoImpl::~MediaRouterMojoImpl() { | 81 MediaRouterMojoImpl::~MediaRouterMojoImpl() { |
| 78 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 82 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 83 if (dial_media_sink_service_proxy_) |
| 84 dial_media_sink_service_proxy_->Stop(); |
| 79 } | 85 } |
| 80 | 86 |
| 81 // static | 87 // static |
| 82 void MediaRouterMojoImpl::BindToRequest( | 88 void MediaRouterMojoImpl::BindToRequest( |
| 83 const extensions::Extension* extension, | 89 const extensions::Extension* extension, |
| 84 content::BrowserContext* context, | 90 content::BrowserContext* context, |
| 85 const service_manager::BindSourceInfo& source_info, | 91 const service_manager::BindSourceInfo& source_info, |
| 86 mojom::MediaRouterRequest request) { | 92 mojom::MediaRouterRequest request) { |
| 87 MediaRouterMojoImpl* impl = static_cast<MediaRouterMojoImpl*>( | 93 MediaRouterMojoImpl* impl = static_cast<MediaRouterMojoImpl*>( |
| 88 MediaRouterFactory::GetApiForBrowserContext(context)); | 94 MediaRouterFactory::GetApiForBrowserContext(context)); |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 std::move(mojo_media_controller_request), | 430 std::move(mojo_media_controller_request), |
| 425 route_controller->BindObserverPtr())); | 431 route_controller->BindObserverPtr())); |
| 426 route_controllers_.emplace(route_id, route_controller.get()); | 432 route_controllers_.emplace(route_id, route_controller.get()); |
| 427 return route_controller; | 433 return route_controller; |
| 428 } | 434 } |
| 429 | 435 |
| 430 void MediaRouterMojoImpl::ProvideSinks( | 436 void MediaRouterMojoImpl::ProvideSinks( |
| 431 const std::string& provider_name, | 437 const std::string& provider_name, |
| 432 const std::vector<MediaSinkInternal>& sinks) { | 438 const std::vector<MediaSinkInternal>& sinks) { |
| 433 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 439 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 440 DVLOG_WITH_INSTANCE(1) << "OnDialMediaSinkDiscovered found " << sinks.size() |
| 441 << " devices..."; |
| 434 | 442 |
| 435 SetWakeReason(MediaRouteProviderWakeReason::PROVIDE_SINKS); | 443 SetWakeReason(MediaRouteProviderWakeReason::PROVIDE_SINKS); |
| 436 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoProvideSinks, | 444 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoProvideSinks, |
| 437 base::Unretained(this), provider_name, sinks)); | 445 base::Unretained(this), provider_name, sinks)); |
| 438 } | 446 } |
| 439 | 447 |
| 440 bool MediaRouterMojoImpl::RegisterMediaSinksObserver( | 448 bool MediaRouterMojoImpl::RegisterMediaSinksObserver( |
| 441 MediaSinksObserver* observer) { | 449 MediaSinksObserver* observer) { |
| 442 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 450 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 443 | 451 |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1063 } | 1071 } |
| 1064 } | 1072 } |
| 1065 | 1073 |
| 1066 void MediaRouterMojoImpl::OnFirewallCheckComplete( | 1074 void MediaRouterMojoImpl::OnFirewallCheckComplete( |
| 1067 bool firewall_can_use_local_ports) { | 1075 bool firewall_can_use_local_ports) { |
| 1068 if (firewall_can_use_local_ports) | 1076 if (firewall_can_use_local_ports) |
| 1069 EnsureMdnsDiscoveryEnabled(); | 1077 EnsureMdnsDiscoveryEnabled(); |
| 1070 } | 1078 } |
| 1071 #endif | 1079 #endif |
| 1072 | 1080 |
| 1081 void MediaRouterMojoImpl::StartDiscovery() { |
| 1082 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 1083 DVLOG_WITH_INSTANCE(1) << "StartDiscovery"; |
| 1084 |
| 1085 if (dial_media_sink_service_proxy_) |
| 1086 return; |
| 1087 |
| 1088 auto* profile = Profile::FromBrowserContext(context_); |
| 1089 if (!profile) |
| 1090 return; |
| 1091 |
| 1092 dial_media_sink_service_proxy_ = new DialMediaSinkServiceProxy( |
| 1093 base::Bind(&MediaRouterMojoImpl::ProvideSinks, base::Unretained(this), |
| 1094 "dial"), |
| 1095 profile->GetRequestContext()); |
| 1096 dial_media_sink_service_proxy_->Start(); |
| 1097 } |
| 1098 |
| 1073 void MediaRouterMojoImpl::UpdateMediaSinks( | 1099 void MediaRouterMojoImpl::UpdateMediaSinks( |
| 1074 const MediaSource::Id& source_id) { | 1100 const MediaSource::Id& source_id) { |
| 1075 SetWakeReason(MediaRouteProviderWakeReason::UPDATE_MEDIA_SINKS); | 1101 SetWakeReason(MediaRouteProviderWakeReason::UPDATE_MEDIA_SINKS); |
| 1076 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoUpdateMediaSinks, | 1102 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoUpdateMediaSinks, |
| 1077 base::Unretained(this), source_id)); | 1103 base::Unretained(this), source_id)); |
| 1078 } | 1104 } |
| 1079 | 1105 |
| 1080 void MediaRouterMojoImpl::DoUpdateMediaSinks( | 1106 void MediaRouterMojoImpl::DoUpdateMediaSinks( |
| 1081 const MediaSource::Id& source_id) { | 1107 const MediaSource::Id& source_id) { |
| 1082 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks: " << source_id; | 1108 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks: " << source_id; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1098 | 1124 |
| 1099 void MediaRouterMojoImpl::OnMediaControllerCreated( | 1125 void MediaRouterMojoImpl::OnMediaControllerCreated( |
| 1100 const MediaRoute::Id& route_id, | 1126 const MediaRoute::Id& route_id, |
| 1101 bool success) { | 1127 bool success) { |
| 1102 // TODO(takumif): Record success/failure with UMA. | 1128 // TODO(takumif): Record success/failure with UMA. |
| 1103 DVLOG_WITH_INSTANCE(1) << "OnMediaControllerCreated: " << route_id | 1129 DVLOG_WITH_INSTANCE(1) << "OnMediaControllerCreated: " << route_id |
| 1104 << (success ? " was successful." : " failed."); | 1130 << (success ? " was successful." : " failed."); |
| 1105 } | 1131 } |
| 1106 | 1132 |
| 1107 } // namespace media_router | 1133 } // namespace media_router |
| OLD | NEW |