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

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

Issue 2857393005: [Media Router] Sync state when MR extension is (re)connected to MR. (Closed)
Patch Set: 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
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 SetWakeReason(MediaRouteProviderWakeReason::REGISTER_MEDIA_ROUTE_PROVIDER); 145 SetWakeReason(MediaRouteProviderWakeReason::REGISTER_MEDIA_ROUTE_PROVIDER);
146 AttemptWakeEventPage(); 146 AttemptWakeEventPage();
147 return; 147 return;
148 } 148 }
149 149
150 media_route_provider_ = std::move(media_route_provider_ptr); 150 media_route_provider_ = std::move(media_route_provider_ptr);
151 media_route_provider_.set_connection_error_handler(base::Bind( 151 media_route_provider_.set_connection_error_handler(base::Bind(
152 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); 152 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this)));
153 callback.Run(instance_id_); 153 callback.Run(instance_id_);
154 ExecutePendingRequests(); 154 ExecutePendingRequests();
155 SyncStateToMediaRouteProvider();
156
155 wakeup_attempt_count_ = 0; 157 wakeup_attempt_count_ = 0;
156 #if defined(OS_WIN)
157 // The MRPM extension already turns on mDNS discovery for platforms other than
158 // Windows. It only relies on this signalling from MR on Windows to avoid
159 // triggering a firewall prompt out of the context of MR from the user's
160 // perspective. This particular call reminds the extension to enable mDNS
161 // discovery when it wakes up, has been upgraded, etc.
162 if (should_enable_mdns_discovery_) {
163 DoEnsureMdnsDiscoveryEnabled();
164 }
165 #endif
166 } 158 }
167 159
168 void MediaRouterMojoImpl::OnIssue(const IssueInfo& issue) { 160 void MediaRouterMojoImpl::OnIssue(const IssueInfo& issue) {
169 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 161 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
170 DVLOG_WITH_INSTANCE(1) << "OnIssue " << issue.title; 162 DVLOG_WITH_INSTANCE(1) << "OnIssue " << issue.title;
171 issue_manager_.AddIssue(issue); 163 issue_manager_.AddIssue(issue);
172 } 164 }
173 165
174 void MediaRouterMojoImpl::OnSinksReceived( 166 void MediaRouterMojoImpl::OnSinksReceived(
175 const std::string& media_source, 167 const std::string& media_source,
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 } 777 }
786 778
787 void MediaRouterMojoImpl::DoStartObservingMediaSinks( 779 void MediaRouterMojoImpl::DoStartObservingMediaSinks(
788 const MediaSource::Id& source_id) { 780 const MediaSource::Id& source_id) {
789 DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaSinks: " << source_id; 781 DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaSinks: " << source_id;
790 // No need to call MRPM if there are no sinks available. 782 // No need to call MRPM if there are no sinks available.
791 if (availability_ == mojom::MediaRouter::SinkAvailability::UNAVAILABLE) 783 if (availability_ == mojom::MediaRouter::SinkAvailability::UNAVAILABLE)
792 return; 784 return;
793 785
794 // No need to call MRPM if all observers have been removed in the meantime. 786 // No need to call MRPM if all observers have been removed in the meantime.
795 auto* sinks_query = sinks_queries_[source_id].get(); 787 auto it = sinks_queries_.find(source_id);
796 if (!sinks_query || !sinks_query->observers.might_have_observers()) 788 if (it == sinks_queries_.end() ||
789 !it->second->observers.might_have_observers())
797 return; 790 return;
798 791
799 DVLOG_WITH_INSTANCE(1) << "MRPM.StartObservingMediaSinks: " << source_id; 792 DVLOG_WITH_INSTANCE(1) << "MRPM.StartObservingMediaSinks: " << source_id;
800 media_route_provider_->StartObservingMediaSinks(source_id); 793 media_route_provider_->StartObservingMediaSinks(source_id);
801 sinks_query->is_active = true; 794 it->second->is_active = true;
802 } 795 }
803 796
804 void MediaRouterMojoImpl::DoStopObservingMediaSinks( 797 void MediaRouterMojoImpl::DoStopObservingMediaSinks(
805 const MediaSource::Id& source_id) { 798 const MediaSource::Id& source_id) {
806 DVLOG_WITH_INSTANCE(1) << "DoStopObservingMediaSinks: " << source_id; 799 DVLOG_WITH_INSTANCE(1) << "DoStopObservingMediaSinks: " << source_id;
807 800
808 auto it = sinks_queries_.find(source_id); 801 auto it = sinks_queries_.find(source_id);
809 // No need to call MRPM if observers have been added in the meantime, 802 // No need to call MRPM if observers have been added in the meantime,
810 // or StopObservingMediaSinks has already been called. 803 // or StopObservingMediaSinks has already been called.
811 if (it == sinks_queries_.end() || !it->second->is_active || 804 if (it == sinks_queries_.end() || !it->second->is_active ||
(...skipping 11 matching lines...) Expand all
823 DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaRoutes"; 816 DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaRoutes";
824 817
825 // No need to call MRPM if all observers have been removed in the meantime. 818 // No need to call MRPM if all observers have been removed in the meantime.
826 auto it = routes_queries_.find(source_id); 819 auto it = routes_queries_.find(source_id);
827 if (it == routes_queries_.end() || 820 if (it == routes_queries_.end() ||
828 !it->second->observers.might_have_observers()) 821 !it->second->observers.might_have_observers())
829 return; 822 return;
830 823
831 DVLOG_WITH_INSTANCE(1) << "MRPM.StartObservingMediaRoutes: " << source_id; 824 DVLOG_WITH_INSTANCE(1) << "MRPM.StartObservingMediaRoutes: " << source_id;
832 media_route_provider_->StartObservingMediaRoutes(source_id); 825 media_route_provider_->StartObservingMediaRoutes(source_id);
833 it->second->is_active = true;
834 } 826 }
835 827
836 void MediaRouterMojoImpl::DoStopObservingMediaRoutes( 828 void MediaRouterMojoImpl::DoStopObservingMediaRoutes(
837 const MediaSource::Id& source_id) { 829 const MediaSource::Id& source_id) {
838 DVLOG_WITH_INSTANCE(1) << "DoStopObservingMediaRoutes"; 830 DVLOG_WITH_INSTANCE(1) << "DoStopObservingMediaRoutes";
839 831
840 // No need to call MRPM if observers have been added in the meantime, 832 // No need to call MRPM if observers have been added in the meantime,
841 // or StopObservingMediaRoutes has already been called. 833 // or StopObservingMediaRoutes has already been called.
842 auto it = routes_queries_.find(source_id); 834 auto it = routes_queries_.find(source_id);
843 if (it == routes_queries_.end() || !it->second->is_active || 835 if (it == routes_queries_.end() ||
844 it->second->observers.might_have_observers()) { 836 it->second->observers.might_have_observers()) {
845 return; 837 return;
846 } 838 }
847 839
848 DVLOG_WITH_INSTANCE(1) << "MRPM.StopObservingMediaRoutes: " << source_id; 840 DVLOG_WITH_INSTANCE(1) << "MRPM.StopObservingMediaRoutes: " << source_id;
849 media_route_provider_->StopObservingMediaRoutes(source_id); 841 media_route_provider_->StopObservingMediaRoutes(source_id);
850 routes_queries_.erase(source_id); 842 routes_queries_.erase(source_id);
851 } 843 }
852 844
853 void MediaRouterMojoImpl::EnqueueTask(const base::Closure& closure) { 845 void MediaRouterMojoImpl::EnqueueTask(const base::Closure& closure) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 DCHECK(media_route_provider_); 905 DCHECK(media_route_provider_);
914 DCHECK(event_page_tracker_); 906 DCHECK(event_page_tracker_);
915 DCHECK(!media_route_provider_extension_id_.empty()); 907 DCHECK(!media_route_provider_extension_id_.empty());
916 908
917 for (const auto& next_request : pending_requests_) 909 for (const auto& next_request : pending_requests_)
918 next_request.Run(); 910 next_request.Run();
919 911
920 pending_requests_.clear(); 912 pending_requests_.clear();
921 } 913 }
922 914
915 void MediaRouterMojoImpl::SyncStateToMediaRouteProvider() {
916 DCHECK(media_route_provider_);
917
918 // Sink queries.
919 if (availability_ != mojom::MediaRouter::SinkAvailability::UNAVAILABLE) {
920 for (const auto& it : sinks_queries_) {
921 DoStartObservingMediaSinks(it.first);
922 }
923 }
924
925 // Route queries.
926 for (const auto& it : routes_queries_) {
927 DoStartObservingMediaRoutes(it.first);
928 }
929
930 // Route messages.
931 for (const auto& it : message_observers_) {
932 DoStartListeningForRouteMessages(it.first);
933 }
934
935 #if defined(OS_WIN)
936 // The MRPM extension already turns on mDNS discovery for platforms other than
937 // Windows. It only relies on this signalling from MR on Windows to avoid
938 // triggering a firewall prompt out of the context of MR from the user's
939 // perspective. This particular call reminds the extension to enable mDNS
940 // discovery when it wakes up, has been upgraded, etc.
941 if (should_enable_mdns_discovery_) {
942 DoEnsureMdnsDiscoveryEnabled();
943 }
944 #endif
945 }
946
923 void MediaRouterMojoImpl::EventPageWakeComplete(bool success) { 947 void MediaRouterMojoImpl::EventPageWakeComplete(bool success) {
924 if (success) { 948 if (success) {
925 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeReason( 949 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeReason(
926 current_wake_reason_); 950 current_wake_reason_);
927 ClearWakeReason(); 951 ClearWakeReason();
928 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeup( 952 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeup(
929 MediaRouteProviderWakeup::SUCCESS); 953 MediaRouteProviderWakeup::SUCCESS);
930 return; 954 return;
931 } 955 }
932 956
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 base::Unretained(this), source_id)); 1014 base::Unretained(this), source_id));
991 } 1015 }
992 1016
993 void MediaRouterMojoImpl::DoUpdateMediaSinks( 1017 void MediaRouterMojoImpl::DoUpdateMediaSinks(
994 const MediaSource::Id& source_id) { 1018 const MediaSource::Id& source_id) {
995 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks" << source_id; 1019 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks" << source_id;
996 media_route_provider_->UpdateMediaSinks(source_id); 1020 media_route_provider_->UpdateMediaSinks(source_id);
997 } 1021 }
998 1022
999 } // namespace media_router 1023 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698