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

Side by Side Diff: chrome/browser/ui/webui/media_router/query_result_manager.cc

Issue 2627463003: Convert MediaRouter mojom apis to intake url::Origin objects instead of strings (Closed)
Patch Set: Add missing dependency for extensions_renderer_resources target Created 3 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/ui/webui/media_router/query_result_manager.h" 5 #include "chrome/browser/ui/webui/media_router/query_result_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/containers/hash_tables.h" 9 #include "base/containers/hash_tables.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "chrome/browser/media/router/media_router.h" 12 #include "chrome/browser/media/router/media_router.h"
13 #include "chrome/browser/media/router/media_sinks_observer.h" 13 #include "chrome/browser/media/router/media_sinks_observer.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 #include "url/gurl.h" 15 #include "url/origin.h"
16 16
17 namespace media_router { 17 namespace media_router {
18 18
19 // MediaSinkObserver that propagates results back to |result_manager|. 19 // MediaSinkObserver that propagates results back to |result_manager|.
20 // An instance of this class is associated with each registered MediaSource. 20 // An instance of this class is associated with each registered MediaSource.
21 class QueryResultManager::MediaSourceMediaSinksObserver 21 class QueryResultManager::MediaSourceMediaSinksObserver
22 : public MediaSinksObserver { 22 : public MediaSinksObserver {
23 public: 23 public:
24 MediaSourceMediaSinksObserver(MediaCastMode cast_mode, 24 MediaSourceMediaSinksObserver(MediaCastMode cast_mode,
25 const MediaSource& source, 25 const MediaSource& source,
26 const GURL& origin, 26 const url::Origin& origin,
27 MediaRouter* router, 27 MediaRouter* router,
28 QueryResultManager* result_manager) 28 QueryResultManager* result_manager)
29 : MediaSinksObserver(router, source, origin), 29 : MediaSinksObserver(router, source, origin),
30 cast_mode_(cast_mode), 30 cast_mode_(cast_mode),
31 source_(source), 31 source_(source),
32 result_manager_(result_manager) { 32 result_manager_(result_manager) {
33 DCHECK(result_manager); 33 DCHECK(result_manager);
34 } 34 }
35 35
36 ~MediaSourceMediaSinksObserver() override {} 36 ~MediaSourceMediaSinksObserver() override {}
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 void QueryResultManager::RemoveObserver(Observer* observer) { 77 void QueryResultManager::RemoveObserver(Observer* observer) {
78 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 78 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
79 DCHECK(observer); 79 DCHECK(observer);
80 observers_.RemoveObserver(observer); 80 observers_.RemoveObserver(observer);
81 } 81 }
82 82
83 void QueryResultManager::SetSourcesForCastMode( 83 void QueryResultManager::SetSourcesForCastMode(
84 MediaCastMode cast_mode, 84 MediaCastMode cast_mode,
85 const std::vector<MediaSource>& sources, 85 const std::vector<MediaSource>& sources,
86 const GURL& origin) { 86 const url::Origin& origin) {
87 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 87 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
88 if (sources.empty()) { 88 if (sources.empty()) {
89 LOG(WARNING) << "SetSourcesForCastMode called with empty sources for " 89 LOG(WARNING) << "SetSourcesForCastMode called with empty sources for "
90 << cast_mode; 90 << cast_mode;
91 return; 91 return;
92 } 92 }
93 if (!AreSourcesValidForCastMode(cast_mode, sources)) { 93 if (!AreSourcesValidForCastMode(cast_mode, sources)) {
94 LOG(WARNING) << "SetSourcesForCastMode called with invalid sources for " 94 LOG(WARNING) << "SetSourcesForCastMode called with invalid sources for "
95 << cast_mode; 95 << cast_mode;
96 return; 96 return;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 if (!base::ContainsValue(new_sources, source)) { 150 if (!base::ContainsValue(new_sources, source)) {
151 sinks_observers_.erase(source); 151 sinks_observers_.erase(source);
152 SetSinksCompatibleWithSource(cast_mode, source, std::vector<MediaSink>()); 152 SetSinksCompatibleWithSource(cast_mode, source, std::vector<MediaSink>());
153 } 153 }
154 } 154 }
155 } 155 }
156 156
157 void QueryResultManager::AddObserversForCastMode( 157 void QueryResultManager::AddObserversForCastMode(
158 MediaCastMode cast_mode, 158 MediaCastMode cast_mode,
159 const std::vector<MediaSource>& sources, 159 const std::vector<MediaSource>& sources,
160 const GURL& origin) { 160 const url::Origin& origin) {
161 for (const MediaSource& source : sources) { 161 for (const MediaSource& source : sources) {
162 if (!base::ContainsKey(sinks_observers_, source)) { 162 if (!base::ContainsKey(sinks_observers_, source)) {
163 std::unique_ptr<MediaSourceMediaSinksObserver> observer( 163 std::unique_ptr<MediaSourceMediaSinksObserver> observer(
164 new MediaSourceMediaSinksObserver(cast_mode, source, origin, router_, 164 new MediaSourceMediaSinksObserver(cast_mode, source, origin, router_,
165 this)); 165 this));
166 observer->Init(); 166 observer->Init();
167 sinks_observers_[source] = std::move(observer); 167 sinks_observers_[source] = std::move(observer);
168 } 168 }
169 } 169 }
170 } 170 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 for (const auto& sink_pair : all_sinks_) { 230 for (const auto& sink_pair : all_sinks_) {
231 MediaSinkWithCastModes sink_with_cast_modes(sink_pair.first); 231 MediaSinkWithCastModes sink_with_cast_modes(sink_pair.first);
232 sink_with_cast_modes.cast_modes = sink_pair.second.GetCastModes(); 232 sink_with_cast_modes.cast_modes = sink_pair.second.GetCastModes();
233 sinks.push_back(sink_with_cast_modes); 233 sinks.push_back(sink_with_cast_modes);
234 } 234 }
235 for (QueryResultManager::Observer& observer : observers_) 235 for (QueryResultManager::Observer& observer : observers_)
236 observer.OnResultsUpdated(sinks); 236 observer.OnResultsUpdated(sinks);
237 } 237 }
238 238
239 } // namespace media_router 239 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698