| 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_local_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 off_the_record_route_ids.clear(); |
| 30 has_local_route = false; | 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. |
| 32 has_route = !routes.empty(); |
| 31 for (const auto& route : routes) { | 33 for (const auto& route : routes) { |
| 32 has_local_route |= route.is_local(); | |
| 33 if (route.off_the_record()) | 34 if (route.off_the_record()) |
| 34 off_the_record_route_ids.push_back(route.media_route_id()); | 35 off_the_record_route_ids.push_back(route.media_route_id()); |
| 35 } | 36 } |
| 36 } | 37 } |
| 37 | 38 |
| 38 bool has_local_route; | 39 bool has_route; |
| 39 std::vector<MediaRoute::Id> off_the_record_route_ids; | 40 std::vector<MediaRoute::Id> off_the_record_route_ids; |
| 40 | 41 |
| 41 private: | 42 private: |
| 42 DISALLOW_COPY_AND_ASSIGN(InternalMediaRoutesObserver); | 43 DISALLOW_COPY_AND_ASSIGN(InternalMediaRoutesObserver); |
| 43 }; | 44 }; |
| 44 | 45 |
| 45 MediaRouterBase::~MediaRouterBase() { | 46 MediaRouterBase::~MediaRouterBase() { |
| 46 CHECK(!internal_routes_observer_); | 47 CHECK(!internal_routes_observer_); |
| 47 } | 48 } |
| 48 | 49 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 if (!callbacks) | 97 if (!callbacks) |
| 97 return; | 98 return; |
| 98 | 99 |
| 99 content::PresentationConnectionStateChangeInfo info( | 100 content::PresentationConnectionStateChangeInfo info( |
| 100 content::PRESENTATION_CONNECTION_STATE_CLOSED); | 101 content::PRESENTATION_CONNECTION_STATE_CLOSED); |
| 101 info.close_reason = reason; | 102 info.close_reason = reason; |
| 102 info.message = message; | 103 info.message = message; |
| 103 callbacks->Notify(info); | 104 callbacks->Notify(info); |
| 104 } | 105 } |
| 105 | 106 |
| 106 bool MediaRouterBase::HasLocalRoute() const { | 107 bool MediaRouterBase::HasJoinableRoute() const { |
| 107 return internal_routes_observer_->has_local_route; | 108 return internal_routes_observer_->has_route; |
| 108 } | 109 } |
| 109 | 110 |
| 110 void MediaRouterBase::Initialize() { | 111 void MediaRouterBase::Initialize() { |
| 111 DCHECK(!initialized_); | 112 DCHECK(!initialized_); |
| 112 // The observer calls virtual methods on MediaRouter; it must be created | 113 // The observer calls virtual methods on MediaRouter; it must be created |
| 113 // outside of the ctor | 114 // outside of the ctor |
| 114 internal_routes_observer_.reset(new InternalMediaRoutesObserver(this)); | 115 internal_routes_observer_.reset(new InternalMediaRoutesObserver(this)); |
| 115 initialized_ = true; | 116 initialized_ = true; |
| 116 } | 117 } |
| 117 | 118 |
| 118 void MediaRouterBase::OnPresentationConnectionStateCallbackRemoved( | 119 void MediaRouterBase::OnPresentationConnectionStateCallbackRemoved( |
| 119 const MediaRoute::Id& route_id) { | 120 const MediaRoute::Id& route_id) { |
| 120 auto* callbacks = presentation_connection_state_callbacks_.get(route_id); | 121 auto* callbacks = presentation_connection_state_callbacks_.get(route_id); |
| 121 if (callbacks && callbacks->empty()) | 122 if (callbacks && callbacks->empty()) |
| 122 presentation_connection_state_callbacks_.erase(route_id); | 123 presentation_connection_state_callbacks_.erase(route_id); |
| 123 } | 124 } |
| 124 | 125 |
| 125 void MediaRouterBase::Shutdown() { | 126 void MediaRouterBase::Shutdown() { |
| 126 // The observer calls virtual methods on MediaRouter; it must be destroyed | 127 // The observer calls virtual methods on MediaRouter; it must be destroyed |
| 127 // outside of the dtor | 128 // outside of the dtor |
| 128 internal_routes_observer_.reset(); | 129 internal_routes_observer_.reset(); |
| 129 } | 130 } |
| 130 | 131 |
| 131 } // namespace media_router | 132 } // namespace media_router |
| OLD | NEW |