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