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