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/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 Loading... | |
| 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 |
| 178 std::vector<GURL> origin_list; | |
| 179 origin_list.reserve(origins.size()); | |
| 180 for (size_t i = 0; i < origins.size(); ++i) { | |
| 181 GURL origin(origins[i].get()); | |
| 182 if (!origin.is_valid()) { | |
| 183 DLOG(ERROR) << "Received invalid origin: " << origin | |
|
mark a. foltz
2016/03/15 00:36:43
Perhaps LOG(WARNING)
imcheng
2016/03/15 01:52:41
Done.
| |
| 184 << ". Dropping result."; | |
| 185 return; | |
| 186 } | |
| 187 origin_list.push_back(origin); | |
| 188 } | |
| 189 | |
| 190 std::vector<MediaSink> sink_list; | |
| 191 sink_list.reserve(sinks.size()); | |
| 192 for (size_t i = 0; i < sinks.size(); ++i) | |
| 193 sink_list.push_back(sinks[i].To<MediaSink>()); | |
| 194 | |
| 177 auto* sinks_query = it->second; | 195 auto* sinks_query = it->second; |
| 178 sinks_query->has_cached_result = true; | 196 sinks_query->has_cached_result = true; |
| 179 auto& cached_sink_list = sinks_query->cached_sink_list; | 197 sinks_query->origins.swap(origin_list); |
| 180 cached_sink_list.clear(); | 198 sinks_query->cached_sink_list.swap(sink_list); |
| 181 cached_sink_list.reserve(sinks.size()); | |
| 182 for (size_t i = 0; i < sinks.size(); ++i) | |
| 183 cached_sink_list.push_back(sinks[i].To<MediaSink>()); | |
| 184 | 199 |
| 185 if (!sinks_query->observers.might_have_observers()) { | 200 if (!sinks_query->observers.might_have_observers()) { |
| 186 DVLOG_WITH_INSTANCE(1) | 201 DVLOG_WITH_INSTANCE(1) |
| 187 << "Received sink list without any active observers: " << media_source; | 202 << "Received sink list without any active observers: " << media_source; |
| 188 } else { | 203 } else { |
| 189 FOR_EACH_OBSERVER(MediaSinksObserver, sinks_query->observers, | 204 FOR_EACH_OBSERVER( |
| 190 OnSinksReceived(cached_sink_list)); | 205 MediaSinksObserver, sinks_query->observers, |
| 206 OnSinksUpdated(sinks_query->cached_sink_list, sinks_query->origins)); | |
| 191 } | 207 } |
| 192 } | 208 } |
| 193 | 209 |
| 194 void MediaRouterMojoImpl::OnRoutesUpdated( | 210 void MediaRouterMojoImpl::OnRoutesUpdated( |
| 195 mojo::Array<interfaces::MediaRoutePtr> routes, | 211 mojo::Array<interfaces::MediaRoutePtr> routes, |
| 196 const mojo::String& media_source, | 212 const mojo::String& media_source, |
| 197 mojo::Array<mojo::String> joinable_route_ids) { | 213 mojo::Array<mojo::String> joinable_route_ids) { |
| 198 DCHECK(thread_checker_.CalledOnValidThread()); | 214 DCHECK(thread_checker_.CalledOnValidThread()); |
| 199 | 215 |
| 200 DVLOG_WITH_INSTANCE(1) << "OnRoutesUpdated"; | 216 DVLOG_WITH_INSTANCE(1) << "OnRoutesUpdated"; |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 sinks_query = new MediaSinksQuery; | 404 sinks_query = new MediaSinksQuery; |
| 389 sinks_queries_.add(source_id, make_scoped_ptr(sinks_query)); | 405 sinks_queries_.add(source_id, make_scoped_ptr(sinks_query)); |
| 390 } else { | 406 } else { |
| 391 DCHECK(!sinks_query->observers.HasObserver(observer)); | 407 DCHECK(!sinks_query->observers.HasObserver(observer)); |
| 392 } | 408 } |
| 393 | 409 |
| 394 // If sink availability is UNAVAILABLE, then there is no need to call MRPM. | 410 // If sink availability is UNAVAILABLE, then there is no need to call MRPM. |
| 395 // |observer| can be immediately notified with an empty list. | 411 // |observer| can be immediately notified with an empty list. |
| 396 sinks_query->observers.AddObserver(observer); | 412 sinks_query->observers.AddObserver(observer); |
| 397 if (availability_ == interfaces::MediaRouter::SinkAvailability::UNAVAILABLE) { | 413 if (availability_ == interfaces::MediaRouter::SinkAvailability::UNAVAILABLE) { |
| 398 observer->OnSinksReceived(std::vector<MediaSink>()); | 414 observer->OnSinksUpdated(std::vector<MediaSink>(), std::vector<GURL>()); |
| 399 } else { | 415 } else { |
| 400 // Need to call MRPM to start observing sinks if the query is new. | 416 // Need to call MRPM to start observing sinks if the query is new. |
| 401 if (new_query) { | 417 if (new_query) { |
| 402 SetWakeReason(MediaRouteProviderWakeReason::START_OBSERVING_MEDIA_SINKS); | 418 SetWakeReason(MediaRouteProviderWakeReason::START_OBSERVING_MEDIA_SINKS); |
| 403 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks, | 419 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks, |
| 404 base::Unretained(this), source_id)); | 420 base::Unretained(this), source_id)); |
| 405 } else if (sinks_query->has_cached_result) { | 421 } else if (sinks_query->has_cached_result) { |
| 406 observer->OnSinksReceived(sinks_query->cached_sink_list); | 422 observer->OnSinksUpdated(sinks_query->cached_sink_list, |
| 423 sinks_query->origins); | |
| 407 } | 424 } |
| 408 } | 425 } |
| 409 return true; | 426 return true; |
| 410 } | 427 } |
| 411 | 428 |
| 412 void MediaRouterMojoImpl::UnregisterMediaSinksObserver( | 429 void MediaRouterMojoImpl::UnregisterMediaSinksObserver( |
| 413 MediaSinksObserver* observer) { | 430 MediaSinksObserver* observer) { |
| 414 DCHECK(thread_checker_.CalledOnValidThread()); | 431 DCHECK(thread_checker_.CalledOnValidThread()); |
| 415 | 432 |
| 416 const MediaSource::Id& source_id = observer->source().id(); | 433 const MediaSource::Id& source_id = observer->source().id(); |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 692 return; | 709 return; |
| 693 | 710 |
| 694 availability_ = availability; | 711 availability_ = availability; |
| 695 if (availability_ == interfaces::MediaRouter::SinkAvailability::UNAVAILABLE) { | 712 if (availability_ == interfaces::MediaRouter::SinkAvailability::UNAVAILABLE) { |
| 696 // Sinks are no longer available. MRPM has already removed all sink queries. | 713 // Sinks are no longer available. MRPM has already removed all sink queries. |
| 697 for (auto& source_and_query : sinks_queries_) { | 714 for (auto& source_and_query : sinks_queries_) { |
| 698 auto* query = source_and_query.second; | 715 auto* query = source_and_query.second; |
| 699 query->is_active = false; | 716 query->is_active = false; |
| 700 query->has_cached_result = false; | 717 query->has_cached_result = false; |
| 701 query->cached_sink_list.clear(); | 718 query->cached_sink_list.clear(); |
| 719 query->origins.clear(); | |
| 702 } | 720 } |
| 703 } else { | 721 } else { |
| 704 // Sinks are now available. Tell MRPM to start all sink queries again. | 722 // Sinks are now available. Tell MRPM to start all sink queries again. |
| 705 for (const auto& source_and_query : sinks_queries_) { | 723 for (const auto& source_and_query : sinks_queries_) { |
| 706 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks, | 724 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks, |
| 707 base::Unretained(this), source_and_query.first)); | 725 base::Unretained(this), source_and_query.first)); |
| 708 } | 726 } |
| 709 } | 727 } |
| 710 } | 728 } |
| 711 | 729 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 885 if (current_wake_reason_ == MediaRouteProviderWakeReason::TOTAL_COUNT) | 903 if (current_wake_reason_ == MediaRouteProviderWakeReason::TOTAL_COUNT) |
| 886 current_wake_reason_ = reason; | 904 current_wake_reason_ = reason; |
| 887 } | 905 } |
| 888 | 906 |
| 889 void MediaRouterMojoImpl::ClearWakeReason() { | 907 void MediaRouterMojoImpl::ClearWakeReason() { |
| 890 DCHECK(current_wake_reason_ != MediaRouteProviderWakeReason::TOTAL_COUNT); | 908 DCHECK(current_wake_reason_ != MediaRouteProviderWakeReason::TOTAL_COUNT); |
| 891 current_wake_reason_ = MediaRouteProviderWakeReason::TOTAL_COUNT; | 909 current_wake_reason_ = MediaRouteProviderWakeReason::TOTAL_COUNT; |
| 892 } | 910 } |
| 893 | 911 |
| 894 } // namespace media_router | 912 } // namespace media_router |
| OLD | NEW |