| 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..36e092ea0c0c39cab4ec080ead7a9fd63bb657d3 100644
|
| --- a/chrome/browser/media/router/media_router_base.cc
|
| +++ b/chrome/browser/media/router/media_router_base.cc
|
| @@ -13,9 +13,38 @@
|
|
|
| namespace media_router {
|
|
|
| -MediaRouterBase::MediaRouterBase() = default;
|
| +// A MediaRoutesObserver that maintains state about the current set of media
|
| +// routes.
|
| +class MediaRouterBase::InternalMediaRoutesObserver
|
| + : public MediaRoutesObserver {
|
| + public:
|
| + explicit InternalMediaRoutesObserver(MediaRouter* router)
|
| + : MediaRoutesObserver(router), has_local_route(false) {}
|
| + ~InternalMediaRoutesObserver() override {}
|
| +
|
| + // MediaRoutesObserver
|
| + void OnRoutesUpdated(
|
| + const std::vector<MediaRoute>& routes,
|
| + const std::vector<MediaRoute::Id>& joinable_route_ids) override {
|
| + 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());
|
| + }
|
| + }
|
| +
|
| + bool has_local_route;
|
| + std::vector<MediaRoute::Id> off_the_record_route_ids;
|
|
|
| -MediaRouterBase::~MediaRouterBase() = default;
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(InternalMediaRoutesObserver);
|
| +};
|
| +
|
| +MediaRouterBase::~MediaRouterBase() {
|
| + CHECK(!internal_routes_observer_);
|
| +}
|
|
|
| std::unique_ptr<PresentationConnectionStateSubscription>
|
| MediaRouterBase::AddPresentationConnectionStateChangedCallback(
|
| @@ -37,20 +66,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 +81,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 +103,16 @@ 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;
|
| }
|
|
|
| void MediaRouterBase::OnPresentationConnectionStateCallbackRemoved(
|
| @@ -102,4 +122,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
|
|
|