| 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/media/router/mojo/media_route_controller.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 14 | 15 |
| 15 namespace media_router { | 16 namespace media_router { |
| 16 | 17 |
| 17 // A MediaRoutesObserver that maintains state about the current set of media | 18 // A MediaRoutesObserver that maintains state about the current set of media |
| 18 // routes. | 19 // routes. |
| 19 class MediaRouterBase::InternalMediaRoutesObserver | 20 class MediaRouterBase::InternalMediaRoutesObserver |
| 20 : public MediaRoutesObserver { | 21 : public MediaRoutesObserver { |
| 21 public: | 22 public: |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 70 |
| 70 void MediaRouterBase::OnIncognitoProfileShutdown() { | 71 void MediaRouterBase::OnIncognitoProfileShutdown() { |
| 71 for (const auto& route_id : internal_routes_observer_->incognito_route_ids) | 72 for (const auto& route_id : internal_routes_observer_->incognito_route_ids) |
| 72 TerminateRoute(route_id); | 73 TerminateRoute(route_id); |
| 73 } | 74 } |
| 74 | 75 |
| 75 std::vector<MediaRoute> MediaRouterBase::GetCurrentRoutes() const { | 76 std::vector<MediaRoute> MediaRouterBase::GetCurrentRoutes() const { |
| 76 return internal_routes_observer_->current_routes; | 77 return internal_routes_observer_->current_routes; |
| 77 } | 78 } |
| 78 | 79 |
| 80 scoped_refptr<MediaRouteController> MediaRouterBase::GetRouteController( |
| 81 const MediaRoute::Id& route_id) { |
| 82 return nullptr; |
| 83 } |
| 84 |
| 79 MediaRouterBase::MediaRouterBase() : initialized_(false) {} | 85 MediaRouterBase::MediaRouterBase() : initialized_(false) {} |
| 80 | 86 |
| 81 // static | 87 // static |
| 82 std::string MediaRouterBase::CreatePresentationId() { | 88 std::string MediaRouterBase::CreatePresentationId() { |
| 83 return "mr_" + base::GenerateGUID(); | 89 return "mr_" + base::GenerateGUID(); |
| 84 } | 90 } |
| 85 | 91 |
| 86 void MediaRouterBase::NotifyPresentationConnectionStateChange( | 92 void MediaRouterBase::NotifyPresentationConnectionStateChange( |
| 87 const MediaRoute::Id& route_id, | 93 const MediaRoute::Id& route_id, |
| 88 content::PresentationConnectionState state) { | 94 content::PresentationConnectionState state) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 108 content::PRESENTATION_CONNECTION_STATE_CLOSED); | 114 content::PRESENTATION_CONNECTION_STATE_CLOSED); |
| 109 info.close_reason = reason; | 115 info.close_reason = reason; |
| 110 info.message = message; | 116 info.message = message; |
| 111 it->second->Notify(info); | 117 it->second->Notify(info); |
| 112 } | 118 } |
| 113 | 119 |
| 114 bool MediaRouterBase::HasJoinableRoute() const { | 120 bool MediaRouterBase::HasJoinableRoute() const { |
| 115 return internal_routes_observer_->has_route; | 121 return internal_routes_observer_->has_route; |
| 116 } | 122 } |
| 117 | 123 |
| 124 bool MediaRouterBase::IsRouteKnown(const std::string& route_id) const { |
| 125 const auto& routes = internal_routes_observer_->current_routes; |
| 126 return std::find_if(routes.begin(), routes.end(), |
| 127 [&route_id](const MediaRoute& route) { |
| 128 return route.media_route_id() == route_id; |
| 129 }) != routes.end(); |
| 130 } |
| 131 |
| 118 void MediaRouterBase::Initialize() { | 132 void MediaRouterBase::Initialize() { |
| 119 DCHECK(!initialized_); | 133 DCHECK(!initialized_); |
| 120 // The observer calls virtual methods on MediaRouter; it must be created | 134 // The observer calls virtual methods on MediaRouter; it must be created |
| 121 // outside of the ctor | 135 // outside of the ctor |
| 122 internal_routes_observer_.reset(new InternalMediaRoutesObserver(this)); | 136 internal_routes_observer_.reset(new InternalMediaRoutesObserver(this)); |
| 123 initialized_ = true; | 137 initialized_ = true; |
| 124 } | 138 } |
| 125 | 139 |
| 126 void MediaRouterBase::OnPresentationConnectionStateCallbackRemoved( | 140 void MediaRouterBase::OnPresentationConnectionStateCallbackRemoved( |
| 127 const MediaRoute::Id& route_id) { | 141 const MediaRoute::Id& route_id) { |
| 128 auto it = presentation_connection_state_callbacks_.find(route_id); | 142 auto it = presentation_connection_state_callbacks_.find(route_id); |
| 129 if (it != presentation_connection_state_callbacks_.end() && | 143 if (it != presentation_connection_state_callbacks_.end() && |
| 130 it->second->empty()) { | 144 it->second->empty()) { |
| 131 presentation_connection_state_callbacks_.erase(route_id); | 145 presentation_connection_state_callbacks_.erase(route_id); |
| 132 } | 146 } |
| 133 } | 147 } |
| 134 | 148 |
| 135 void MediaRouterBase::Shutdown() { | 149 void MediaRouterBase::Shutdown() { |
| 136 // The observer calls virtual methods on MediaRouter; it must be destroyed | 150 // The observer calls virtual methods on MediaRouter; it must be destroyed |
| 137 // outside of the dtor | 151 // outside of the dtor |
| 138 internal_routes_observer_.reset(); | 152 internal_routes_observer_.reset(); |
| 139 } | 153 } |
| 140 | 154 |
| 155 void MediaRouterBase::DetachRouteController(const MediaRoute::Id& route_id, |
| 156 MediaRouteController* controller) {} |
| 157 |
| 141 } // namespace media_router | 158 } // namespace media_router |
| OLD | NEW |