| 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/mojo/media_router_mojo_impl.h" | 5 #include "chrome/browser/media/router/mojo/media_router_mojo_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/guid.h" | 12 #include "base/guid.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
| 16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 19 #include "chrome/browser/media/router/issues_observer.h" | 19 #include "chrome/browser/media/router/issues_observer.h" |
| 20 #include "chrome/browser/media/router/media_router_factory.h" | 20 #include "chrome/browser/media/router/media_router_factory.h" |
| 21 #include "chrome/browser/media/router/media_routes_observer.h" | 21 #include "chrome/browser/media/router/media_routes_observer.h" |
| 22 #include "chrome/browser/media/router/media_sinks_observer.h" | 22 #include "chrome/browser/media/router/media_sinks_observer.h" |
| 23 #include "chrome/browser/media/router/media_source_helper.h" | 23 #include "chrome/browser/media/router/media_source_helper.h" |
| 24 #include "chrome/browser/media/router/mojo/media_route_controller.h" |
| 24 #include "chrome/browser/media/router/mojo/media_route_provider_util_win.h" | 25 #include "chrome/browser/media/router/mojo/media_route_provider_util_win.h" |
| 25 #include "chrome/browser/media/router/mojo/media_router_mojo_metrics.h" | 26 #include "chrome/browser/media/router/mojo/media_router_mojo_metrics.h" |
| 26 #include "chrome/browser/media/router/route_message.h" | 27 #include "chrome/browser/media/router/route_message.h" |
| 27 #include "chrome/browser/media/router/route_message_observer.h" | 28 #include "chrome/browser/media/router/route_message_observer.h" |
| 28 #include "chrome/browser/sessions/session_tab_helper.h" | 29 #include "chrome/browser/sessions/session_tab_helper.h" |
| 29 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
| 30 #include "extensions/browser/process_manager.h" | 31 #include "extensions/browser/process_manager.h" |
| 31 | 32 |
| 32 #define DVLOG_WITH_INSTANCE(level) \ | 33 #define DVLOG_WITH_INSTANCE(level) \ |
| 33 DVLOG(level) << "MR #" << instance_id_ << ": " | 34 DVLOG(level) << "MR #" << instance_id_ << ": " |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 auto it = routes_queries_.find(media_source); | 211 auto it = routes_queries_.find(media_source); |
| 211 if (it == routes_queries_.end() || | 212 if (it == routes_queries_.end() || |
| 212 !(it->second->observers.might_have_observers())) { | 213 !(it->second->observers.might_have_observers())) { |
| 213 DVLOG_WITH_INSTANCE(1) | 214 DVLOG_WITH_INSTANCE(1) |
| 214 << "Received route list without any active observers: " << media_source; | 215 << "Received route list without any active observers: " << media_source; |
| 215 return; | 216 return; |
| 216 } | 217 } |
| 217 | 218 |
| 218 for (auto& observer : it->second->observers) | 219 for (auto& observer : it->second->observers) |
| 219 observer.OnRoutesUpdated(routes, joinable_route_ids); | 220 observer.OnRoutesUpdated(routes, joinable_route_ids); |
| 221 |
| 222 RemoveInvalidMediaRouteControllers(routes); |
| 220 } | 223 } |
| 221 | 224 |
| 222 void MediaRouterMojoImpl::RouteResponseReceived( | 225 void MediaRouterMojoImpl::RouteResponseReceived( |
| 223 const std::string& presentation_id, | 226 const std::string& presentation_id, |
| 224 bool is_incognito, | 227 bool is_incognito, |
| 225 const std::vector<MediaRouteResponseCallback>& callbacks, | 228 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 226 bool is_join, | 229 bool is_join, |
| 227 const base::Optional<MediaRoute>& media_route, | 230 const base::Optional<MediaRoute>& media_route, |
| 228 const base::Optional<std::string>& error_text, | 231 const base::Optional<std::string>& error_text, |
| 229 RouteRequestResult::ResultCode result_code) { | 232 RouteRequestResult::ResultCode result_code) { |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 const std::string& domain, | 381 const std::string& domain, |
| 379 const MediaSinkSearchResponseCallback& sink_callback) { | 382 const MediaSinkSearchResponseCallback& sink_callback) { |
| 380 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 383 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 381 | 384 |
| 382 SetWakeReason(MediaRouteProviderWakeReason::SEARCH_SINKS); | 385 SetWakeReason(MediaRouteProviderWakeReason::SEARCH_SINKS); |
| 383 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoSearchSinks, | 386 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoSearchSinks, |
| 384 base::Unretained(this), sink_id, source_id, | 387 base::Unretained(this), sink_id, source_id, |
| 385 search_input, domain, sink_callback)); | 388 search_input, domain, sink_callback)); |
| 386 } | 389 } |
| 387 | 390 |
| 391 MediaRouteController* MediaRouterMojoImpl::GetControllerForRoute( |
| 392 const MediaRoute::Id& route_id) { |
| 393 auto it = route_controllers_.find(route_id); |
| 394 if (it != route_controllers_.end()) |
| 395 return it->second.get(); |
| 396 route_controllers_[route_id] = base::MakeUnique<MediaRouteController>( |
| 397 route_id, media_route_provider_.get(), |
| 398 base::Bind(&MediaRouterMojoImpl::DestroyMediaRouteController, |
| 399 base::Unretained(this), route_id)); |
| 400 return route_controllers_[route_id].get(); |
| 401 } |
| 402 |
| 403 void MediaRouterMojoImpl::DestroyMediaRouteController( |
| 404 const MediaRoute::Id& route_id) { |
| 405 route_controllers_.erase(route_id); |
| 406 } |
| 407 |
| 388 bool MediaRouterMojoImpl::RegisterMediaSinksObserver( | 408 bool MediaRouterMojoImpl::RegisterMediaSinksObserver( |
| 389 MediaSinksObserver* observer) { | 409 MediaSinksObserver* observer) { |
| 390 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 410 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 391 | 411 |
| 392 // Create an observer list for the media source and add |observer| | 412 // Create an observer list for the media source and add |observer| |
| 393 // to it. Fail if |observer| is already registered. | 413 // to it. Fail if |observer| is already registered. |
| 394 const std::string& source_id = observer->source().id(); | 414 const std::string& source_id = observer->source().id(); |
| 395 std::unique_ptr<MediaSinksQuery>& sinks_query = sinks_queries_[source_id]; | 415 std::unique_ptr<MediaSinksQuery>& sinks_query = sinks_queries_[source_id]; |
| 396 bool new_query = false; | 416 bool new_query = false; |
| 397 if (!sinks_query) { | 417 if (!sinks_query) { |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoUpdateMediaSinks, | 948 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoUpdateMediaSinks, |
| 929 base::Unretained(this), source_id)); | 949 base::Unretained(this), source_id)); |
| 930 } | 950 } |
| 931 | 951 |
| 932 void MediaRouterMojoImpl::DoUpdateMediaSinks( | 952 void MediaRouterMojoImpl::DoUpdateMediaSinks( |
| 933 const MediaSource::Id& source_id) { | 953 const MediaSource::Id& source_id) { |
| 934 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks" << source_id; | 954 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks" << source_id; |
| 935 media_route_provider_->UpdateMediaSinks(source_id); | 955 media_route_provider_->UpdateMediaSinks(source_id); |
| 936 } | 956 } |
| 937 | 957 |
| 958 void MediaRouterMojoImpl::RemoveInvalidMediaRouteControllers( |
| 959 const std::vector<MediaRoute>& routes) { |
| 960 auto it = route_controllers_.begin(); |
| 961 while (it != route_controllers_.end()) { |
| 962 const MediaRoute::Id& route_id = it->first; |
| 963 if (std::find_if(routes.begin(), routes.end(), |
| 964 [&route_id](const MediaRoute& route) { |
| 965 return route.media_route_id() == route_id; |
| 966 }) == routes.end()) { |
| 967 it = route_controllers_.erase(it); |
| 968 } else { |
| 969 ++it; |
| 970 } |
| 971 } |
| 972 } |
| 973 |
| 938 } // namespace media_router | 974 } // namespace media_router |
| OLD | NEW |