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

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

Issue 1376703002: Presentation API: reject screen availability observing on Android low ram devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix and add tests Created 5 years, 2 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/guid.h" 8 #include "base/guid.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 issue_manager_.ClearIssue(issue_id); 268 issue_manager_.ClearIssue(issue_id);
269 } 269 }
270 270
271 void MediaRouterMojoImpl::OnPresentationSessionDetached( 271 void MediaRouterMojoImpl::OnPresentationSessionDetached(
272 const MediaRoute::Id& route_id) { 272 const MediaRoute::Id& route_id) {
273 DCHECK(thread_checker_.CalledOnValidThread()); 273 DCHECK(thread_checker_.CalledOnValidThread());
274 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoOnPresentationSessionDetached, 274 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoOnPresentationSessionDetached,
275 base::Unretained(this), route_id)); 275 base::Unretained(this), route_id));
276 } 276 }
277 277
278 void MediaRouterMojoImpl::RegisterMediaSinksObserver( 278 bool MediaRouterMojoImpl::RegisterMediaSinksObserver(
279 MediaSinksObserver* observer) { 279 MediaSinksObserver* observer) {
280 DCHECK(thread_checker_.CalledOnValidThread()); 280 DCHECK(thread_checker_.CalledOnValidThread());
281 281
282 // Create an observer list for the media source and add |observer| 282 // Create an observer list for the media source and add |observer|
283 // to it. Fail if |observer| is already registered. 283 // to it. Fail if |observer| is already registered.
284 const std::string& source_id = observer->source().id(); 284 const std::string& source_id = observer->source().id();
285 base::ObserverList<MediaSinksObserver>* observer_list = 285 base::ObserverList<MediaSinksObserver>* observer_list =
286 sinks_observers_.get(source_id); 286 sinks_observers_.get(source_id);
287 if (!observer_list) { 287 if (!observer_list) {
288 observer_list = new base::ObserverList<MediaSinksObserver>; 288 observer_list = new base::ObserverList<MediaSinksObserver>;
289 sinks_observers_.add(source_id, make_scoped_ptr(observer_list)); 289 sinks_observers_.add(source_id, make_scoped_ptr(observer_list));
290 } else { 290 } else {
291 DCHECK(!observer_list->HasObserver(observer)); 291 DCHECK(!observer_list->HasObserver(observer));
292 } 292 }
293 293
294 // We need to call DoStartObservingMediaSinks every time an observer is 294 // We need to call DoStartObservingMediaSinks every time an observer is
295 // added to ensure the observer will be notified with a fresh set of results. 295 // added to ensure the observer will be notified with a fresh set of results.
296 // TODO(imcheng): Implement caching. (crbug.com/492451) 296 // TODO(imcheng): Implement caching. (crbug.com/492451)
297 observer_list->AddObserver(observer); 297 observer_list->AddObserver(observer);
298 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks, 298 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks,
299 base::Unretained(this), source_id)); 299 base::Unretained(this), source_id));
300 return true;
300 } 301 }
301 302
302 void MediaRouterMojoImpl::UnregisterMediaSinksObserver( 303 void MediaRouterMojoImpl::UnregisterMediaSinksObserver(
303 MediaSinksObserver* observer) { 304 MediaSinksObserver* observer) {
304 DCHECK(thread_checker_.CalledOnValidThread()); 305 DCHECK(thread_checker_.CalledOnValidThread());
305 306
306 const MediaSource::Id& source_id = observer->source().id(); 307 const MediaSource::Id& source_id = observer->source().id();
307 auto* observer_list = sinks_observers_.get(source_id); 308 auto* observer_list = sinks_observers_.get(source_id);
308 if (!observer_list || !observer_list->HasObserver(observer)) { 309 if (!observer_list || !observer_list->HasObserver(observer)) {
309 return; 310 return;
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 return; 584 return;
584 } 585 }
585 586
586 for (const auto& next_request : pending_requests_) 587 for (const auto& next_request : pending_requests_)
587 next_request.Run(); 588 next_request.Run();
588 589
589 pending_requests_.clear(); 590 pending_requests_.clear();
590 } 591 }
591 592
592 } // namespace media_router 593 } // 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