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/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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 routes_query->joinable_route_ids = joinable_route_ids; | 225 routes_query->joinable_route_ids = joinable_route_ids; |
| 225 | 226 |
| 226 if (routes_query->observers.might_have_observers()) { | 227 if (routes_query->observers.might_have_observers()) { |
| 227 for (auto& observer : routes_query->observers) | 228 for (auto& observer : routes_query->observers) |
| 228 observer.OnRoutesUpdated(routes, joinable_route_ids); | 229 observer.OnRoutesUpdated(routes, joinable_route_ids); |
| 229 } else { | 230 } else { |
| 230 DVLOG_WITH_INSTANCE(1) | 231 DVLOG_WITH_INSTANCE(1) |
| 231 << "Received routes update without any active observers: " | 232 << "Received routes update without any active observers: " |
| 232 << media_source; | 233 << media_source; |
| 233 } | 234 } |
| 235 RemoveInvalidRouteControllers(routes); | |
| 234 } | 236 } |
| 235 | 237 |
| 236 void MediaRouterMojoImpl::RouteResponseReceived( | 238 void MediaRouterMojoImpl::RouteResponseReceived( |
| 237 const std::string& presentation_id, | 239 const std::string& presentation_id, |
| 238 bool is_incognito, | 240 bool is_incognito, |
| 239 const std::vector<MediaRouteResponseCallback>& callbacks, | 241 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 240 bool is_join, | 242 bool is_join, |
| 241 const base::Optional<MediaRoute>& media_route, | 243 const base::Optional<MediaRoute>& media_route, |
| 242 const base::Optional<std::string>& error_text, | 244 const base::Optional<std::string>& error_text, |
| 243 RouteRequestResult::ResultCode result_code) { | 245 RouteRequestResult::ResultCode result_code) { |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 const std::string& domain, | 394 const std::string& domain, |
| 393 const MediaSinkSearchResponseCallback& sink_callback) { | 395 const MediaSinkSearchResponseCallback& sink_callback) { |
| 394 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 396 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 395 | 397 |
| 396 SetWakeReason(MediaRouteProviderWakeReason::SEARCH_SINKS); | 398 SetWakeReason(MediaRouteProviderWakeReason::SEARCH_SINKS); |
| 397 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoSearchSinks, | 399 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoSearchSinks, |
| 398 base::Unretained(this), sink_id, source_id, | 400 base::Unretained(this), sink_id, source_id, |
| 399 search_input, domain, sink_callback)); | 401 search_input, domain, sink_callback)); |
| 400 } | 402 } |
| 401 | 403 |
| 404 scoped_refptr<MediaRouteController> MediaRouterMojoImpl::GetRouteController( | |
| 405 const MediaRoute::Id& route_id) { | |
| 406 auto it = route_controllers_.find(route_id); | |
| 407 if (it != route_controllers_.end()) | |
| 408 return scoped_refptr<MediaRouteController>(it->second); | |
| 409 | |
| 410 mojom::MediaControllerPtr media_controller; | |
|
mark a. foltz
2017/03/30 23:03:28
Can you prefix Mojo variables with mojo_ for reada
takumif
2017/04/04 03:19:50
Done.
| |
| 411 mojom::MediaControllerRequest media_controller_request = | |
| 412 mojo::MakeRequest(&media_controller); | |
| 413 scoped_refptr<MediaRouteController> route_controller = | |
| 414 new MediaRouteController(route_id, std::move(media_controller), this); | |
| 415 | |
| 416 media_route_provider_->CreateMediaRouteController( | |
|
mark a. foltz
2017/03/30 23:03:28
What guarantees that the event page is alive? Mos
takumif
2017/04/04 03:19:51
These requests should be queued as well. I can't s
| |
| 417 route_id, std::move(media_controller_request), | |
| 418 base::Bind(&MediaRouterMojoImpl::OnMediaControllerCreated, | |
| 419 base::Unretained(this), route_id)); | |
| 420 media_route_provider_->SetMediaRouteStatusObserver( | |
| 421 route_id, route_controller->BindObserverPtr()); | |
| 422 route_controllers_.insert({route_id, route_controller.get()}); | |
| 423 return route_controller; | |
|
mark a. foltz
2017/03/30 23:03:28
What state is this in before OnMediaControllerCrea
takumif
2017/04/04 03:19:50
Before DoCreateMediaRouteController() is called, r
| |
| 424 } | |
| 425 | |
| 402 bool MediaRouterMojoImpl::RegisterMediaSinksObserver( | 426 bool MediaRouterMojoImpl::RegisterMediaSinksObserver( |
| 403 MediaSinksObserver* observer) { | 427 MediaSinksObserver* observer) { |
| 404 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 428 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 405 | 429 |
| 406 // Create an observer list for the media source and add |observer| | 430 // Create an observer list for the media source and add |observer| |
| 407 // to it. Fail if |observer| is already registered. | 431 // to it. Fail if |observer| is already registered. |
| 408 const std::string& source_id = observer->source().id(); | 432 const std::string& source_id = observer->source().id(); |
| 409 std::unique_ptr<MediaSinksQuery>& sinks_query = sinks_queries_[source_id]; | 433 std::unique_ptr<MediaSinksQuery>& sinks_query = sinks_queries_[source_id]; |
| 410 bool is_new_query = false; | 434 bool is_new_query = false; |
| 411 if (!sinks_query) { | 435 if (!sinks_query) { |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 585 it->second->RemoveObserver(observer); | 609 it->second->RemoveObserver(observer); |
| 586 if (!it->second->might_have_observers()) { | 610 if (!it->second->might_have_observers()) { |
| 587 message_observers_.erase(route_id); | 611 message_observers_.erase(route_id); |
| 588 SetWakeReason( | 612 SetWakeReason( |
| 589 MediaRouteProviderWakeReason::STOP_LISTENING_FOR_ROUTE_MESSAGES); | 613 MediaRouteProviderWakeReason::STOP_LISTENING_FOR_ROUTE_MESSAGES); |
| 590 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStopListeningForRouteMessages, | 614 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStopListeningForRouteMessages, |
| 591 base::Unretained(this), route_id)); | 615 base::Unretained(this), route_id)); |
| 592 } | 616 } |
| 593 } | 617 } |
| 594 | 618 |
| 619 void MediaRouterMojoImpl::DetachRouteController( | |
| 620 const MediaRoute::Id& route_id, | |
| 621 MediaRouteController* controller) { | |
| 622 auto it = route_controllers_.find(route_id); | |
| 623 if (it != route_controllers_.end() && it->second == controller) | |
| 624 route_controllers_.erase(it); | |
| 625 } | |
| 626 | |
| 595 void MediaRouterMojoImpl::DoCreateRoute( | 627 void MediaRouterMojoImpl::DoCreateRoute( |
| 596 const MediaSource::Id& source_id, | 628 const MediaSource::Id& source_id, |
| 597 const MediaSink::Id& sink_id, | 629 const MediaSink::Id& sink_id, |
| 598 const url::Origin& origin, | 630 const url::Origin& origin, |
| 599 int tab_id, | 631 int tab_id, |
| 600 const std::vector<MediaRouteResponseCallback>& callbacks, | 632 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 601 base::TimeDelta timeout, | 633 base::TimeDelta timeout, |
| 602 bool incognito) { | 634 bool incognito) { |
| 603 std::string presentation_id = MediaRouterBase::CreatePresentationId(); | 635 std::string presentation_id = MediaRouterBase::CreatePresentationId(); |
| 604 DVLOG_WITH_INSTANCE(1) << "DoCreateRoute " << source_id << "=>" << sink_id | 636 DVLOG_WITH_INSTANCE(1) << "DoCreateRoute " << source_id << "=>" << sink_id |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 973 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoUpdateMediaSinks, | 1005 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoUpdateMediaSinks, |
| 974 base::Unretained(this), source_id)); | 1006 base::Unretained(this), source_id)); |
| 975 } | 1007 } |
| 976 | 1008 |
| 977 void MediaRouterMojoImpl::DoUpdateMediaSinks( | 1009 void MediaRouterMojoImpl::DoUpdateMediaSinks( |
| 978 const MediaSource::Id& source_id) { | 1010 const MediaSource::Id& source_id) { |
| 979 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks" << source_id; | 1011 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks" << source_id; |
| 980 media_route_provider_->UpdateMediaSinks(source_id); | 1012 media_route_provider_->UpdateMediaSinks(source_id); |
| 981 } | 1013 } |
| 982 | 1014 |
| 1015 void MediaRouterMojoImpl::RemoveInvalidRouteControllers( | |
| 1016 const std::vector<MediaRoute>& routes) { | |
| 1017 auto it = route_controllers_.begin(); | |
| 1018 while (it != route_controllers_.end()) { | |
| 1019 const MediaRoute::Id& route_id = it->first; | |
| 1020 if (std::find_if(routes.begin(), routes.end(), | |
| 1021 [&route_id](const MediaRoute& route) { | |
| 1022 return route.media_route_id() == route_id; | |
| 1023 }) == routes.end()) { | |
| 1024 MediaRouteController* controller = it->second; | |
| 1025 it = route_controllers_.erase(it); | |
| 1026 // Invalidate() will result in another erase() call, which will be no-op. | |
| 1027 controller->Invalidate(); | |
|
mark a. foltz
2017/03/30 23:03:28
Doesn't this call back into DetachRouteController(
takumif
2017/04/04 03:19:50
Yes. Added OnRouteInvalid().
| |
| 1028 } else { | |
| 1029 ++it; | |
| 1030 } | |
| 1031 } | |
| 1032 } | |
| 1033 | |
| 1034 void MediaRouterMojoImpl::OnMediaControllerCreated( | |
|
mark a. foltz
2017/03/30 23:03:28
Shouldn't this return a boolean per the mojom?
takumif
2017/04/04 03:19:51
No, this is the callback that gets called, so it d
| |
| 1035 const MediaRoute::Id& route_id, | |
| 1036 bool success) { | |
| 1037 if (success) | |
| 1038 return; | |
| 1039 | |
| 1040 auto it = route_controllers_.find(route_id); | |
| 1041 if (it != route_controllers_.end()) | |
| 1042 it->second->Invalidate(); | |
| 1043 } | |
| 1044 | |
| 983 } // namespace media_router | 1045 } // namespace media_router |
| OLD | NEW |