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/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 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 SetWakeReason(MediaRouteProviderWakeReason::REGISTER_MEDIA_ROUTE_PROVIDER); | 146 SetWakeReason(MediaRouteProviderWakeReason::REGISTER_MEDIA_ROUTE_PROVIDER); |
| 147 AttemptWakeEventPage(); | 147 AttemptWakeEventPage(); |
| 148 return; | 148 return; |
| 149 } | 149 } |
| 150 | 150 |
| 151 media_route_provider_ = std::move(media_route_provider_ptr); | 151 media_route_provider_ = std::move(media_route_provider_ptr); |
| 152 media_route_provider_.set_connection_error_handler(base::Bind( | 152 media_route_provider_.set_connection_error_handler(base::Bind( |
| 153 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); | 153 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); |
| 154 callback.Run(instance_id_); | 154 callback.Run(instance_id_); |
| 155 ExecutePendingRequests(); | 155 ExecutePendingRequests(); |
| 156 EnsureMediaRouteProviderStateSynced(); | |
| 157 | |
| 156 wakeup_attempt_count_ = 0; | 158 wakeup_attempt_count_ = 0; |
| 157 #if defined(OS_WIN) | |
| 158 // The MRPM extension already turns on mDNS discovery for platforms other than | |
| 159 // Windows. It only relies on this signalling from MR on Windows to avoid | |
| 160 // triggering a firewall prompt out of the context of MR from the user's | |
| 161 // perspective. This particular call reminds the extension to enable mDNS | |
| 162 // discovery when it wakes up, has been upgraded, etc. | |
| 163 if (should_enable_mdns_discovery_) { | |
| 164 DoEnsureMdnsDiscoveryEnabled(); | |
| 165 } | |
| 166 #endif | |
| 167 } | 159 } |
| 168 | 160 |
| 169 void MediaRouterMojoImpl::OnIssue(const IssueInfo& issue) { | 161 void MediaRouterMojoImpl::OnIssue(const IssueInfo& issue) { |
| 170 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 162 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 171 DVLOG_WITH_INSTANCE(1) << "OnIssue " << issue.title; | 163 DVLOG_WITH_INSTANCE(1) << "OnIssue " << issue.title; |
| 172 issue_manager_.AddIssue(issue); | 164 issue_manager_.AddIssue(issue); |
| 173 } | 165 } |
| 174 | 166 |
| 175 void MediaRouterMojoImpl::OnSinksReceived( | 167 void MediaRouterMojoImpl::OnSinksReceived( |
| 176 const std::string& media_source, | 168 const std::string& media_source, |
| (...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 839 } | 831 } |
| 840 | 832 |
| 841 void MediaRouterMojoImpl::DoStartObservingMediaSinks( | 833 void MediaRouterMojoImpl::DoStartObservingMediaSinks( |
| 842 const MediaSource::Id& source_id) { | 834 const MediaSource::Id& source_id) { |
| 843 DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaSinks: " << source_id; | 835 DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaSinks: " << source_id; |
| 844 // No need to call MRPM if there are no sinks available. | 836 // No need to call MRPM if there are no sinks available. |
| 845 if (availability_ == mojom::MediaRouter::SinkAvailability::UNAVAILABLE) | 837 if (availability_ == mojom::MediaRouter::SinkAvailability::UNAVAILABLE) |
| 846 return; | 838 return; |
| 847 | 839 |
| 848 // No need to call MRPM if all observers have been removed in the meantime. | 840 // No need to call MRPM if all observers have been removed in the meantime. |
| 849 auto* sinks_query = sinks_queries_[source_id].get(); | 841 auto it = sinks_queries_.find(source_id); |
| 850 if (!sinks_query || !sinks_query->observers.might_have_observers()) | 842 if (it == sinks_queries_.end() || |
| 843 !it->second->observers.might_have_observers()) | |
| 851 return; | 844 return; |
| 852 | 845 |
| 853 DVLOG_WITH_INSTANCE(1) << "MRPM.StartObservingMediaSinks: " << source_id; | 846 DVLOG_WITH_INSTANCE(1) << "MRPM.StartObservingMediaSinks: " << source_id; |
| 854 media_route_provider_->StartObservingMediaSinks(source_id); | 847 media_route_provider_->StartObservingMediaSinks(source_id); |
| 855 sinks_query->is_active = true; | 848 it->second->is_active = true; |
| 856 } | 849 } |
| 857 | 850 |
| 858 void MediaRouterMojoImpl::DoStopObservingMediaSinks( | 851 void MediaRouterMojoImpl::DoStopObservingMediaSinks( |
| 859 const MediaSource::Id& source_id) { | 852 const MediaSource::Id& source_id) { |
| 860 DVLOG_WITH_INSTANCE(1) << "DoStopObservingMediaSinks: " << source_id; | 853 DVLOG_WITH_INSTANCE(1) << "DoStopObservingMediaSinks: " << source_id; |
| 861 | 854 |
| 862 auto it = sinks_queries_.find(source_id); | 855 auto it = sinks_queries_.find(source_id); |
| 863 // No need to call MRPM if observers have been added in the meantime, | 856 // No need to call MRPM if observers have been added in the meantime, |
| 864 // or StopObservingMediaSinks has already been called. | 857 // or StopObservingMediaSinks has already been called. |
| 865 if (it == sinks_queries_.end() || !it->second->is_active || | 858 if (it == sinks_queries_.end() || !it->second->is_active || |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 877 DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaRoutes"; | 870 DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaRoutes"; |
| 878 | 871 |
| 879 // No need to call MRPM if all observers have been removed in the meantime. | 872 // No need to call MRPM if all observers have been removed in the meantime. |
| 880 auto it = routes_queries_.find(source_id); | 873 auto it = routes_queries_.find(source_id); |
| 881 if (it == routes_queries_.end() || | 874 if (it == routes_queries_.end() || |
| 882 !it->second->observers.might_have_observers()) | 875 !it->second->observers.might_have_observers()) |
| 883 return; | 876 return; |
| 884 | 877 |
| 885 DVLOG_WITH_INSTANCE(1) << "MRPM.StartObservingMediaRoutes: " << source_id; | 878 DVLOG_WITH_INSTANCE(1) << "MRPM.StartObservingMediaRoutes: " << source_id; |
| 886 media_route_provider_->StartObservingMediaRoutes(source_id); | 879 media_route_provider_->StartObservingMediaRoutes(source_id); |
| 887 it->second->is_active = true; | |
| 888 } | 880 } |
| 889 | 881 |
| 890 void MediaRouterMojoImpl::DoStopObservingMediaRoutes( | 882 void MediaRouterMojoImpl::DoStopObservingMediaRoutes( |
| 891 const MediaSource::Id& source_id) { | 883 const MediaSource::Id& source_id) { |
| 892 DVLOG_WITH_INSTANCE(1) << "DoStopObservingMediaRoutes"; | 884 DVLOG_WITH_INSTANCE(1) << "DoStopObservingMediaRoutes"; |
| 893 | 885 |
| 894 // No need to call MRPM if observers have been added in the meantime, | 886 // No need to call MRPM if observers have been added in the meantime, |
| 895 // or StopObservingMediaRoutes has already been called. | 887 // or StopObservingMediaRoutes has already been called. |
| 896 auto it = routes_queries_.find(source_id); | 888 auto it = routes_queries_.find(source_id); |
| 897 if (it == routes_queries_.end() || !it->second->is_active || | 889 if (it == routes_queries_.end() || |
| 898 it->second->observers.might_have_observers()) { | 890 it->second->observers.might_have_observers()) { |
| 899 return; | 891 return; |
| 900 } | 892 } |
| 901 | 893 |
| 902 DVLOG_WITH_INSTANCE(1) << "MRPM.StopObservingMediaRoutes: " << source_id; | 894 DVLOG_WITH_INSTANCE(1) << "MRPM.StopObservingMediaRoutes: " << source_id; |
| 903 media_route_provider_->StopObservingMediaRoutes(source_id); | 895 media_route_provider_->StopObservingMediaRoutes(source_id); |
| 904 routes_queries_.erase(source_id); | 896 routes_queries_.erase(source_id); |
| 905 } | 897 } |
| 906 | 898 |
| 907 void MediaRouterMojoImpl::EnqueueTask(base::OnceClosure closure) { | 899 void MediaRouterMojoImpl::EnqueueTask(base::OnceClosure closure) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 967 DCHECK(media_route_provider_); | 959 DCHECK(media_route_provider_); |
| 968 DCHECK(event_page_tracker_); | 960 DCHECK(event_page_tracker_); |
| 969 DCHECK(!media_route_provider_extension_id_.empty()); | 961 DCHECK(!media_route_provider_extension_id_.empty()); |
| 970 | 962 |
| 971 for (auto& next_request : pending_requests_) | 963 for (auto& next_request : pending_requests_) |
| 972 std::move(next_request).Run(); | 964 std::move(next_request).Run(); |
| 973 | 965 |
| 974 pending_requests_.clear(); | 966 pending_requests_.clear(); |
| 975 } | 967 } |
| 976 | 968 |
| 969 void MediaRouterMojoImpl::EnsureMediaRouteProviderStateSynced() { | |
| 970 DCHECK(media_route_provider_); | |
| 971 | |
| 972 // Sink queries. | |
| 973 if (availability_ != mojom::MediaRouter::SinkAvailability::UNAVAILABLE) { | |
| 974 for (const auto& it : sinks_queries_) { | |
| 975 DoStartObservingMediaSinks(it.first); | |
| 976 } | |
| 977 } | |
| 978 | |
| 979 // Route queries. | |
| 980 for (const auto& it : routes_queries_) { | |
| 981 DoStartObservingMediaRoutes(it.first); | |
| 982 } | |
| 983 | |
| 984 // Route messages. | |
| 985 for (const auto& it : message_observers_) { | |
| 986 DoStartListeningForRouteMessages(it.first); | |
| 987 } | |
| 988 | |
| 989 #if defined(OS_WIN) | |
| 990 // The MRPM extension already turns on mDNS discovery for platforms other than | |
| 991 // Windows. It only relies on this signalling from MR on Windows to avoid | |
| 992 // triggering a firewall prompt out of the context of MR from the user's | |
| 993 // perspective. This particular call reminds the extension to enable mDNS | |
| 994 // discovery when it wakes up, has been upgraded, etc. | |
| 995 if (should_enable_mdns_discovery_) { | |
| 996 DoEnsureMdnsDiscoveryEnabled(); | |
|
mark a. foltz
2017/05/03 17:37:08
Would prefer DoEnableMdnsDiscovery(), but not nece
imcheng
2017/05/03 18:22:41
Acknowledged.
| |
| 997 } | |
| 998 #endif | |
| 999 } | |
| 1000 | |
| 977 void MediaRouterMojoImpl::EventPageWakeComplete(bool success) { | 1001 void MediaRouterMojoImpl::EventPageWakeComplete(bool success) { |
| 978 if (success) { | 1002 if (success) { |
| 979 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeReason( | 1003 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeReason( |
| 980 current_wake_reason_); | 1004 current_wake_reason_); |
| 981 ClearWakeReason(); | 1005 ClearWakeReason(); |
| 982 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeup( | 1006 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeup( |
| 983 MediaRouteProviderWakeup::SUCCESS); | 1007 MediaRouteProviderWakeup::SUCCESS); |
| 984 return; | 1008 return; |
| 985 } | 1009 } |
| 986 | 1010 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1065 | 1089 |
| 1066 void MediaRouterMojoImpl::OnMediaControllerCreated( | 1090 void MediaRouterMojoImpl::OnMediaControllerCreated( |
| 1067 const MediaRoute::Id& route_id, | 1091 const MediaRoute::Id& route_id, |
| 1068 bool success) { | 1092 bool success) { |
| 1069 // TODO(takumif): Record success/failure with UMA. | 1093 // TODO(takumif): Record success/failure with UMA. |
| 1070 DVLOG_WITH_INSTANCE(1) << "OnMediaControllerCreated: " << route_id | 1094 DVLOG_WITH_INSTANCE(1) << "OnMediaControllerCreated: " << route_id |
| 1071 << (success ? " was successful." : " failed."); | 1095 << (success ? " was successful." : " failed."); |
| 1072 } | 1096 } |
| 1073 | 1097 |
| 1074 } // namespace media_router | 1098 } // namespace media_router |
| OLD | NEW |