Chromium Code Reviews| Index: chrome/browser/media/router/media_router_base.cc |
| diff --git a/chrome/browser/media/router/media_router_base.cc b/chrome/browser/media/router/media_router_base.cc |
| index 21de5782357a8695823150c43a1c8c1893452ae8..628d994b588fc640975c794156d3c88be315152b 100644 |
| --- a/chrome/browser/media/router/media_router_base.cc |
| +++ b/chrome/browser/media/router/media_router_base.cc |
| @@ -13,9 +13,7 @@ |
| namespace media_router { |
| -MediaRouterBase::MediaRouterBase() = default; |
| - |
| -MediaRouterBase::~MediaRouterBase() = default; |
| +MediaRouterBase::~MediaRouterBase() {} |
|
imcheng
2016/04/25 18:59:54
suggestion: Add a CHECK(!internal_routes_observer_
mark a. foltz
2016/04/26 21:11:10
Done.
|
| std::unique_ptr<PresentationConnectionStateSubscription> |
| MediaRouterBase::AddPresentationConnectionStateChangedCallback( |
| @@ -37,20 +35,13 @@ MediaRouterBase::AddPresentationConnectionStateChangedCallback( |
| } |
| void MediaRouterBase::OnOffTheRecordProfileShutdown() { |
| - // TODO(mfoltz): There is a race condition where off-the-record routes created |
| - // by pending CreateRoute requests won't be terminated. Fixing this would |
| - // extra bookeeping of route requests in progress, and a way to cancel them |
| - // in-flight. |
| - for (auto route_ids_it = off_the_record_route_ids_.begin(); |
| - route_ids_it != off_the_record_route_ids_.end(); |
| - /* no-op */) { |
| - // TerminateRoute will erase |route_id| from |off_the_record_route_ids_|, |
| - // make a copy as the iterator will be invalidated. |
| - const MediaRoute::Id route_id = *route_ids_it++; |
| + for (const auto& route_id : |
| + internal_routes_observer_->off_the_record_route_ids) |
| TerminateRoute(route_id); |
| - } |
| } |
| +MediaRouterBase::MediaRouterBase() : initialized_(false) {} |
| + |
| // static |
| std::string MediaRouterBase::CreatePresentationId() { |
| return "mr_" + base::GenerateGUID(); |
| @@ -59,9 +50,6 @@ std::string MediaRouterBase::CreatePresentationId() { |
| void MediaRouterBase::NotifyPresentationConnectionStateChange( |
| const MediaRoute::Id& route_id, |
| content::PresentationConnectionState state) { |
| - if (state == content::PRESENTATION_CONNECTION_STATE_TERMINATED) |
| - OnRouteTerminated(route_id); |
| - |
| auto* callbacks = presentation_connection_state_callbacks_.get(route_id); |
| if (!callbacks) |
| return; |
| @@ -84,15 +72,34 @@ void MediaRouterBase::NotifyPresentationConnectionClose( |
| callbacks->Notify(info); |
| } |
| -void MediaRouterBase::OnOffTheRecordRouteCreated( |
| - const MediaRoute::Id& route_id) { |
| - DCHECK(!ContainsKey(off_the_record_route_ids_, route_id)); |
| - off_the_record_route_ids_.insert(route_id); |
| +bool MediaRouterBase::HasLocalRoute() const { |
| + return internal_routes_observer_->has_local_route; |
| } |
| -void MediaRouterBase::OnRouteTerminated(const MediaRoute::Id& route_id) { |
| - // NOTE: This is called for all routes (off the record or not). |
| - off_the_record_route_ids_.erase(route_id); |
| +void MediaRouterBase::Initialize() { |
| + DCHECK(!initialized_); |
| + // The observer calls virtual methods on MediaRouter; it must be created |
| + // outside of the ctor |
| + internal_routes_observer_.reset(new InternalMediaRoutesObserver(this)); |
| + initialized_ = true; |
| +} |
| + |
| +MediaRouterBase::InternalMediaRoutesObserver::InternalMediaRoutesObserver( |
| + MediaRouter* router) |
| + : MediaRoutesObserver(router), has_local_route(false) {} |
| + |
| +MediaRouterBase::InternalMediaRoutesObserver::~InternalMediaRoutesObserver() {} |
| + |
| +void MediaRouterBase::InternalMediaRoutesObserver::OnRoutesUpdated( |
| + const std::vector<MediaRoute>& routes, |
| + const std::vector<MediaRoute::Id>& joinable_route_ids) { |
| + off_the_record_route_ids.clear(); |
| + has_local_route = false; |
| + for (const auto& route : routes) { |
| + has_local_route |= route.is_local(); |
| + if (route.off_the_record()) |
| + off_the_record_route_ids.push_back(route.media_route_id()); |
| + } |
| } |
| void MediaRouterBase::OnPresentationConnectionStateCallbackRemoved( |
| @@ -102,4 +109,10 @@ void MediaRouterBase::OnPresentationConnectionStateCallbackRemoved( |
| presentation_connection_state_callbacks_.erase(route_id); |
| } |
| +void MediaRouterBase::Shutdown() { |
| + // The observer calls virtual methods on MediaRouter; it must be destroyed |
| + // outside of the dtor |
| + internal_routes_observer_.reset(); |
| +} |
| + |
| } // namespace media_router |