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

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

Issue 1693963003: Pass origin to StartObservingMediaSinks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Marks Review Fixes with URL changes Created 4 years, 9 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/media_router_mojo_impl.h" 5 #include "chrome/browser/media/router/media_router_mojo_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 158
159 void MediaRouterMojoImpl::OnIssue(const interfaces::IssuePtr issue) { 159 void MediaRouterMojoImpl::OnIssue(const interfaces::IssuePtr issue) {
160 DCHECK(thread_checker_.CalledOnValidThread()); 160 DCHECK(thread_checker_.CalledOnValidThread());
161 DVLOG_WITH_INSTANCE(1) << "OnIssue " << issue->title; 161 DVLOG_WITH_INSTANCE(1) << "OnIssue " << issue->title;
162 const Issue& issue_converted = issue.To<Issue>(); 162 const Issue& issue_converted = issue.To<Issue>();
163 issue_manager_.AddIssue(issue_converted); 163 issue_manager_.AddIssue(issue_converted);
164 } 164 }
165 165
166 void MediaRouterMojoImpl::OnSinksReceived( 166 void MediaRouterMojoImpl::OnSinksReceived(
167 const mojo::String& media_source, 167 const mojo::String& media_source,
168 const mojo::String& origin,
168 mojo::Array<interfaces::MediaSinkPtr> sinks) { 169 mojo::Array<interfaces::MediaSinkPtr> sinks) {
169 DCHECK(thread_checker_.CalledOnValidThread()); 170 DCHECK(thread_checker_.CalledOnValidThread());
170 DVLOG_WITH_INSTANCE(1) << "OnSinksReceived"; 171 DVLOG_WITH_INSTANCE(1) << "OnSinksReceived";
171 auto it = sinks_queries_.find(media_source); 172 MediaSource source(media_source);
173 source.set_origin(origin);
174 auto it = sinks_queries_.find(source);
172 if (it == sinks_queries_.end()) { 175 if (it == sinks_queries_.end()) {
173 DVLOG_WITH_INSTANCE(1) << "Received sink list without MediaSinksQuery."; 176 DVLOG_WITH_INSTANCE(1) << "Received sink list without MediaSinksQuery.";
174 return; 177 return;
175 } 178 }
176 179
177 auto* sinks_query = it->second; 180 auto* sinks_query = it->second;
178 sinks_query->has_cached_result = true; 181 sinks_query->has_cached_result = true;
179 auto& cached_sink_list = sinks_query->cached_sink_list; 182 auto& cached_sink_list = sinks_query->cached_sink_list;
180 cached_sink_list.clear(); 183 cached_sink_list.clear();
181 cached_sink_list.reserve(sinks.size()); 184 cached_sink_list.reserve(sinks.size());
182 for (size_t i = 0; i < sinks.size(); ++i) 185 for (size_t i = 0; i < sinks.size(); ++i)
183 cached_sink_list.push_back(sinks[i].To<MediaSink>()); 186 cached_sink_list.push_back(sinks[i].To<MediaSink>());
184 187
185 if (!sinks_query->observers.might_have_observers()) { 188 if (!sinks_query->observers.might_have_observers()) {
186 DVLOG_WITH_INSTANCE(1) 189 DVLOG_WITH_INSTANCE(1)
187 << "Received sink list without any active observers: " << media_source; 190 << "Received sink list without any active observers: " << media_source;
188 } else { 191 } else {
189 FOR_EACH_OBSERVER(MediaSinksObserver, sinks_query->observers, 192 FOR_EACH_OBSERVER(MediaSinksObserver, sinks_query->observers,
190 OnSinksReceived(cached_sink_list)); 193 OnSinksReceived(source, cached_sink_list));
191 } 194 }
192 } 195 }
193 196
194 void MediaRouterMojoImpl::OnRoutesUpdated( 197 void MediaRouterMojoImpl::OnRoutesUpdated(
195 mojo::Array<interfaces::MediaRoutePtr> routes, 198 mojo::Array<interfaces::MediaRoutePtr> routes,
196 const mojo::String& media_source, 199 const mojo::String& media_source,
197 mojo::Array<mojo::String> joinable_route_ids) { 200 mojo::Array<mojo::String> joinable_route_ids) {
198 DCHECK(thread_checker_.CalledOnValidThread()); 201 DCHECK(thread_checker_.CalledOnValidThread());
199 202
200 DVLOG_WITH_INSTANCE(1) << "OnRoutesUpdated"; 203 DVLOG_WITH_INSTANCE(1) << "OnRoutesUpdated";
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 DCHECK(thread_checker_.CalledOnValidThread()); 376 DCHECK(thread_checker_.CalledOnValidThread());
374 issue_manager_.ClearIssue(issue_id); 377 issue_manager_.ClearIssue(issue_id);
375 } 378 }
376 379
377 bool MediaRouterMojoImpl::RegisterMediaSinksObserver( 380 bool MediaRouterMojoImpl::RegisterMediaSinksObserver(
378 MediaSinksObserver* observer) { 381 MediaSinksObserver* observer) {
379 DCHECK(thread_checker_.CalledOnValidThread()); 382 DCHECK(thread_checker_.CalledOnValidThread());
380 383
381 // Create an observer list for the media source and add |observer| 384 // Create an observer list for the media source and add |observer|
382 // to it. Fail if |observer| is already registered. 385 // to it. Fail if |observer| is already registered.
383 const std::string& source_id = observer->source().id(); 386 const MediaSource& source = observer->source();
384 auto* sinks_query = sinks_queries_.get(source_id); 387 auto* sinks_query = sinks_queries_.get(source);
385 bool new_query = false; 388 bool new_query = false;
386 if (!sinks_query) { 389 if (!sinks_query) {
387 new_query = true; 390 new_query = true;
388 sinks_query = new MediaSinksQuery; 391 sinks_query = new MediaSinksQuery;
389 sinks_queries_.add(source_id, make_scoped_ptr(sinks_query)); 392 sinks_queries_.add(source, make_scoped_ptr(sinks_query));
390 } else { 393 } else {
391 DCHECK(!sinks_query->observers.HasObserver(observer)); 394 DCHECK(!sinks_query->observers.HasObserver(observer));
392 } 395 }
393 396
394 // If sink availability is UNAVAILABLE, then there is no need to call MRPM. 397 // If sink availability is UNAVAILABLE, then there is no need to call MRPM.
395 // |observer| can be immediately notified with an empty list. 398 // |observer| can be immediately notified with an empty list.
396 sinks_query->observers.AddObserver(observer); 399 sinks_query->observers.AddObserver(observer);
397 if (availability_ == interfaces::MediaRouter::SinkAvailability::UNAVAILABLE) { 400 if (availability_ == interfaces::MediaRouter::SinkAvailability::UNAVAILABLE) {
398 observer->OnSinksReceived(std::vector<MediaSink>()); 401 observer->OnSinksReceived(source, std::vector<MediaSink>());
399 } else { 402 } else {
400 // Need to call MRPM to start observing sinks if the query is new. 403 // Need to call MRPM to start observing sinks if the query is new.
401 if (new_query) { 404 if (new_query) {
402 SetWakeReason(MediaRouteProviderWakeReason::START_OBSERVING_MEDIA_SINKS); 405 SetWakeReason(MediaRouteProviderWakeReason::START_OBSERVING_MEDIA_SINKS);
403 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks, 406 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks,
404 base::Unretained(this), source_id)); 407 base::Unretained(this), source));
405 } else if (sinks_query->has_cached_result) { 408 } else if (sinks_query->has_cached_result) {
406 observer->OnSinksReceived(sinks_query->cached_sink_list); 409 observer->OnSinksReceived(source, sinks_query->cached_sink_list);
407 } 410 }
408 } 411 }
409 return true; 412 return true;
410 } 413 }
411 414
412 void MediaRouterMojoImpl::UnregisterMediaSinksObserver( 415 void MediaRouterMojoImpl::UnregisterMediaSinksObserver(
413 MediaSinksObserver* observer) { 416 MediaSinksObserver* observer) {
414 DCHECK(thread_checker_.CalledOnValidThread()); 417 DCHECK(thread_checker_.CalledOnValidThread());
415 418
416 const MediaSource::Id& source_id = observer->source().id(); 419 const MediaSource& source = observer->source();
417 auto* sinks_query = sinks_queries_.get(source_id); 420 auto* sinks_query = sinks_queries_.get(source);
418 if (!sinks_query || !sinks_query->observers.HasObserver(observer)) { 421 if (!sinks_query || !sinks_query->observers.HasObserver(observer)) {
419 return; 422 return;
420 } 423 }
421 424
422 // If we are removing the final observer for the source, then stop 425 // If we are removing the final observer for the source, then stop
423 // observing sinks for it. 426 // observing sinks for it.
424 // might_have_observers() is reliable here on the assumption that this call 427 // might_have_observers() is reliable here on the assumption that this call
425 // is not inside the ObserverList iteration. 428 // is not inside the ObserverList iteration.
426 sinks_query->observers.RemoveObserver(observer); 429 sinks_query->observers.RemoveObserver(observer);
427 if (!sinks_query->observers.might_have_observers()) { 430 if (!sinks_query->observers.might_have_observers()) {
428 // Only ask MRPM to stop observing media sinks if the availability is not 431 // Only ask MRPM to stop observing media sinks if the availability is not
429 // UNAVAILABLE. 432 // UNAVAILABLE.
430 // Otherwise, the MRPM would have discarded the queries already. 433 // Otherwise, the MRPM would have discarded the queries already.
431 if (availability_ != 434 if (availability_ !=
432 interfaces::MediaRouter::SinkAvailability::UNAVAILABLE) { 435 interfaces::MediaRouter::SinkAvailability::UNAVAILABLE) {
433 SetWakeReason(MediaRouteProviderWakeReason::STOP_OBSERVING_MEDIA_SINKS); 436 SetWakeReason(MediaRouteProviderWakeReason::STOP_OBSERVING_MEDIA_SINKS);
434 // The |sinks_queries_| entry will be removed in the immediate or deferred 437 // The |sinks_queries_| entry will be removed in the immediate or deferred
435 // |DoStopObservingMediaSinks| call. 438 // |DoStopObservingMediaSinks| call.
436 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStopObservingMediaSinks, 439 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStopObservingMediaSinks,
437 base::Unretained(this), source_id)); 440 base::Unretained(this), source));
438 } else { 441 } else {
439 sinks_queries_.erase(source_id); 442 sinks_queries_.erase(source);
440 } 443 }
441 } 444 }
442 } 445 }
443 446
444 void MediaRouterMojoImpl::RegisterMediaRoutesObserver( 447 void MediaRouterMojoImpl::RegisterMediaRoutesObserver(
445 MediaRoutesObserver* observer) { 448 MediaRoutesObserver* observer) {
446 DCHECK(thread_checker_.CalledOnValidThread()); 449 DCHECK(thread_checker_.CalledOnValidThread());
447 const MediaSource::Id source_id = observer->source_id(); 450 const MediaSource::Id source_id = observer->source_id();
448 auto* routes_query = routes_queries_.get(source_id); 451 auto* routes_query = routes_queries_.get(source_id);
449 if (!routes_query) { 452 if (!routes_query) {
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 void MediaRouterMojoImpl::OnPresentationConnectionClosed( 722 void MediaRouterMojoImpl::OnPresentationConnectionClosed(
720 const mojo::String& route_id, 723 const mojo::String& route_id,
721 interfaces::MediaRouter::PresentationConnectionCloseReason reason, 724 interfaces::MediaRouter::PresentationConnectionCloseReason reason,
722 const mojo::String& message) { 725 const mojo::String& message) {
723 NotifyPresentationConnectionClose( 726 NotifyPresentationConnectionClose(
724 route_id, mojo::PresentationConnectionCloseReasonFromMojo(reason), 727 route_id, mojo::PresentationConnectionCloseReasonFromMojo(reason),
725 message); 728 message);
726 } 729 }
727 730
728 void MediaRouterMojoImpl::DoStartObservingMediaSinks( 731 void MediaRouterMojoImpl::DoStartObservingMediaSinks(
729 const MediaSource::Id& source_id) { 732 const MediaSource& source) {
730 DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaSinks: " << source_id; 733 DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaSinks: " << source.id();
731 // No need to call MRPM if there are no sinks available. 734 // No need to call MRPM if there are no sinks available.
732 if (availability_ == interfaces::MediaRouter::SinkAvailability::UNAVAILABLE) 735 if (availability_ == interfaces::MediaRouter::SinkAvailability::UNAVAILABLE)
733 return; 736 return;
734 737
735 // No need to call MRPM if all observers have been removed in the meantime. 738 // No need to call MRPM if all observers have been removed in the meantime.
736 auto* sinks_query = sinks_queries_.get(source_id); 739 auto* sinks_query = sinks_queries_.get(source);
737 if (!sinks_query || !sinks_query->observers.might_have_observers()) 740 if (!sinks_query || !sinks_query->observers.might_have_observers())
738 return; 741 return;
739 742
740 DVLOG_WITH_INSTANCE(1) << "MRPM.StartObservingMediaSinks: " << source_id; 743 DVLOG_WITH_INSTANCE(1) << "MRPM.StartObservingMediaSinks: " << source.id();
741 media_route_provider_->StartObservingMediaSinks(source_id); 744 media_route_provider_->StartObservingMediaSinks(source.id(),
745 source.origin());
742 sinks_query->is_active = true; 746 sinks_query->is_active = true;
743 } 747 }
744 748
745 void MediaRouterMojoImpl::DoStopObservingMediaSinks( 749 void MediaRouterMojoImpl::DoStopObservingMediaSinks(
746 const MediaSource::Id& source_id) { 750 const MediaSource& source) {
747 DVLOG_WITH_INSTANCE(1) << "DoStopObservingMediaSinks: " << source_id; 751 DVLOG_WITH_INSTANCE(1) << "DoStopObservingMediaSinks: " << source.id();
748 752
749 auto* sinks_query = sinks_queries_.get(source_id); 753 auto* sinks_query = sinks_queries_.get(source);
750 // No need to call MRPM if observers have been added in the meantime, 754 // No need to call MRPM if observers have been added in the meantime,
751 // or StopObservingMediaSinks has already been called. 755 // or StopObservingMediaSinks has already been called.
752 if (!sinks_query || !sinks_query->is_active || 756 if (!sinks_query || !sinks_query->is_active ||
753 sinks_query->observers.might_have_observers()) { 757 sinks_query->observers.might_have_observers()) {
754 return; 758 return;
755 } 759 }
756 760
757 DVLOG_WITH_INSTANCE(1) << "MRPM.StopObservingMediaSinks: " << source_id; 761 DVLOG_WITH_INSTANCE(1) << "MRPM.StopObservingMediaSinks: " << source.id();
758 media_route_provider_->StopObservingMediaSinks(source_id); 762 media_route_provider_->StopObservingMediaSinks(source.id(),
759 sinks_queries_.erase(source_id); 763 source.origin());
764 sinks_queries_.erase(source);
760 } 765 }
761 766
762 void MediaRouterMojoImpl::DoStartObservingMediaRoutes( 767 void MediaRouterMojoImpl::DoStartObservingMediaRoutes(
763 const MediaSource::Id& source_id) { 768 const MediaSource::Id& source_id) {
764 DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaRoutes"; 769 DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaRoutes";
765 770
766 // No need to call MRPM if all observers have been removed in the meantime. 771 // No need to call MRPM if all observers have been removed in the meantime.
767 auto* routes_query = routes_queries_.get(source_id); 772 auto* routes_query = routes_queries_.get(source_id);
768 if (!routes_query || !routes_query->observers.might_have_observers()) 773 if (!routes_query || !routes_query->observers.might_have_observers())
769 return; 774 return;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 if (current_wake_reason_ == MediaRouteProviderWakeReason::TOTAL_COUNT) 890 if (current_wake_reason_ == MediaRouteProviderWakeReason::TOTAL_COUNT)
886 current_wake_reason_ = reason; 891 current_wake_reason_ = reason;
887 } 892 }
888 893
889 void MediaRouterMojoImpl::ClearWakeReason() { 894 void MediaRouterMojoImpl::ClearWakeReason() {
890 DCHECK(current_wake_reason_ != MediaRouteProviderWakeReason::TOTAL_COUNT); 895 DCHECK(current_wake_reason_ != MediaRouteProviderWakeReason::TOTAL_COUNT);
891 current_wake_reason_ = MediaRouteProviderWakeReason::TOTAL_COUNT; 896 current_wake_reason_ = MediaRouteProviderWakeReason::TOTAL_COUNT;
892 } 897 }
893 898
894 } // namespace media_router 899 } // namespace media_router
OLDNEW
« no previous file with comments | « chrome/browser/media/router/media_router_mojo_impl.h ('k') | chrome/browser/media/router/media_router_mojo_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698