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 <map> | |
| 8 | |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/guid.h" | 10 #include "base/guid.h" |
| 9 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 10 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 13 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 14 | 16 |
| 15 namespace media_router { | 17 namespace media_router { |
| 16 | 18 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 31 incognito_route_ids.clear(); | 33 incognito_route_ids.clear(); |
| 32 // TODO(crbug.com/611486): Have the MRPM pass a list of joinable route ids | 34 // TODO(crbug.com/611486): Have the MRPM pass a list of joinable route ids |
| 33 // via |joinable_route_ids|, and check here if it is non-empty. | 35 // via |joinable_route_ids|, and check here if it is non-empty. |
| 34 has_route = !routes.empty(); | 36 has_route = !routes.empty(); |
| 35 for (const auto& route : routes) { | 37 for (const auto& route : routes) { |
| 36 if (route.is_incognito()) | 38 if (route.is_incognito()) |
| 37 incognito_route_ids.push_back(route.media_route_id()); | 39 incognito_route_ids.push_back(route.media_route_id()); |
| 38 } | 40 } |
| 39 } | 41 } |
| 40 | 42 |
| 43 void RegisterPresentationRoute(const std::string& presentation_id, | |
| 44 const MediaRoute& route) { | |
| 45 presentation_id_route.insert(std::make_pair(presentation_id, route)); | |
| 46 } | |
| 47 | |
| 48 void UnregisterPresentationRoute(const std::string& presentation_id) { | |
| 49 presentation_id_route.erase(presentation_id); | |
|
imcheng
2017/03/08 20:06:35
If a MediaRoute was removed by the MRP, how is the
mark a. foltz
2017/03/08 22:01:47
One solution would be for each update sent to the
zhaobin
2017/03/09 00:34:27
Done.
| |
| 50 } | |
| 51 | |
| 52 const MediaRoute* GetPresentationRoute( | |
| 53 const std::string& presentation_id) const { | |
| 54 auto it = presentation_id_route.find(presentation_id); | |
| 55 if (it == presentation_id_route.end()) | |
| 56 return nullptr; | |
| 57 | |
| 58 return &it->second; | |
| 59 } | |
| 60 | |
| 41 bool has_route; | 61 bool has_route; |
| 42 std::vector<MediaRoute> current_routes; | 62 std::vector<MediaRoute> current_routes; |
| 43 std::vector<MediaRoute::Id> incognito_route_ids; | 63 std::vector<MediaRoute::Id> incognito_route_ids; |
| 64 std::map<std::string, MediaRoute> presentation_id_route; | |
| 44 | 65 |
| 45 private: | 66 private: |
| 46 DISALLOW_COPY_AND_ASSIGN(InternalMediaRoutesObserver); | 67 DISALLOW_COPY_AND_ASSIGN(InternalMediaRoutesObserver); |
| 47 }; | 68 }; |
| 48 | 69 |
| 49 MediaRouterBase::~MediaRouterBase() { | 70 MediaRouterBase::~MediaRouterBase() { |
| 50 CHECK(!internal_routes_observer_); | 71 CHECK(!internal_routes_observer_); |
| 51 } | 72 } |
| 52 | 73 |
| 53 std::unique_ptr<PresentationConnectionStateSubscription> | 74 std::unique_ptr<PresentationConnectionStateSubscription> |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 69 | 90 |
| 70 void MediaRouterBase::OnIncognitoProfileShutdown() { | 91 void MediaRouterBase::OnIncognitoProfileShutdown() { |
| 71 for (const auto& route_id : internal_routes_observer_->incognito_route_ids) | 92 for (const auto& route_id : internal_routes_observer_->incognito_route_ids) |
| 72 TerminateRoute(route_id); | 93 TerminateRoute(route_id); |
| 73 } | 94 } |
| 74 | 95 |
| 75 std::vector<MediaRoute> MediaRouterBase::GetCurrentRoutes() const { | 96 std::vector<MediaRoute> MediaRouterBase::GetCurrentRoutes() const { |
| 76 return internal_routes_observer_->current_routes; | 97 return internal_routes_observer_->current_routes; |
| 77 } | 98 } |
| 78 | 99 |
| 100 void MediaRouterBase::RegisterPresentationRoute( | |
| 101 const std::string& presentation_id, | |
| 102 const MediaRoute& route) { | |
| 103 DCHECK(internal_routes_observer_); | |
| 104 internal_routes_observer_->RegisterPresentationRoute(presentation_id, route); | |
| 105 } | |
| 106 | |
| 107 void MediaRouterBase::UnregisterPresentationRoute( | |
| 108 const std::string& presentation_id) { | |
| 109 DCHECK(internal_routes_observer_); | |
| 110 internal_routes_observer_->UnregisterPresentationRoute(presentation_id); | |
| 111 } | |
| 112 | |
| 113 const MediaRoute* MediaRouterBase::GetPresentationRoute( | |
| 114 const std::string& presentation_id) const { | |
| 115 DCHECK(internal_routes_observer_); | |
| 116 return internal_routes_observer_->GetPresentationRoute(presentation_id); | |
| 117 } | |
| 118 | |
| 79 MediaRouterBase::MediaRouterBase() : initialized_(false) {} | 119 MediaRouterBase::MediaRouterBase() : initialized_(false) {} |
| 80 | 120 |
| 81 // static | 121 // static |
| 82 std::string MediaRouterBase::CreatePresentationId() { | 122 std::string MediaRouterBase::CreatePresentationId() { |
| 83 return "mr_" + base::GenerateGUID(); | 123 return "mr_" + base::GenerateGUID(); |
| 84 } | 124 } |
| 85 | 125 |
| 86 void MediaRouterBase::NotifyPresentationConnectionStateChange( | 126 void MediaRouterBase::NotifyPresentationConnectionStateChange( |
| 87 const MediaRoute::Id& route_id, | 127 const MediaRoute::Id& route_id, |
| 88 content::PresentationConnectionState state) { | 128 content::PresentationConnectionState state) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 } | 172 } |
| 133 } | 173 } |
| 134 | 174 |
| 135 void MediaRouterBase::Shutdown() { | 175 void MediaRouterBase::Shutdown() { |
| 136 // The observer calls virtual methods on MediaRouter; it must be destroyed | 176 // The observer calls virtual methods on MediaRouter; it must be destroyed |
| 137 // outside of the dtor | 177 // outside of the dtor |
| 138 internal_routes_observer_.reset(); | 178 internal_routes_observer_.reset(); |
| 139 } | 179 } |
| 140 | 180 |
| 141 } // namespace media_router | 181 } // namespace media_router |
| OLD | NEW |