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

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

Issue 1784533004: [Media Router] Add origins to sink query results. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 mojo::Array<interfaces::MediaSinkPtr> sinks) { 168 mojo::Array<interfaces::MediaSinkPtr> sinks,
169 mojo::Array<mojo::String> origins) {
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 auto it = sinks_queries_.find(media_source);
172 if (it == sinks_queries_.end()) { 173 if (it == sinks_queries_.end()) {
173 DVLOG_WITH_INSTANCE(1) << "Received sink list without MediaSinksQuery."; 174 DVLOG_WITH_INSTANCE(1) << "Received sink list without MediaSinksQuery.";
174 return; 175 return;
175 } 176 }
176 177
177 auto* sinks_query = it->second; 178 auto* sinks_query = it->second;
178 sinks_query->has_cached_result = true; 179 sinks_query->has_cached_result = true;
179 auto& cached_sink_list = sinks_query->cached_sink_list; 180 auto& cached_sink_list = sinks_query->cached_sink_list;
180 cached_sink_list.clear(); 181 cached_sink_list.clear();
181 cached_sink_list.reserve(sinks.size()); 182 cached_sink_list.reserve(sinks.size());
182 for (size_t i = 0; i < sinks.size(); ++i) 183 for (size_t i = 0; i < sinks.size(); ++i)
183 cached_sink_list.push_back(sinks[i].To<MediaSink>()); 184 cached_sink_list.push_back(sinks[i].To<MediaSink>());
184 185
186 auto& origins_list = sinks_query->origins;
187 origins_list.clear();
188 origins_list.reserve(origins.size());
189 for (size_t i = 0; i < origins.size(); ++i) {
190 GURL origin(origins[i].get());
191 DLOG_IF(ERROR, !origin.is_valid()) << "Received invalid origin: " << origin;
192 origins_list.push_back(origin);
mark a. foltz 2016/03/11 01:20:23 If we receive an invalid origin from the MRPM, can
imcheng 2016/03/14 21:30:20 Changed it to do an early return if an origin is i
193 }
194
185 if (!sinks_query->observers.might_have_observers()) { 195 if (!sinks_query->observers.might_have_observers()) {
186 DVLOG_WITH_INSTANCE(1) 196 DVLOG_WITH_INSTANCE(1)
187 << "Received sink list without any active observers: " << media_source; 197 << "Received sink list without any active observers: " << media_source;
188 } else { 198 } else {
189 FOR_EACH_OBSERVER(MediaSinksObserver, sinks_query->observers, 199 FOR_EACH_OBSERVER(MediaSinksObserver, sinks_query->observers,
190 OnSinksReceived(cached_sink_list)); 200 OnSinksUpdated(cached_sink_list, origins_list));
191 } 201 }
192 } 202 }
193 203
194 void MediaRouterMojoImpl::OnRoutesUpdated( 204 void MediaRouterMojoImpl::OnRoutesUpdated(
195 mojo::Array<interfaces::MediaRoutePtr> routes, 205 mojo::Array<interfaces::MediaRoutePtr> routes,
196 const mojo::String& media_source, 206 const mojo::String& media_source,
197 mojo::Array<mojo::String> joinable_route_ids) { 207 mojo::Array<mojo::String> joinable_route_ids) {
198 DCHECK(thread_checker_.CalledOnValidThread()); 208 DCHECK(thread_checker_.CalledOnValidThread());
199 209
200 DVLOG_WITH_INSTANCE(1) << "OnRoutesUpdated"; 210 DVLOG_WITH_INSTANCE(1) << "OnRoutesUpdated";
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 sinks_query = new MediaSinksQuery; 398 sinks_query = new MediaSinksQuery;
389 sinks_queries_.add(source_id, make_scoped_ptr(sinks_query)); 399 sinks_queries_.add(source_id, make_scoped_ptr(sinks_query));
390 } else { 400 } else {
391 DCHECK(!sinks_query->observers.HasObserver(observer)); 401 DCHECK(!sinks_query->observers.HasObserver(observer));
392 } 402 }
393 403
394 // If sink availability is UNAVAILABLE, then there is no need to call MRPM. 404 // If sink availability is UNAVAILABLE, then there is no need to call MRPM.
395 // |observer| can be immediately notified with an empty list. 405 // |observer| can be immediately notified with an empty list.
396 sinks_query->observers.AddObserver(observer); 406 sinks_query->observers.AddObserver(observer);
397 if (availability_ == interfaces::MediaRouter::SinkAvailability::UNAVAILABLE) { 407 if (availability_ == interfaces::MediaRouter::SinkAvailability::UNAVAILABLE) {
398 observer->OnSinksReceived(std::vector<MediaSink>()); 408 observer->OnSinksUpdated(std::vector<MediaSink>(), std::vector<GURL>());
399 } else { 409 } else {
400 // Need to call MRPM to start observing sinks if the query is new. 410 // Need to call MRPM to start observing sinks if the query is new.
401 if (new_query) { 411 if (new_query) {
402 SetWakeReason(MediaRouteProviderWakeReason::START_OBSERVING_MEDIA_SINKS); 412 SetWakeReason(MediaRouteProviderWakeReason::START_OBSERVING_MEDIA_SINKS);
403 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks, 413 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks,
404 base::Unretained(this), source_id)); 414 base::Unretained(this), source_id));
405 } else if (sinks_query->has_cached_result) { 415 } else if (sinks_query->has_cached_result) {
406 observer->OnSinksReceived(sinks_query->cached_sink_list); 416 observer->OnSinksUpdated(sinks_query->cached_sink_list,
mark a. foltz 2016/03/11 01:20:23 It seems like an observer could get an empty list
imcheng 2016/03/14 21:30:20 It should be ok for now. In all cases, the observe
417 sinks_query->origins);
407 } 418 }
408 } 419 }
409 return true; 420 return true;
410 } 421 }
411 422
412 void MediaRouterMojoImpl::UnregisterMediaSinksObserver( 423 void MediaRouterMojoImpl::UnregisterMediaSinksObserver(
413 MediaSinksObserver* observer) { 424 MediaSinksObserver* observer) {
414 DCHECK(thread_checker_.CalledOnValidThread()); 425 DCHECK(thread_checker_.CalledOnValidThread());
415 426
416 const MediaSource::Id& source_id = observer->source().id(); 427 const MediaSource::Id& source_id = observer->source().id();
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 return; 703 return;
693 704
694 availability_ = availability; 705 availability_ = availability;
695 if (availability_ == interfaces::MediaRouter::SinkAvailability::UNAVAILABLE) { 706 if (availability_ == interfaces::MediaRouter::SinkAvailability::UNAVAILABLE) {
696 // Sinks are no longer available. MRPM has already removed all sink queries. 707 // Sinks are no longer available. MRPM has already removed all sink queries.
697 for (auto& source_and_query : sinks_queries_) { 708 for (auto& source_and_query : sinks_queries_) {
698 auto* query = source_and_query.second; 709 auto* query = source_and_query.second;
699 query->is_active = false; 710 query->is_active = false;
700 query->has_cached_result = false; 711 query->has_cached_result = false;
701 query->cached_sink_list.clear(); 712 query->cached_sink_list.clear();
713 query->origins.clear();
702 } 714 }
703 } else { 715 } else {
704 // Sinks are now available. Tell MRPM to start all sink queries again. 716 // Sinks are now available. Tell MRPM to start all sink queries again.
705 for (const auto& source_and_query : sinks_queries_) { 717 for (const auto& source_and_query : sinks_queries_) {
706 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks, 718 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks,
707 base::Unretained(this), source_and_query.first)); 719 base::Unretained(this), source_and_query.first));
708 } 720 }
709 } 721 }
710 } 722 }
711 723
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 if (current_wake_reason_ == MediaRouteProviderWakeReason::TOTAL_COUNT) 897 if (current_wake_reason_ == MediaRouteProviderWakeReason::TOTAL_COUNT)
886 current_wake_reason_ = reason; 898 current_wake_reason_ = reason;
887 } 899 }
888 900
889 void MediaRouterMojoImpl::ClearWakeReason() { 901 void MediaRouterMojoImpl::ClearWakeReason() {
890 DCHECK(current_wake_reason_ != MediaRouteProviderWakeReason::TOTAL_COUNT); 902 DCHECK(current_wake_reason_ != MediaRouteProviderWakeReason::TOTAL_COUNT);
891 current_wake_reason_ = MediaRouteProviderWakeReason::TOTAL_COUNT; 903 current_wake_reason_ = MediaRouteProviderWakeReason::TOTAL_COUNT;
892 } 904 }
893 905
894 } // namespace media_router 906 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698