Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: chrome/browser/media/router/media_router_base.cc

Issue 2558963003: Add GetCurrentRoutes() to MediaRouter API, ensure dialog has routes at init (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 14
15 namespace media_router { 15 namespace media_router {
16 16
17 // A MediaRoutesObserver that maintains state about the current set of media 17 // A MediaRoutesObserver that maintains state about the current set of media
18 // routes. 18 // routes.
19 class MediaRouterBase::InternalMediaRoutesObserver 19 class MediaRouterBase::InternalMediaRoutesObserver
20 : public MediaRoutesObserver { 20 : public MediaRoutesObserver {
21 public: 21 public:
22 explicit InternalMediaRoutesObserver(MediaRouter* router) 22 explicit InternalMediaRoutesObserver(MediaRouter* router)
23 : MediaRoutesObserver(router), has_route(false) {} 23 : MediaRoutesObserver(router), has_route(false) {}
24 ~InternalMediaRoutesObserver() override {} 24 ~InternalMediaRoutesObserver() override {}
25 25
26 // MediaRoutesObserver 26 // MediaRoutesObserver
27 void OnRoutesUpdated( 27 void OnRoutesUpdated(
28 const std::vector<MediaRoute>& routes, 28 const std::vector<MediaRoute>& routes,
29 const std::vector<MediaRoute::Id>& joinable_route_ids) override { 29 const std::vector<MediaRoute::Id>& joinable_route_ids) override {
30 current_routes = routes;
30 incognito_route_ids.clear(); 31 incognito_route_ids.clear();
31 // TODO(crbug.com/611486): Have the MRPM pass a list of joinable route ids 32 // TODO(crbug.com/611486): Have the MRPM pass a list of joinable route ids
32 // via |joinable_route_ids|, and check here if it is non-empty. 33 // via |joinable_route_ids|, and check here if it is non-empty.
33 has_route = !routes.empty(); 34 has_route = !routes.empty();
34 for (const auto& route : routes) { 35 for (const auto& route : routes) {
35 if (route.is_incognito()) 36 if (route.is_incognito())
36 incognito_route_ids.push_back(route.media_route_id()); 37 incognito_route_ids.push_back(route.media_route_id());
37 } 38 }
38 } 39 }
39 40
40 bool has_route; 41 bool has_route;
42 std::vector<MediaRoute> current_routes;
41 std::vector<MediaRoute::Id> incognito_route_ids; 43 std::vector<MediaRoute::Id> incognito_route_ids;
42 44
43 private: 45 private:
44 DISALLOW_COPY_AND_ASSIGN(InternalMediaRoutesObserver); 46 DISALLOW_COPY_AND_ASSIGN(InternalMediaRoutesObserver);
45 }; 47 };
46 48
47 MediaRouterBase::~MediaRouterBase() { 49 MediaRouterBase::~MediaRouterBase() {
48 CHECK(!internal_routes_observer_); 50 CHECK(!internal_routes_observer_);
49 } 51 }
50 52
(...skipping 14 matching lines...) Expand all
65 } 67 }
66 68
67 return callbacks->Add(callback); 69 return callbacks->Add(callback);
68 } 70 }
69 71
70 void MediaRouterBase::OnIncognitoProfileShutdown() { 72 void MediaRouterBase::OnIncognitoProfileShutdown() {
71 for (const auto& route_id : internal_routes_observer_->incognito_route_ids) 73 for (const auto& route_id : internal_routes_observer_->incognito_route_ids)
72 TerminateRoute(route_id); 74 TerminateRoute(route_id);
73 } 75 }
74 76
77 std::vector<MediaRoute> MediaRouterBase::GetCurrentRoutes() const {
78 return internal_routes_observer_->current_routes;
79 }
80
75 MediaRouterBase::MediaRouterBase() : initialized_(false) {} 81 MediaRouterBase::MediaRouterBase() : initialized_(false) {}
76 82
77 // static 83 // static
78 std::string MediaRouterBase::CreatePresentationId() { 84 std::string MediaRouterBase::CreatePresentationId() {
79 return "mr_" + base::GenerateGUID(); 85 return "mr_" + base::GenerateGUID();
80 } 86 }
81 87
82 void MediaRouterBase::NotifyPresentationConnectionStateChange( 88 void MediaRouterBase::NotifyPresentationConnectionStateChange(
83 const MediaRoute::Id& route_id, 89 const MediaRoute::Id& route_id,
84 content::PresentationConnectionState state) { 90 content::PresentationConnectionState state) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 presentation_connection_state_callbacks_.erase(route_id); 132 presentation_connection_state_callbacks_.erase(route_id);
127 } 133 }
128 134
129 void MediaRouterBase::Shutdown() { 135 void MediaRouterBase::Shutdown() {
130 // The observer calls virtual methods on MediaRouter; it must be destroyed 136 // The observer calls virtual methods on MediaRouter; it must be destroyed
131 // outside of the dtor 137 // outside of the dtor
132 internal_routes_observer_.reset(); 138 internal_routes_observer_.reset();
133 } 139 }
134 140
135 } // namespace media_router 141 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698