| 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_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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/guid.h" | 11 #include "base/guid.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "chrome/browser/media/router/issues_observer.h" | 17 #include "chrome/browser/media/router/issues_observer.h" |
| 18 #include "chrome/browser/media/router/media_router_factory.h" | 18 #include "chrome/browser/media/router/media_router_factory.h" |
| 19 #include "chrome/browser/media/router/media_router_metrics.h" | |
| 20 #include "chrome/browser/media/router/media_router_type_converters.h" | |
| 21 #include "chrome/browser/media/router/media_routes_observer.h" | 19 #include "chrome/browser/media/router/media_routes_observer.h" |
| 22 #include "chrome/browser/media/router/media_sinks_observer.h" | 20 #include "chrome/browser/media/router/media_sinks_observer.h" |
| 21 #include "chrome/browser/media/router/mojo/media_router_mojo_metrics.h" |
| 22 #include "chrome/browser/media/router/mojo/media_router_type_converters.h" |
| 23 #include "chrome/browser/media/router/presentation_session_messages_observer.h" | 23 #include "chrome/browser/media/router/presentation_session_messages_observer.h" |
| 24 #include "chrome/browser/sessions/session_tab_helper.h" | 24 #include "chrome/browser/sessions/session_tab_helper.h" |
| 25 #include "extensions/browser/process_manager.h" | 25 #include "extensions/browser/process_manager.h" |
| 26 | 26 |
| 27 #define DVLOG_WITH_INSTANCE(level) \ | 27 #define DVLOG_WITH_INSTANCE(level) \ |
| 28 DVLOG(level) << "MR #" << instance_id_ << ": " | 28 DVLOG(level) << "MR #" << instance_id_ << ": " |
| 29 | 29 |
| 30 #define DLOG_WITH_INSTANCE(level) DLOG(level) << "MR #" << instance_id_ << ": " | 30 #define DLOG_WITH_INSTANCE(level) DLOG(level) << "MR #" << instance_id_ << ": " |
| 31 | 31 |
| 32 namespace media_router { | 32 namespace media_router { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 const extensions::Extension& extension) { | 104 const extensions::Extension& extension) { |
| 105 DCHECK(thread_checker_.CalledOnValidThread()); | 105 DCHECK(thread_checker_.CalledOnValidThread()); |
| 106 | 106 |
| 107 binding_.reset( | 107 binding_.reset( |
| 108 new mojo::Binding<interfaces::MediaRouter>(this, std::move(request))); | 108 new mojo::Binding<interfaces::MediaRouter>(this, std::move(request))); |
| 109 binding_->set_connection_error_handler(base::Bind( | 109 binding_->set_connection_error_handler(base::Bind( |
| 110 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); | 110 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); |
| 111 | 111 |
| 112 media_route_provider_extension_id_ = extension.id(); | 112 media_route_provider_extension_id_ = extension.id(); |
| 113 if (!provider_version_was_recorded_) { | 113 if (!provider_version_was_recorded_) { |
| 114 MediaRouterMetrics::RecordMediaRouteProviderVersion(extension); | 114 MediaRouterMojoMetrics::RecordMediaRouteProviderVersion(extension); |
| 115 provider_version_was_recorded_ = true; | 115 provider_version_was_recorded_ = true; |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 | 118 |
| 119 void MediaRouterMojoImpl::OnConnectionError() { | 119 void MediaRouterMojoImpl::OnConnectionError() { |
| 120 DCHECK(thread_checker_.CalledOnValidThread()); | 120 DCHECK(thread_checker_.CalledOnValidThread()); |
| 121 | 121 |
| 122 media_route_provider_.reset(); | 122 media_route_provider_.reset(); |
| 123 binding_.reset(); | 123 binding_.reset(); |
| 124 | 124 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 | 227 |
| 228 std::vector<MediaRoute> routes_converted; | 228 std::vector<MediaRoute> routes_converted; |
| 229 routes_converted.reserve(routes.size()); | 229 routes_converted.reserve(routes.size()); |
| 230 | 230 |
| 231 for (size_t i = 0; i < routes.size(); ++i) | 231 for (size_t i = 0; i < routes.size(); ++i) |
| 232 routes_converted.push_back(routes[i].To<MediaRoute>()); | 232 routes_converted.push_back(routes[i].To<MediaRoute>()); |
| 233 | 233 |
| 234 std::vector<MediaRoute::Id> joinable_routes_converted = | 234 std::vector<MediaRoute::Id> joinable_routes_converted = |
| 235 joinable_route_ids.To<std::vector<std::string>>(); | 235 joinable_route_ids.To<std::vector<std::string>>(); |
| 236 | 236 |
| 237 FOR_EACH_OBSERVER(MediaRoutesObserver, it->second->observers, | 237 FOR_EACH_OBSERVER( |
| 238 OnRoutesUpdated(routes_converted, | 238 MediaRoutesObserver, it->second->observers, |
| 239 joinable_routes_converted)); | 239 OnRoutesUpdated(routes_converted, joinable_routes_converted)); |
| 240 } | 240 } |
| 241 | 241 |
| 242 void MediaRouterMojoImpl::RouteResponseReceived( | 242 void MediaRouterMojoImpl::RouteResponseReceived( |
| 243 const std::string& presentation_id, | 243 const std::string& presentation_id, |
| 244 bool off_the_record, | 244 bool off_the_record, |
| 245 const std::vector<MediaRouteResponseCallback>& callbacks, | 245 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 246 interfaces::MediaRoutePtr media_route, | 246 interfaces::MediaRoutePtr media_route, |
| 247 const mojo::String& error_text, | 247 const mojo::String& error_text, |
| 248 interfaces::RouteRequestResultCode result_code) { | 248 interfaces::RouteRequestResultCode result_code) { |
| 249 scoped_ptr<RouteRequestResult> result; | 249 scoped_ptr<RouteRequestResult> result; |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 } | 855 } |
| 856 } | 856 } |
| 857 | 857 |
| 858 void MediaRouterMojoImpl::AttemptWakeEventPage() { | 858 void MediaRouterMojoImpl::AttemptWakeEventPage() { |
| 859 ++wakeup_attempt_count_; | 859 ++wakeup_attempt_count_; |
| 860 if (wakeup_attempt_count_ > kMaxWakeupAttemptCount) { | 860 if (wakeup_attempt_count_ > kMaxWakeupAttemptCount) { |
| 861 DLOG_WITH_INSTANCE(ERROR) << "Attempted too many times to wake up event " | 861 DLOG_WITH_INSTANCE(ERROR) << "Attempted too many times to wake up event " |
| 862 << "page."; | 862 << "page."; |
| 863 DrainPendingRequests(); | 863 DrainPendingRequests(); |
| 864 wakeup_attempt_count_ = 0; | 864 wakeup_attempt_count_ = 0; |
| 865 MediaRouterMetrics::RecordMediaRouteProviderWakeup( | 865 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeup( |
| 866 MediaRouteProviderWakeup::ERROR_TOO_MANY_RETRIES); | 866 MediaRouteProviderWakeup::ERROR_TOO_MANY_RETRIES); |
| 867 return; | 867 return; |
| 868 } | 868 } |
| 869 | 869 |
| 870 DVLOG_WITH_INSTANCE(1) << "Attempting to wake up event page: attempt " | 870 DVLOG_WITH_INSTANCE(1) << "Attempting to wake up event page: attempt " |
| 871 << wakeup_attempt_count_; | 871 << wakeup_attempt_count_; |
| 872 | 872 |
| 873 // This return false if the extension is already awake. | 873 // This return false if the extension is already awake. |
| 874 // Callback is bound using WeakPtr because |event_page_tracker_| outlives | 874 // Callback is bound using WeakPtr because |event_page_tracker_| outlives |
| 875 // |this|. | 875 // |this|. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 888 DCHECK(!media_route_provider_extension_id_.empty()); | 888 DCHECK(!media_route_provider_extension_id_.empty()); |
| 889 | 889 |
| 890 for (const auto& next_request : pending_requests_) | 890 for (const auto& next_request : pending_requests_) |
| 891 next_request.Run(); | 891 next_request.Run(); |
| 892 | 892 |
| 893 pending_requests_.clear(); | 893 pending_requests_.clear(); |
| 894 } | 894 } |
| 895 | 895 |
| 896 void MediaRouterMojoImpl::EventPageWakeComplete(bool success) { | 896 void MediaRouterMojoImpl::EventPageWakeComplete(bool success) { |
| 897 if (success) { | 897 if (success) { |
| 898 MediaRouterMetrics::RecordMediaRouteProviderWakeReason( | 898 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeReason( |
| 899 current_wake_reason_); | 899 current_wake_reason_); |
| 900 ClearWakeReason(); | 900 ClearWakeReason(); |
| 901 MediaRouterMetrics::RecordMediaRouteProviderWakeup( | 901 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeup( |
| 902 MediaRouteProviderWakeup::SUCCESS); | 902 MediaRouteProviderWakeup::SUCCESS); |
| 903 return; | 903 return; |
| 904 } | 904 } |
| 905 | 905 |
| 906 // This is likely an non-retriable error. Drop the pending requests. | 906 // This is likely an non-retriable error. Drop the pending requests. |
| 907 DLOG_WITH_INSTANCE(ERROR) | 907 DLOG_WITH_INSTANCE(ERROR) |
| 908 << "An error encountered while waking the event page."; | 908 << "An error encountered while waking the event page."; |
| 909 ClearWakeReason(); | 909 ClearWakeReason(); |
| 910 DrainPendingRequests(); | 910 DrainPendingRequests(); |
| 911 MediaRouterMetrics::RecordMediaRouteProviderWakeup( | 911 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeup( |
| 912 MediaRouteProviderWakeup::ERROR_UNKNOWN); | 912 MediaRouteProviderWakeup::ERROR_UNKNOWN); |
| 913 } | 913 } |
| 914 | 914 |
| 915 void MediaRouterMojoImpl::DrainPendingRequests() { | 915 void MediaRouterMojoImpl::DrainPendingRequests() { |
| 916 DLOG_WITH_INSTANCE(ERROR) | 916 DLOG_WITH_INSTANCE(ERROR) |
| 917 << "Draining request queue. (queue-length=" << pending_requests_.size() | 917 << "Draining request queue. (queue-length=" << pending_requests_.size() |
| 918 << ")"; | 918 << ")"; |
| 919 pending_requests_.clear(); | 919 pending_requests_.clear(); |
| 920 } | 920 } |
| 921 | 921 |
| 922 void MediaRouterMojoImpl::SetWakeReason(MediaRouteProviderWakeReason reason) { | 922 void MediaRouterMojoImpl::SetWakeReason(MediaRouteProviderWakeReason reason) { |
| 923 DCHECK(reason != MediaRouteProviderWakeReason::TOTAL_COUNT); | 923 DCHECK(reason != MediaRouteProviderWakeReason::TOTAL_COUNT); |
| 924 if (current_wake_reason_ == MediaRouteProviderWakeReason::TOTAL_COUNT) | 924 if (current_wake_reason_ == MediaRouteProviderWakeReason::TOTAL_COUNT) |
| 925 current_wake_reason_ = reason; | 925 current_wake_reason_ = reason; |
| 926 } | 926 } |
| 927 | 927 |
| 928 void MediaRouterMojoImpl::ClearWakeReason() { | 928 void MediaRouterMojoImpl::ClearWakeReason() { |
| 929 DCHECK(current_wake_reason_ != MediaRouteProviderWakeReason::TOTAL_COUNT); | 929 DCHECK(current_wake_reason_ != MediaRouteProviderWakeReason::TOTAL_COUNT); |
| 930 current_wake_reason_ = MediaRouteProviderWakeReason::TOTAL_COUNT; | 930 current_wake_reason_ = MediaRouteProviderWakeReason::TOTAL_COUNT; |
| 931 } | 931 } |
| 932 | 932 |
| 933 } // namespace media_router | 933 } // namespace media_router |
| OLD | NEW |