OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/media/router/media_router_base.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 |
| 9 namespace media_router { |
| 10 |
| 11 MediaRouterBase::MediaRouterBase() = default; |
| 12 |
| 13 MediaRouterBase::~MediaRouterBase() = default; |
| 14 |
| 15 scoped_ptr<PresentationConnectionStateSubscription> |
| 16 MediaRouterBase::AddPresentationConnectionStateChangedCallback( |
| 17 const MediaRoute::Id& route_id, |
| 18 const content::PresentationConnectionStateChangedCallback& callback) { |
| 19 DCHECK(thread_checker_.CalledOnValidThread()); |
| 20 |
| 21 auto* callbacks = presentation_connection_state_callbacks_.get(route_id); |
| 22 if (!callbacks) { |
| 23 callbacks = new PresentationConnectionStateChangedCallbacks; |
| 24 callbacks->set_removal_callback(base::Bind( |
| 25 &MediaRouterBase::OnPresentationConnectionStateCallbackRemoved, |
| 26 base::Unretained(this), route_id)); |
| 27 presentation_connection_state_callbacks_.add(route_id, |
| 28 make_scoped_ptr(callbacks)); |
| 29 } |
| 30 |
| 31 return callbacks->Add(callback); |
| 32 } |
| 33 |
| 34 void MediaRouterBase::NotifyPresentationConnectionStateChange( |
| 35 const MediaRoute::Id& route_id, |
| 36 content::PresentationConnectionState state) { |
| 37 auto* callbacks = presentation_connection_state_callbacks_.get(route_id); |
| 38 if (!callbacks) |
| 39 return; |
| 40 |
| 41 callbacks->Notify(state); |
| 42 } |
| 43 |
| 44 void MediaRouterBase::OnPresentationConnectionStateCallbackRemoved( |
| 45 const MediaRoute::Id& route_id) { |
| 46 auto* callbacks = presentation_connection_state_callbacks_.get(route_id); |
| 47 if (callbacks && callbacks->empty()) |
| 48 presentation_connection_state_callbacks_.erase(route_id); |
| 49 } |
| 50 |
| 51 } // namespace media_router |
OLD | NEW |