| 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_base.h" | 5 #include "chrome/browser/media/router/media_router_base.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/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 | 13 |
| 14 namespace media_router { | 14 namespace media_router { |
| 15 | 15 |
| 16 // A MediaRoutesObserver that maintains state about the current set of media | 16 // A MediaRoutesObserver that maintains state about the current set of media |
| 17 // routes. | 17 // routes. |
| 18 class MediaRouterBase::InternalMediaRoutesObserver | 18 class MediaRouterBase::InternalMediaRoutesObserver |
| 19 : public MediaRoutesObserver { | 19 : public MediaRoutesObserver { |
| 20 public: | 20 public: |
| 21 explicit InternalMediaRoutesObserver(MediaRouter* router) | 21 explicit InternalMediaRoutesObserver(MediaRouter* router) |
| 22 : MediaRoutesObserver(router), has_route(false) {} | 22 : MediaRoutesObserver(router), has_route(false) {} |
| 23 ~InternalMediaRoutesObserver() override {} | 23 ~InternalMediaRoutesObserver() override {} |
| 24 | 24 |
| 25 // MediaRoutesObserver | 25 // MediaRoutesObserver |
| 26 void OnRoutesUpdated( | 26 void OnRoutesUpdated( |
| 27 const std::vector<MediaRoute>& routes, | 27 const std::vector<MediaRoute>& routes, |
| 28 const std::vector<MediaRoute::Id>& joinable_route_ids) override { | 28 const std::vector<MediaRoute::Id>& joinable_route_ids) override { |
| 29 off_the_record_route_ids.clear(); | 29 incognito_route_ids.clear(); |
| 30 // TODO(crbug.com/611486): Have the MRPM pass a list of joinable route ids | 30 // TODO(crbug.com/611486): Have the MRPM pass a list of joinable route ids |
| 31 // via |joinable_route_ids|, and check here if it is non-empty. | 31 // via |joinable_route_ids|, and check here if it is non-empty. |
| 32 has_route = !routes.empty(); | 32 has_route = !routes.empty(); |
| 33 for (const auto& route : routes) { | 33 for (const auto& route : routes) { |
| 34 if (route.off_the_record()) | 34 if (route.incognito()) |
| 35 off_the_record_route_ids.push_back(route.media_route_id()); | 35 incognito_route_ids.push_back(route.media_route_id()); |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 | 38 |
| 39 bool has_route; | 39 bool has_route; |
| 40 std::vector<MediaRoute::Id> off_the_record_route_ids; | 40 std::vector<MediaRoute::Id> incognito_route_ids; |
| 41 | 41 |
| 42 private: | 42 private: |
| 43 DISALLOW_COPY_AND_ASSIGN(InternalMediaRoutesObserver); | 43 DISALLOW_COPY_AND_ASSIGN(InternalMediaRoutesObserver); |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 MediaRouterBase::~MediaRouterBase() { | 46 MediaRouterBase::~MediaRouterBase() { |
| 47 CHECK(!internal_routes_observer_); | 47 CHECK(!internal_routes_observer_); |
| 48 } | 48 } |
| 49 | 49 |
| 50 std::unique_ptr<PresentationConnectionStateSubscription> | 50 std::unique_ptr<PresentationConnectionStateSubscription> |
| 51 MediaRouterBase::AddPresentationConnectionStateChangedCallback( | 51 MediaRouterBase::AddPresentationConnectionStateChangedCallback( |
| 52 const MediaRoute::Id& route_id, | 52 const MediaRoute::Id& route_id, |
| 53 const content::PresentationConnectionStateChangedCallback& callback) { | 53 const content::PresentationConnectionStateChangedCallback& callback) { |
| 54 DCHECK(thread_checker_.CalledOnValidThread()); | 54 DCHECK(thread_checker_.CalledOnValidThread()); |
| 55 | 55 |
| 56 auto* callbacks = presentation_connection_state_callbacks_.get(route_id); | 56 auto* callbacks = presentation_connection_state_callbacks_.get(route_id); |
| 57 if (!callbacks) { | 57 if (!callbacks) { |
| 58 callbacks = new PresentationConnectionStateChangedCallbacks; | 58 callbacks = new PresentationConnectionStateChangedCallbacks; |
| 59 callbacks->set_removal_callback(base::Bind( | 59 callbacks->set_removal_callback(base::Bind( |
| 60 &MediaRouterBase::OnPresentationConnectionStateCallbackRemoved, | 60 &MediaRouterBase::OnPresentationConnectionStateCallbackRemoved, |
| 61 base::Unretained(this), route_id)); | 61 base::Unretained(this), route_id)); |
| 62 presentation_connection_state_callbacks_.add(route_id, | 62 presentation_connection_state_callbacks_.add(route_id, |
| 63 base::WrapUnique(callbacks)); | 63 base::WrapUnique(callbacks)); |
| 64 } | 64 } |
| 65 | 65 |
| 66 return callbacks->Add(callback); | 66 return callbacks->Add(callback); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void MediaRouterBase::OnOffTheRecordProfileShutdown() { | 69 void MediaRouterBase::OnIncognitoProfileShutdown() { |
| 70 for (const auto& route_id : | 70 for (const auto& route_id : internal_routes_observer_->incognito_route_ids) |
| 71 internal_routes_observer_->off_the_record_route_ids) | |
| 72 TerminateRoute(route_id); | 71 TerminateRoute(route_id); |
| 73 } | 72 } |
| 74 | 73 |
| 75 MediaRouterBase::MediaRouterBase() : initialized_(false) {} | 74 MediaRouterBase::MediaRouterBase() : initialized_(false) {} |
| 76 | 75 |
| 77 // static | 76 // static |
| 78 std::string MediaRouterBase::CreatePresentationId() { | 77 std::string MediaRouterBase::CreatePresentationId() { |
| 79 return "mr_" + base::GenerateGUID(); | 78 return "mr_" + base::GenerateGUID(); |
| 80 } | 79 } |
| 81 | 80 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 presentation_connection_state_callbacks_.erase(route_id); | 122 presentation_connection_state_callbacks_.erase(route_id); |
| 124 } | 123 } |
| 125 | 124 |
| 126 void MediaRouterBase::Shutdown() { | 125 void MediaRouterBase::Shutdown() { |
| 127 // The observer calls virtual methods on MediaRouter; it must be destroyed | 126 // The observer calls virtual methods on MediaRouter; it must be destroyed |
| 128 // outside of the dtor | 127 // outside of the dtor |
| 129 internal_routes_observer_.reset(); | 128 internal_routes_observer_.reset(); |
| 130 } | 129 } |
| 131 | 130 |
| 132 } // namespace media_router | 131 } // namespace media_router |
| OLD | NEW |