| 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_route_provider_util_win.h" | |
| 19 #include "chrome/browser/media/router/media_router_factory.h" | 18 #include "chrome/browser/media/router/media_router_factory.h" |
| 20 #include "chrome/browser/media/router/media_router_metrics.h" | |
| 21 #include "chrome/browser/media/router/media_router_type_converters.h" | |
| 22 #include "chrome/browser/media/router/media_routes_observer.h" | 19 #include "chrome/browser/media/router/media_routes_observer.h" |
| 23 #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_route_provider_util_win.h" |
| 22 #include "chrome/browser/media/router/mojo/media_router_mojo_metrics.h" |
| 23 #include "chrome/browser/media/router/mojo/media_router_type_converters.h" |
| 24 #include "chrome/browser/media/router/presentation_session_messages_observer.h" | 24 #include "chrome/browser/media/router/presentation_session_messages_observer.h" |
| 25 #include "chrome/browser/sessions/session_tab_helper.h" | 25 #include "chrome/browser/sessions/session_tab_helper.h" |
| 26 #include "extensions/browser/process_manager.h" | 26 #include "extensions/browser/process_manager.h" |
| 27 | 27 |
| 28 #define DVLOG_WITH_INSTANCE(level) \ | 28 #define DVLOG_WITH_INSTANCE(level) \ |
| 29 DVLOG(level) << "MR #" << instance_id_ << ": " | 29 DVLOG(level) << "MR #" << instance_id_ << ": " |
| 30 | 30 |
| 31 #define DLOG_WITH_INSTANCE(level) DLOG(level) << "MR #" << instance_id_ << ": " | 31 #define DLOG_WITH_INSTANCE(level) DLOG(level) << "MR #" << instance_id_ << ": " |
| 32 | 32 |
| 33 namespace media_router { | 33 namespace media_router { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 const extensions::Extension& extension) { | 110 const extensions::Extension& extension) { |
| 111 DCHECK(thread_checker_.CalledOnValidThread()); | 111 DCHECK(thread_checker_.CalledOnValidThread()); |
| 112 | 112 |
| 113 binding_.reset( | 113 binding_.reset( |
| 114 new mojo::Binding<interfaces::MediaRouter>(this, std::move(request))); | 114 new mojo::Binding<interfaces::MediaRouter>(this, std::move(request))); |
| 115 binding_->set_connection_error_handler(base::Bind( | 115 binding_->set_connection_error_handler(base::Bind( |
| 116 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); | 116 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); |
| 117 | 117 |
| 118 media_route_provider_extension_id_ = extension.id(); | 118 media_route_provider_extension_id_ = extension.id(); |
| 119 if (!provider_version_was_recorded_) { | 119 if (!provider_version_was_recorded_) { |
| 120 MediaRouterMetrics::RecordMediaRouteProviderVersion(extension); | 120 MediaRouterMojoMetrics::RecordMediaRouteProviderVersion(extension); |
| 121 provider_version_was_recorded_ = true; | 121 provider_version_was_recorded_ = true; |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 | 124 |
| 125 void MediaRouterMojoImpl::OnConnectionError() { | 125 void MediaRouterMojoImpl::OnConnectionError() { |
| 126 DCHECK(thread_checker_.CalledOnValidThread()); | 126 DCHECK(thread_checker_.CalledOnValidThread()); |
| 127 | 127 |
| 128 media_route_provider_.reset(); | 128 media_route_provider_.reset(); |
| 129 binding_.reset(); | 129 binding_.reset(); |
| 130 | 130 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 | 251 |
| 252 std::vector<MediaRoute> routes_converted; | 252 std::vector<MediaRoute> routes_converted; |
| 253 routes_converted.reserve(routes.size()); | 253 routes_converted.reserve(routes.size()); |
| 254 | 254 |
| 255 for (size_t i = 0; i < routes.size(); ++i) | 255 for (size_t i = 0; i < routes.size(); ++i) |
| 256 routes_converted.push_back(routes[i].To<MediaRoute>()); | 256 routes_converted.push_back(routes[i].To<MediaRoute>()); |
| 257 | 257 |
| 258 std::vector<MediaRoute::Id> joinable_routes_converted = | 258 std::vector<MediaRoute::Id> joinable_routes_converted = |
| 259 joinable_route_ids.To<std::vector<std::string>>(); | 259 joinable_route_ids.To<std::vector<std::string>>(); |
| 260 | 260 |
| 261 FOR_EACH_OBSERVER(MediaRoutesObserver, it->second->observers, | 261 FOR_EACH_OBSERVER( |
| 262 OnRoutesUpdated(routes_converted, | 262 MediaRoutesObserver, it->second->observers, |
| 263 joinable_routes_converted)); | 263 OnRoutesUpdated(routes_converted, joinable_routes_converted)); |
| 264 } | 264 } |
| 265 | 265 |
| 266 void MediaRouterMojoImpl::RouteResponseReceived( | 266 void MediaRouterMojoImpl::RouteResponseReceived( |
| 267 const std::string& presentation_id, | 267 const std::string& presentation_id, |
| 268 bool off_the_record, | 268 bool off_the_record, |
| 269 const std::vector<MediaRouteResponseCallback>& callbacks, | 269 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 270 interfaces::MediaRoutePtr media_route, | 270 interfaces::MediaRoutePtr media_route, |
| 271 const mojo::String& error_text, | 271 const mojo::String& error_text, |
| 272 interfaces::RouteRequestResultCode result_code) { | 272 interfaces::RouteRequestResultCode result_code) { |
| 273 scoped_ptr<RouteRequestResult> result; | 273 scoped_ptr<RouteRequestResult> result; |
| (...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 } | 885 } |
| 886 } | 886 } |
| 887 | 887 |
| 888 void MediaRouterMojoImpl::AttemptWakeEventPage() { | 888 void MediaRouterMojoImpl::AttemptWakeEventPage() { |
| 889 ++wakeup_attempt_count_; | 889 ++wakeup_attempt_count_; |
| 890 if (wakeup_attempt_count_ > kMaxWakeupAttemptCount) { | 890 if (wakeup_attempt_count_ > kMaxWakeupAttemptCount) { |
| 891 DLOG_WITH_INSTANCE(ERROR) << "Attempted too many times to wake up event " | 891 DLOG_WITH_INSTANCE(ERROR) << "Attempted too many times to wake up event " |
| 892 << "page."; | 892 << "page."; |
| 893 DrainPendingRequests(); | 893 DrainPendingRequests(); |
| 894 wakeup_attempt_count_ = 0; | 894 wakeup_attempt_count_ = 0; |
| 895 MediaRouterMetrics::RecordMediaRouteProviderWakeup( | 895 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeup( |
| 896 MediaRouteProviderWakeup::ERROR_TOO_MANY_RETRIES); | 896 MediaRouteProviderWakeup::ERROR_TOO_MANY_RETRIES); |
| 897 return; | 897 return; |
| 898 } | 898 } |
| 899 | 899 |
| 900 DVLOG_WITH_INSTANCE(1) << "Attempting to wake up event page: attempt " | 900 DVLOG_WITH_INSTANCE(1) << "Attempting to wake up event page: attempt " |
| 901 << wakeup_attempt_count_; | 901 << wakeup_attempt_count_; |
| 902 | 902 |
| 903 // This return false if the extension is already awake. | 903 // This return false if the extension is already awake. |
| 904 // Callback is bound using WeakPtr because |event_page_tracker_| outlives | 904 // Callback is bound using WeakPtr because |event_page_tracker_| outlives |
| 905 // |this|. | 905 // |this|. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 918 DCHECK(!media_route_provider_extension_id_.empty()); | 918 DCHECK(!media_route_provider_extension_id_.empty()); |
| 919 | 919 |
| 920 for (const auto& next_request : pending_requests_) | 920 for (const auto& next_request : pending_requests_) |
| 921 next_request.Run(); | 921 next_request.Run(); |
| 922 | 922 |
| 923 pending_requests_.clear(); | 923 pending_requests_.clear(); |
| 924 } | 924 } |
| 925 | 925 |
| 926 void MediaRouterMojoImpl::EventPageWakeComplete(bool success) { | 926 void MediaRouterMojoImpl::EventPageWakeComplete(bool success) { |
| 927 if (success) { | 927 if (success) { |
| 928 MediaRouterMetrics::RecordMediaRouteProviderWakeReason( | 928 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeReason( |
| 929 current_wake_reason_); | 929 current_wake_reason_); |
| 930 ClearWakeReason(); | 930 ClearWakeReason(); |
| 931 MediaRouterMetrics::RecordMediaRouteProviderWakeup( | 931 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeup( |
| 932 MediaRouteProviderWakeup::SUCCESS); | 932 MediaRouteProviderWakeup::SUCCESS); |
| 933 return; | 933 return; |
| 934 } | 934 } |
| 935 | 935 |
| 936 // This is likely an non-retriable error. Drop the pending requests. | 936 // This is likely an non-retriable error. Drop the pending requests. |
| 937 DLOG_WITH_INSTANCE(ERROR) | 937 DLOG_WITH_INSTANCE(ERROR) |
| 938 << "An error encountered while waking the event page."; | 938 << "An error encountered while waking the event page."; |
| 939 ClearWakeReason(); | 939 ClearWakeReason(); |
| 940 DrainPendingRequests(); | 940 DrainPendingRequests(); |
| 941 MediaRouterMetrics::RecordMediaRouteProviderWakeup( | 941 MediaRouterMojoMetrics::RecordMediaRouteProviderWakeup( |
| 942 MediaRouteProviderWakeup::ERROR_UNKNOWN); | 942 MediaRouteProviderWakeup::ERROR_UNKNOWN); |
| 943 } | 943 } |
| 944 | 944 |
| 945 void MediaRouterMojoImpl::DrainPendingRequests() { | 945 void MediaRouterMojoImpl::DrainPendingRequests() { |
| 946 DLOG_WITH_INSTANCE(ERROR) | 946 DLOG_WITH_INSTANCE(ERROR) |
| 947 << "Draining request queue. (queue-length=" << pending_requests_.size() | 947 << "Draining request queue. (queue-length=" << pending_requests_.size() |
| 948 << ")"; | 948 << ")"; |
| 949 pending_requests_.clear(); | 949 pending_requests_.clear(); |
| 950 } | 950 } |
| 951 | 951 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 980 } | 980 } |
| 981 | 981 |
| 982 void MediaRouterMojoImpl::OnFirewallCheckComplete( | 982 void MediaRouterMojoImpl::OnFirewallCheckComplete( |
| 983 bool firewall_can_use_local_ports) { | 983 bool firewall_can_use_local_ports) { |
| 984 if (firewall_can_use_local_ports) | 984 if (firewall_can_use_local_ports) |
| 985 EnsureMdnsDiscoveryEnabled(); | 985 EnsureMdnsDiscoveryEnabled(); |
| 986 } | 986 } |
| 987 #endif | 987 #endif |
| 988 | 988 |
| 989 } // namespace media_router | 989 } // namespace media_router |
| OLD | NEW |