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

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: Ready for Review Created 4 years, 10 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 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 407
408 void MediaRouterMojoImpl::ClearIssue(const Issue::Id& issue_id) { 408 void MediaRouterMojoImpl::ClearIssue(const Issue::Id& issue_id) {
409 DCHECK(thread_checker_.CalledOnValidThread()); 409 DCHECK(thread_checker_.CalledOnValidThread());
410 issue_manager_.ClearIssue(issue_id); 410 issue_manager_.ClearIssue(issue_id);
411 } 411 }
412 412
413 bool MediaRouterMojoImpl::RegisterMediaSinksObserver( 413 bool MediaRouterMojoImpl::RegisterMediaSinksObserver(
414 MediaSinksObserver* observer) { 414 MediaSinksObserver* observer) {
415 DCHECK(thread_checker_.CalledOnValidThread()); 415 DCHECK(thread_checker_.CalledOnValidThread());
416 416
417 const GURL& origin = observer->origin();
418 DCHECK(origin.is_valid());
mark a. foltz 2016/02/17 21:50:51 You might want to DCHECK or LOG(WARNING) that the
matt.boetger 2016/02/18 00:50:33 Done.
417 // Create an observer list for the media source and add |observer| 419 // Create an observer list for the media source and add |observer|
418 // to it. Fail if |observer| is already registered. 420 // to it. Fail if |observer| is already registered.
419 const std::string& source_id = observer->source().id(); 421 const std::string& source_id = observer->source().id();
420 auto* sinks_query = sinks_queries_.get(source_id); 422 auto* sinks_query = sinks_queries_.get(source_id);
421 bool new_query = false; 423 bool new_query = false;
422 if (!sinks_query) { 424 if (!sinks_query) {
423 new_query = true; 425 new_query = true;
424 sinks_query = new MediaSinksQuery; 426 sinks_query = new MediaSinksQuery;
427 sinks_query->origin = origin;
425 sinks_queries_.add(source_id, make_scoped_ptr(sinks_query)); 428 sinks_queries_.add(source_id, make_scoped_ptr(sinks_query));
426 } else { 429 } else {
427 DCHECK(!sinks_query->observers.HasObserver(observer)); 430 DCHECK(!sinks_query->observers.HasObserver(observer));
428 } 431 }
429 432
433
mark a. foltz 2016/02/17 21:50:51 Extra newline
matt.boetger 2016/02/18 00:50:33 Done.
430 // If sink availability is UNAVAILABLE, then there is no need to call MRPM. 434 // If sink availability is UNAVAILABLE, then there is no need to call MRPM.
431 // |observer| can be immediately notified with an empty list. 435 // |observer| can be immediately notified with an empty list.
432 sinks_query->observers.AddObserver(observer); 436 sinks_query->observers.AddObserver(observer);
433 if (availability_ == interfaces::MediaRouter::SinkAvailability::UNAVAILABLE) { 437 if (availability_ == interfaces::MediaRouter::SinkAvailability::UNAVAILABLE) {
434 observer->OnSinksReceived(std::vector<MediaSink>()); 438 observer->OnSinksReceived(std::vector<MediaSink>());
435 } else { 439 } else {
436 // Need to call MRPM to start observing sinks if the query is new. 440 // Need to call MRPM to start observing sinks if the query is new.
437 if (new_query) { 441 if (new_query) {
438 SetWakeReason(MediaRouteProviderWakeReason::START_OBSERVING_MEDIA_SINKS); 442 SetWakeReason(MediaRouteProviderWakeReason::START_OBSERVING_MEDIA_SINKS);
439 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks, 443 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks,
440 base::Unretained(this), source_id)); 444 base::Unretained(this), source_id, origin));
441 } else if (sinks_query->has_cached_result) { 445 } else if (sinks_query->has_cached_result) {
442 observer->OnSinksReceived(sinks_query->cached_sink_list); 446 observer->OnSinksReceived(sinks_query->cached_sink_list);
443 } 447 }
444 } 448 }
445 return true; 449 return true;
446 } 450 }
447 451
448 void MediaRouterMojoImpl::UnregisterMediaSinksObserver( 452 void MediaRouterMojoImpl::UnregisterMediaSinksObserver(
449 MediaSinksObserver* observer) { 453 MediaSinksObserver* observer) {
450 DCHECK(thread_checker_.CalledOnValidThread()); 454 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 for (auto& source_and_query : sinks_queries_) { 743 for (auto& source_and_query : sinks_queries_) {
740 auto* query = source_and_query.second; 744 auto* query = source_and_query.second;
741 query->is_active = false; 745 query->is_active = false;
742 query->has_cached_result = false; 746 query->has_cached_result = false;
743 query->cached_sink_list.clear(); 747 query->cached_sink_list.clear();
744 } 748 }
745 } else { 749 } else {
746 // Sinks are now available. Tell MRPM to start all sink queries again. 750 // Sinks are now available. Tell MRPM to start all sink queries again.
747 for (const auto& source_and_query : sinks_queries_) { 751 for (const auto& source_and_query : sinks_queries_) {
748 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks, 752 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks,
749 base::Unretained(this), source_and_query.first)); 753 base::Unretained(this), source_and_query.first,
754 source_and_query.second->origin));
750 } 755 }
751 } 756 }
752 } 757 }
753 758
754 void MediaRouterMojoImpl::OnPresentationConnectionStateChanged( 759 void MediaRouterMojoImpl::OnPresentationConnectionStateChanged(
755 const mojo::String& route_id, 760 const mojo::String& route_id,
756 interfaces::MediaRouter::PresentationConnectionState state) { 761 interfaces::MediaRouter::PresentationConnectionState state) {
757 NotifyPresentationConnectionStateChange( 762 NotifyPresentationConnectionStateChange(
758 route_id, mojo::PresentationConnectionStateFromMojo(state)); 763 route_id, mojo::PresentationConnectionStateFromMojo(state));
759 } 764 }
760 765
761 bool MediaRouterMojoImpl::HasLocalDisplayRoute() const { 766 bool MediaRouterMojoImpl::HasLocalDisplayRoute() const {
762 return has_local_display_route_; 767 return has_local_display_route_;
763 } 768 }
764 769
765 void MediaRouterMojoImpl::DoStartObservingMediaSinks( 770 void MediaRouterMojoImpl::DoStartObservingMediaSinks(
766 const MediaSource::Id& source_id) { 771 const MediaSource::Id& source_id, const GURL& origin) {
772 DCHECK(origin.is_valid());
767 DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaSinks: " << source_id; 773 DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaSinks: " << source_id;
768 // No need to call MRPM if there are no sinks available. 774 // No need to call MRPM if there are no sinks available.
769 if (availability_ == interfaces::MediaRouter::SinkAvailability::UNAVAILABLE) 775 if (availability_ == interfaces::MediaRouter::SinkAvailability::UNAVAILABLE)
770 return; 776 return;
771 777
772 // No need to call MRPM if all observers have been removed in the meantime. 778 // No need to call MRPM if all observers have been removed in the meantime.
773 auto* sinks_query = sinks_queries_.get(source_id); 779 auto* sinks_query = sinks_queries_.get(source_id);
774 if (!sinks_query || !sinks_query->observers.might_have_observers()) 780 if (!sinks_query || !sinks_query->observers.might_have_observers())
775 return; 781 return;
776 782
777 DVLOG_WITH_INSTANCE(1) << "MRPM.StartObservingMediaSinks: " << source_id; 783 DVLOG_WITH_INSTANCE(1) << "MRPM.StartObservingMediaSinks: " << source_id;
778 media_route_provider_->StartObservingMediaSinks(source_id); 784 media_route_provider_->StartObservingMediaSinks(source_id,
785 origin.is_empty() ? "" : origin.spec());
779 sinks_query->is_active = true; 786 sinks_query->is_active = true;
780 } 787 }
781 788
782 void MediaRouterMojoImpl::DoStopObservingMediaSinks( 789 void MediaRouterMojoImpl::DoStopObservingMediaSinks(
783 const MediaSource::Id& source_id) { 790 const MediaSource::Id& source_id) {
784 DVLOG_WITH_INSTANCE(1) << "DoStopObservingMediaSinks: " << source_id; 791 DVLOG_WITH_INSTANCE(1) << "DoStopObservingMediaSinks: " << source_id;
785 792
786 auto* sinks_query = sinks_queries_.get(source_id); 793 auto* sinks_query = sinks_queries_.get(source_id);
787 // No need to call MRPM if observers have been added in the meantime, 794 // No need to call MRPM if observers have been added in the meantime,
788 // or StopObservingMediaSinks has already been called. 795 // or StopObservingMediaSinks has already been called.
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 if (current_wake_reason_ == MediaRouteProviderWakeReason::TOTAL_COUNT) 929 if (current_wake_reason_ == MediaRouteProviderWakeReason::TOTAL_COUNT)
923 current_wake_reason_ = reason; 930 current_wake_reason_ = reason;
924 } 931 }
925 932
926 void MediaRouterMojoImpl::ClearWakeReason() { 933 void MediaRouterMojoImpl::ClearWakeReason() {
927 DCHECK(current_wake_reason_ != MediaRouteProviderWakeReason::TOTAL_COUNT); 934 DCHECK(current_wake_reason_ != MediaRouteProviderWakeReason::TOTAL_COUNT);
928 current_wake_reason_ = MediaRouteProviderWakeReason::TOTAL_COUNT; 935 current_wake_reason_ = MediaRouteProviderWakeReason::TOTAL_COUNT;
929 } 936 }
930 937
931 } // namespace media_router 938 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698