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_del
egate.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_routes_observer.h" | 21 #include "chrome/browser/media/router/media_routes_observer.h" |
21 #include "chrome/browser/media/router/media_sinks_observer.h" | 22 #include "chrome/browser/media/router/media_sinks_observer.h" |
22 #include "chrome/browser/media/router/mojo/media_route_controller.h" | 23 #include "chrome/browser/media/router/mojo/media_route_controller.h" |
23 #include "chrome/browser/media/router/mojo/media_route_provider_util_win.h" | 24 #include "chrome/browser/media/router/mojo/media_route_provider_util_win.h" |
24 #include "chrome/browser/media/router/mojo/media_router_mojo_metrics.h" | 25 #include "chrome/browser/media/router/mojo/media_router_mojo_metrics.h" |
25 #include "chrome/browser/media/router/route_message_observer.h" | 26 #include "chrome/browser/media/router/route_message_observer.h" |
| 27 #include "chrome/browser/profiles/profile.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" |
30 #include "extensions/browser/process_manager.h" | 32 #include "extensions/browser/process_manager.h" |
31 | 33 |
32 #define DVLOG_WITH_INSTANCE(level) \ | 34 #define DVLOG_WITH_INSTANCE(level) \ |
33 DVLOG(level) << "MR #" << instance_id_ << ": " | 35 DVLOG(level) << "MR #" << instance_id_ << ": " |
34 | 36 |
35 #define DLOG_WITH_INSTANCE(level) DLOG(level) << "MR #" << instance_id_ << ": " | 37 #define DLOG_WITH_INSTANCE(level) DLOG(level) << "MR #" << instance_id_ << ": " |
(...skipping 15 matching lines...) Expand all Loading... |
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 |
76 MediaRouterMojoImpl::~MediaRouterMojoImpl() { | 80 MediaRouterMojoImpl::~MediaRouterMojoImpl() { |
77 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 81 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 82 if (dial_media_sink_service_delegate_) |
| 83 dial_media_sink_service_delegate_->Stop(); |
78 } | 84 } |
79 | 85 |
80 // static | 86 // static |
81 void MediaRouterMojoImpl::BindToRequest( | 87 void MediaRouterMojoImpl::BindToRequest( |
82 const extensions::Extension* extension, | 88 const extensions::Extension* extension, |
83 content::BrowserContext* context, | 89 content::BrowserContext* context, |
84 const service_manager::BindSourceInfo& source_info, | 90 const service_manager::BindSourceInfo& source_info, |
85 mojom::MediaRouterRequest request) { | 91 mojom::MediaRouterRequest request) { |
86 MediaRouterMojoImpl* impl = static_cast<MediaRouterMojoImpl*>( | 92 MediaRouterMojoImpl* impl = static_cast<MediaRouterMojoImpl*>( |
87 MediaRouterFactory::GetApiForBrowserContext(context)); | 93 MediaRouterFactory::GetApiForBrowserContext(context)); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 "suspended."; | 151 "suspended."; |
146 media_route_provider_.reset(); | 152 media_route_provider_.reset(); |
147 SetWakeReason(MediaRouteProviderWakeReason::REGISTER_MEDIA_ROUTE_PROVIDER); | 153 SetWakeReason(MediaRouteProviderWakeReason::REGISTER_MEDIA_ROUTE_PROVIDER); |
148 AttemptWakeEventPage(); | 154 AttemptWakeEventPage(); |
149 return; | 155 return; |
150 } | 156 } |
151 | 157 |
152 media_route_provider_ = std::move(media_route_provider_ptr); | 158 media_route_provider_ = std::move(media_route_provider_ptr); |
153 media_route_provider_.set_connection_error_handler(base::Bind( | 159 media_route_provider_.set_connection_error_handler(base::Bind( |
154 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); | 160 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); |
| 161 |
155 callback.Run(instance_id_); | 162 callback.Run(instance_id_); |
156 ExecutePendingRequests(); | 163 ExecutePendingRequests(); |
157 SyncStateToMediaRouteProvider(); | 164 SyncStateToMediaRouteProvider(); |
158 | 165 |
159 wakeup_attempt_count_ = 0; | 166 wakeup_attempt_count_ = 0; |
160 } | 167 } |
161 | 168 |
162 void MediaRouterMojoImpl::OnIssue(const IssueInfo& issue) { | 169 void MediaRouterMojoImpl::OnIssue(const IssueInfo& issue) { |
163 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 170 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
164 DVLOG_WITH_INSTANCE(1) << "OnIssue " << issue.title; | 171 DVLOG_WITH_INSTANCE(1) << "OnIssue " << issue.title; |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 std::move(mojo_media_controller_request), | 423 std::move(mojo_media_controller_request), |
417 route_controller->BindObserverPtr())); | 424 route_controller->BindObserverPtr())); |
418 route_controllers_.emplace(route_id, route_controller.get()); | 425 route_controllers_.emplace(route_id, route_controller.get()); |
419 return route_controller; | 426 return route_controller; |
420 } | 427 } |
421 | 428 |
422 void MediaRouterMojoImpl::ProvideSinks( | 429 void MediaRouterMojoImpl::ProvideSinks( |
423 const std::string& provider_name, | 430 const std::string& provider_name, |
424 const std::vector<MediaSinkInternal>& sinks) { | 431 const std::vector<MediaSinkInternal>& sinks) { |
425 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 432 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 433 DVLOG_WITH_INSTANCE(1) << "OnDialMediaSinkDiscovered found " << sinks.size() |
| 434 << " devices..."; |
426 | 435 |
427 SetWakeReason(MediaRouteProviderWakeReason::PROVIDE_SINKS); | 436 SetWakeReason(MediaRouteProviderWakeReason::PROVIDE_SINKS); |
428 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoProvideSinks, | 437 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoProvideSinks, |
429 base::Unretained(this), provider_name, sinks)); | 438 base::Unretained(this), provider_name, sinks)); |
430 } | 439 } |
431 | 440 |
432 bool MediaRouterMojoImpl::RegisterMediaSinksObserver( | 441 bool MediaRouterMojoImpl::RegisterMediaSinksObserver( |
433 MediaSinksObserver* observer) { | 442 MediaSinksObserver* observer) { |
434 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 443 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
435 | 444 |
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 } | 1064 } |
1056 } | 1065 } |
1057 | 1066 |
1058 void MediaRouterMojoImpl::OnFirewallCheckComplete( | 1067 void MediaRouterMojoImpl::OnFirewallCheckComplete( |
1059 bool firewall_can_use_local_ports) { | 1068 bool firewall_can_use_local_ports) { |
1060 if (firewall_can_use_local_ports) | 1069 if (firewall_can_use_local_ports) |
1061 EnsureMdnsDiscoveryEnabled(); | 1070 EnsureMdnsDiscoveryEnabled(); |
1062 } | 1071 } |
1063 #endif | 1072 #endif |
1064 | 1073 |
| 1074 void MediaRouterMojoImpl::StartDiscovery() { |
| 1075 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 1076 DVLOG_WITH_INSTANCE(1) << "StartDiscovery"; |
| 1077 |
| 1078 if (dial_media_sink_service_delegate_) |
| 1079 return; |
| 1080 |
| 1081 auto* profile = Profile::FromBrowserContext(context_); |
| 1082 if (!profile) |
| 1083 return; |
| 1084 |
| 1085 dial_media_sink_service_delegate_ = new DialMediaSinkServiceDelegate(); |
| 1086 dial_media_sink_service_delegate_->Start( |
| 1087 base::Bind(&MediaRouterMojoImpl::ProvideSinks, base::Unretained(this), |
| 1088 "dial"), |
| 1089 profile->GetRequestContext()); |
| 1090 } |
| 1091 |
1065 void MediaRouterMojoImpl::UpdateMediaSinks( | 1092 void MediaRouterMojoImpl::UpdateMediaSinks( |
1066 const MediaSource::Id& source_id) { | 1093 const MediaSource::Id& source_id) { |
1067 SetWakeReason(MediaRouteProviderWakeReason::UPDATE_MEDIA_SINKS); | 1094 SetWakeReason(MediaRouteProviderWakeReason::UPDATE_MEDIA_SINKS); |
1068 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoUpdateMediaSinks, | 1095 RunOrDefer(base::BindOnce(&MediaRouterMojoImpl::DoUpdateMediaSinks, |
1069 base::Unretained(this), source_id)); | 1096 base::Unretained(this), source_id)); |
1070 } | 1097 } |
1071 | 1098 |
1072 void MediaRouterMojoImpl::DoUpdateMediaSinks( | 1099 void MediaRouterMojoImpl::DoUpdateMediaSinks( |
1073 const MediaSource::Id& source_id) { | 1100 const MediaSource::Id& source_id) { |
1074 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks: " << source_id; | 1101 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks: " << source_id; |
(...skipping 15 matching lines...) Expand all Loading... |
1090 | 1117 |
1091 void MediaRouterMojoImpl::OnMediaControllerCreated( | 1118 void MediaRouterMojoImpl::OnMediaControllerCreated( |
1092 const MediaRoute::Id& route_id, | 1119 const MediaRoute::Id& route_id, |
1093 bool success) { | 1120 bool success) { |
1094 // TODO(takumif): Record success/failure with UMA. | 1121 // TODO(takumif): Record success/failure with UMA. |
1095 DVLOG_WITH_INSTANCE(1) << "OnMediaControllerCreated: " << route_id | 1122 DVLOG_WITH_INSTANCE(1) << "OnMediaControllerCreated: " << route_id |
1096 << (success ? " was successful." : " failed."); | 1123 << (success ? " was successful." : " failed."); |
1097 } | 1124 } |
1098 | 1125 |
1099 } // namespace media_router | 1126 } // namespace media_router |
OLD | NEW |