Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: chrome/browser/media/router/mojo/media_router_mojo_impl.cc

Issue 2837363002: [Media Router] Use DialMediaSinkService in MediaRouterMojoImpl (Closed)
Patch Set: fix windows unit tests failures Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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),
69 context_(context),
66 weak_factory_(this) { 70 weak_factory_(this) {
67 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 71 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
68 DCHECK(event_page_tracker_); 72 DCHECK(event_page_tracker_);
69 #if defined(OS_WIN) 73 #if defined(OS_WIN)
70 CanFirewallUseLocalPorts( 74 CanFirewallUseLocalPorts(
71 base::Bind(&MediaRouterMojoImpl::OnFirewallCheckComplete, 75 base::Bind(&MediaRouterMojoImpl::OnFirewallCheckComplete,
72 weak_factory_.GetWeakPtr())); 76 weak_factory_.GetWeakPtr()));
73 #endif 77 #endif
74 } 78 }
75 79
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 "suspended."; 149 "suspended.";
146 media_route_provider_.reset(); 150 media_route_provider_.reset();
147 SetWakeReason(MediaRouteProviderWakeReason::REGISTER_MEDIA_ROUTE_PROVIDER); 151 SetWakeReason(MediaRouteProviderWakeReason::REGISTER_MEDIA_ROUTE_PROVIDER);
148 AttemptWakeEventPage(); 152 AttemptWakeEventPage();
149 return; 153 return;
150 } 154 }
151 155
152 media_route_provider_ = std::move(media_route_provider_ptr); 156 media_route_provider_ = std::move(media_route_provider_ptr);
153 media_route_provider_.set_connection_error_handler(base::Bind( 157 media_route_provider_.set_connection_error_handler(base::Bind(
154 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); 158 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this)));
155 callback.Run(instance_id_); 159
160 auto config = mojom::MediaRouteProviderConfig::New();
161 config->enable_dial_discovery = !media_router::DialLocalDiscoveryEnabled();
162 config->enable_cast_discovery = !media_router::CastDiscoveryEnabled();
163 callback.Run(instance_id_, std::move(config));
156 ExecutePendingRequests(); 164 ExecutePendingRequests();
157 SyncStateToMediaRouteProvider(); 165 SyncStateToMediaRouteProvider();
158 166
159 wakeup_attempt_count_ = 0; 167 wakeup_attempt_count_ = 0;
160 } 168 }
161 169
162 void MediaRouterMojoImpl::OnIssue(const IssueInfo& issue) { 170 void MediaRouterMojoImpl::OnIssue(const IssueInfo& issue) {
163 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 171 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
164 DVLOG_WITH_INSTANCE(1) << "OnIssue " << issue.title; 172 DVLOG_WITH_INSTANCE(1) << "OnIssue " << issue.title;
165 issue_manager_.AddIssue(issue); 173 issue_manager_.AddIssue(issue);
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 std::move(mojo_media_controller_request), 424 std::move(mojo_media_controller_request),
417 route_controller->BindObserverPtr())); 425 route_controller->BindObserverPtr()));
418 route_controllers_.emplace(route_id, route_controller.get()); 426 route_controllers_.emplace(route_id, route_controller.get());
419 return route_controller; 427 return route_controller;
420 } 428 }
421 429
422 void MediaRouterMojoImpl::ProvideSinks( 430 void MediaRouterMojoImpl::ProvideSinks(
423 const std::string& provider_name, 431 const std::string& provider_name,
424 const std::vector<MediaSinkInternal>& sinks) { 432 const std::vector<MediaSinkInternal>& sinks) {
425 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 433 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
434 DVLOG_WITH_INSTANCE(1) << "OnDialMediaSinkDiscovered found " << sinks.size()
435 << " devices...";
426 436
427 SetWakeReason(MediaRouteProviderWakeReason::PROVIDE_SINKS); 437 SetWakeReason(MediaRouteProviderWakeReason::PROVIDE_SINKS);
428 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoProvideSinks, 438 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoProvideSinks,
429 base::Unretained(this), provider_name, sinks)); 439 base::Unretained(this), provider_name, sinks));
430 } 440 }
431 441
432 bool MediaRouterMojoImpl::RegisterMediaSinksObserver( 442 bool MediaRouterMojoImpl::RegisterMediaSinksObserver(
433 MediaSinksObserver* observer) { 443 MediaSinksObserver* observer) {
434 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 444 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
435 445
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 #if defined(OS_WIN) 1000 #if defined(OS_WIN)
991 // The MRPM extension already turns on mDNS discovery for platforms other than 1001 // The MRPM extension already turns on mDNS discovery for platforms other than
992 // Windows. It only relies on this signalling from MR on Windows to avoid 1002 // Windows. It only relies on this signalling from MR on Windows to avoid
993 // triggering a firewall prompt out of the context of MR from the user's 1003 // triggering a firewall prompt out of the context of MR from the user's
994 // perspective. This particular call reminds the extension to enable mDNS 1004 // perspective. This particular call reminds the extension to enable mDNS
995 // discovery when it wakes up, has been upgraded, etc. 1005 // discovery when it wakes up, has been upgraded, etc.
996 if (should_enable_mdns_discovery_) { 1006 if (should_enable_mdns_discovery_) {
997 DoEnsureMdnsDiscoveryEnabled(); 1007 DoEnsureMdnsDiscoveryEnabled();
998 } 1008 }
999 #endif 1009 #endif
1010
1011 if (media_router::DialLocalDiscoveryEnabled())
1012 StartDiscovery();
1000 } 1013 }
1001 1014
1002 void MediaRouterMojoImpl::EventPageWakeComplete(bool success) { 1015 void MediaRouterMojoImpl::EventPageWakeComplete(bool success) {
1003 if (success) { 1016 if (success) {
1004 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeReason( 1017 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeReason(
1005 current_wake_reason_); 1018 current_wake_reason_);
1006 ClearWakeReason(); 1019 ClearWakeReason();
1007 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeup( 1020 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeup(
1008 MediaRouteProviderWakeup::SUCCESS); 1021 MediaRouteProviderWakeup::SUCCESS);
1009 return; 1022 return;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 } 1068 }
1056 } 1069 }
1057 1070
1058 void MediaRouterMojoImpl::OnFirewallCheckComplete( 1071 void MediaRouterMojoImpl::OnFirewallCheckComplete(
1059 bool firewall_can_use_local_ports) { 1072 bool firewall_can_use_local_ports) {
1060 if (firewall_can_use_local_ports) 1073 if (firewall_can_use_local_ports)
1061 EnsureMdnsDiscoveryEnabled(); 1074 EnsureMdnsDiscoveryEnabled();
1062 } 1075 }
1063 #endif 1076 #endif
1064 1077
1078 void MediaRouterMojoImpl::StartDiscovery() {
1079 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
1080 DVLOG_WITH_INSTANCE(1) << "StartDiscovery";
1081
1082 if (dial_media_sink_service_)
1083 return;
1084
1085 auto* profile = Profile::FromBrowserContext(context_);
1086 if (!profile)
1087 return;
1088
1089 dial_media_sink_service_ =
1090 new DialMediaSinkService(base::Bind(&MediaRouterMojoImpl::ProvideSinks,
1091 base::Unretained(this), "dial"),
Kevin M 2017/05/09 17:32:06 Are there potential lifetime issues in giving an r
zhaobin 2017/05/10 18:17:34 Done.
1092 profile->GetRequestContext());
1093 dial_media_sink_service_->Start();
1094 }
1095
1065 void MediaRouterMojoImpl::UpdateMediaSinks( 1096 void MediaRouterMojoImpl::UpdateMediaSinks(
1066 const MediaSource::Id& source_id) { 1097 const MediaSource::Id& source_id) {
1067 SetWakeReason(MediaRouteProviderWakeReason::UPDATE_MEDIA_SINKS); 1098 SetWakeReason(MediaRouteProviderWakeReason::UPDATE_MEDIA_SINKS);
1068 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoUpdateMediaSinks, 1099 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoUpdateMediaSinks,
1069 base::Unretained(this), source_id)); 1100 base::Unretained(this), source_id));
1070 } 1101 }
1071 1102
1072 void MediaRouterMojoImpl::DoUpdateMediaSinks( 1103 void MediaRouterMojoImpl::DoUpdateMediaSinks(
1073 const MediaSource::Id& source_id) { 1104 const MediaSource::Id& source_id) {
1074 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks: " << source_id; 1105 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks: " << source_id;
(...skipping 15 matching lines...) Expand all
1090 1121
1091 void MediaRouterMojoImpl::OnMediaControllerCreated( 1122 void MediaRouterMojoImpl::OnMediaControllerCreated(
1092 const MediaRoute::Id& route_id, 1123 const MediaRoute::Id& route_id,
1093 bool success) { 1124 bool success) {
1094 // TODO(takumif): Record success/failure with UMA. 1125 // TODO(takumif): Record success/failure with UMA.
1095 DVLOG_WITH_INSTANCE(1) << "OnMediaControllerCreated: " << route_id 1126 DVLOG_WITH_INSTANCE(1) << "OnMediaControllerCreated: " << route_id
1096 << (success ? " was successful." : " failed."); 1127 << (success ? " was successful." : " failed.");
1097 } 1128 }
1098 1129
1099 } // namespace media_router 1130 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698