Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: chrome/browser/media/router/media_router_mojo_impl.cc

Issue 1765143002: [Media Router] Add UMA histograms tracking component extension version/wakeups (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move media_router_metrics_unittest to non_android Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/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"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 71
72 MediaRouterMojoImpl::MediaSinksQuery::MediaSinksQuery() = default; 72 MediaRouterMojoImpl::MediaSinksQuery::MediaSinksQuery() = default;
73 73
74 MediaRouterMojoImpl::MediaSinksQuery::~MediaSinksQuery() = default; 74 MediaRouterMojoImpl::MediaSinksQuery::~MediaSinksQuery() = default;
75 75
76 MediaRouterMojoImpl::MediaRouterMojoImpl( 76 MediaRouterMojoImpl::MediaRouterMojoImpl(
77 extensions::EventPageTracker* event_page_tracker) 77 extensions::EventPageTracker* event_page_tracker)
78 : event_page_tracker_(event_page_tracker), 78 : event_page_tracker_(event_page_tracker),
79 instance_id_(base::GenerateGUID()), 79 instance_id_(base::GenerateGUID()),
80 availability_(interfaces::MediaRouter::SinkAvailability::UNAVAILABLE), 80 availability_(interfaces::MediaRouter::SinkAvailability::UNAVAILABLE),
81 wakeup_attempt_count_(0),
82 current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT), 81 current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT),
83 weak_factory_(this) { 82 weak_factory_(this) {
84 DCHECK(event_page_tracker_); 83 DCHECK(event_page_tracker_);
85 } 84 }
86 85
87 MediaRouterMojoImpl::~MediaRouterMojoImpl() { 86 MediaRouterMojoImpl::~MediaRouterMojoImpl() {
88 DCHECK(thread_checker_.CalledOnValidThread()); 87 DCHECK(thread_checker_.CalledOnValidThread());
89 } 88 }
90 89
91 // static 90 // static
92 void MediaRouterMojoImpl::BindToRequest( 91 void MediaRouterMojoImpl::BindToRequest(
93 const std::string& extension_id, 92 const extensions::Extension* extension,
94 content::BrowserContext* context, 93 content::BrowserContext* context,
95 mojo::InterfaceRequest<interfaces::MediaRouter> request) { 94 mojo::InterfaceRequest<interfaces::MediaRouter> request) {
96 MediaRouterMojoImpl* impl = static_cast<MediaRouterMojoImpl*>( 95 MediaRouterMojoImpl* impl = static_cast<MediaRouterMojoImpl*>(
97 MediaRouterFactory::GetApiForBrowserContext(context)); 96 MediaRouterFactory::GetApiForBrowserContext(context));
98 DCHECK(impl); 97 DCHECK(impl);
99 98
100 impl->BindToMojoRequest(std::move(request), extension_id); 99 impl->BindToMojoRequest(std::move(request), *extension);
101 } 100 }
102 101
103 void MediaRouterMojoImpl::BindToMojoRequest( 102 void MediaRouterMojoImpl::BindToMojoRequest(
104 mojo::InterfaceRequest<interfaces::MediaRouter> request, 103 mojo::InterfaceRequest<interfaces::MediaRouter> request,
105 const std::string& extension_id) { 104 const extensions::Extension& extension) {
106 DCHECK(thread_checker_.CalledOnValidThread()); 105 DCHECK(thread_checker_.CalledOnValidThread());
107 106
108 binding_.reset( 107 binding_.reset(
109 new mojo::Binding<interfaces::MediaRouter>(this, std::move(request))); 108 new mojo::Binding<interfaces::MediaRouter>(this, std::move(request)));
110 binding_->set_connection_error_handler(base::Bind( 109 binding_->set_connection_error_handler(base::Bind(
111 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); 110 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this)));
112 111
113 media_route_provider_extension_id_ = extension_id; 112 media_route_provider_extension_id_ = extension.id();
113 if (!provider_version_was_recorded_) {
114 MediaRouterMetrics::RecordMediaRouteProviderVersion(extension);
115 provider_version_was_recorded_ = true;
116 }
114 } 117 }
115 118
116 void MediaRouterMojoImpl::OnConnectionError() { 119 void MediaRouterMojoImpl::OnConnectionError() {
117 DCHECK(thread_checker_.CalledOnValidThread()); 120 DCHECK(thread_checker_.CalledOnValidThread());
118 121
119 media_route_provider_.reset(); 122 media_route_provider_.reset();
120 binding_.reset(); 123 binding_.reset();
121 124
122 // If |OnConnectionError| is invoked while there are pending requests, then 125 // If |OnConnectionError| is invoked while there are pending requests, then
123 // it means we tried to wake the extension, but weren't able to complete the 126 // it means we tried to wake the extension, but weren't able to complete the
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 } 855 }
853 } 856 }
854 857
855 void MediaRouterMojoImpl::AttemptWakeEventPage() { 858 void MediaRouterMojoImpl::AttemptWakeEventPage() {
856 ++wakeup_attempt_count_; 859 ++wakeup_attempt_count_;
857 if (wakeup_attempt_count_ > kMaxWakeupAttemptCount) { 860 if (wakeup_attempt_count_ > kMaxWakeupAttemptCount) {
858 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 "
859 << "page."; 862 << "page.";
860 DrainPendingRequests(); 863 DrainPendingRequests();
861 wakeup_attempt_count_ = 0; 864 wakeup_attempt_count_ = 0;
865 MediaRouterMetrics::RecordMediaRouteProviderWakeup(
866 MediaRouteProviderWakeup::ERROR_TOO_MANY_RETRIES);
862 return; 867 return;
863 } 868 }
864 869
865 DVLOG_WITH_INSTANCE(1) << "Attempting to wake up event page: attempt " 870 DVLOG_WITH_INSTANCE(1) << "Attempting to wake up event page: attempt "
866 << wakeup_attempt_count_; 871 << wakeup_attempt_count_;
867 872
868 // This return false if the extension is already awake. 873 // This return false if the extension is already awake.
869 // Callback is bound using WeakPtr because |event_page_tracker_| outlives 874 // Callback is bound using WeakPtr because |event_page_tracker_| outlives
870 // |this|. 875 // |this|.
871 if (!event_page_tracker_->WakeEventPage( 876 if (!event_page_tracker_->WakeEventPage(
(...skipping 14 matching lines...) Expand all
886 next_request.Run(); 891 next_request.Run();
887 892
888 pending_requests_.clear(); 893 pending_requests_.clear();
889 } 894 }
890 895
891 void MediaRouterMojoImpl::EventPageWakeComplete(bool success) { 896 void MediaRouterMojoImpl::EventPageWakeComplete(bool success) {
892 if (success) { 897 if (success) {
893 MediaRouterMetrics::RecordMediaRouteProviderWakeReason( 898 MediaRouterMetrics::RecordMediaRouteProviderWakeReason(
894 current_wake_reason_); 899 current_wake_reason_);
895 ClearWakeReason(); 900 ClearWakeReason();
901 MediaRouterMetrics::RecordMediaRouteProviderWakeup(
902 MediaRouteProviderWakeup::SUCCESS);
896 return; 903 return;
897 } 904 }
898 905
899 // This is likely an non-retriable error. Drop the pending requests. 906 // This is likely an non-retriable error. Drop the pending requests.
900 DLOG_WITH_INSTANCE(ERROR) 907 DLOG_WITH_INSTANCE(ERROR)
901 << "An error encountered while waking the event page."; 908 << "An error encountered while waking the event page.";
902 ClearWakeReason(); 909 ClearWakeReason();
903 DrainPendingRequests(); 910 DrainPendingRequests();
911 MediaRouterMetrics::RecordMediaRouteProviderWakeup(
912 MediaRouteProviderWakeup::ERROR_UNKNOWN);
904 } 913 }
905 914
906 void MediaRouterMojoImpl::DrainPendingRequests() { 915 void MediaRouterMojoImpl::DrainPendingRequests() {
907 DLOG_WITH_INSTANCE(ERROR) 916 DLOG_WITH_INSTANCE(ERROR)
908 << "Draining request queue. (queue-length=" << pending_requests_.size() 917 << "Draining request queue. (queue-length=" << pending_requests_.size()
909 << ")"; 918 << ")";
910 pending_requests_.clear(); 919 pending_requests_.clear();
911 } 920 }
912 921
913 void MediaRouterMojoImpl::SetWakeReason(MediaRouteProviderWakeReason reason) { 922 void MediaRouterMojoImpl::SetWakeReason(MediaRouteProviderWakeReason reason) {
914 DCHECK(reason != MediaRouteProviderWakeReason::TOTAL_COUNT); 923 DCHECK(reason != MediaRouteProviderWakeReason::TOTAL_COUNT);
915 if (current_wake_reason_ == MediaRouteProviderWakeReason::TOTAL_COUNT) 924 if (current_wake_reason_ == MediaRouteProviderWakeReason::TOTAL_COUNT)
916 current_wake_reason_ = reason; 925 current_wake_reason_ = reason;
917 } 926 }
918 927
919 void MediaRouterMojoImpl::ClearWakeReason() { 928 void MediaRouterMojoImpl::ClearWakeReason() {
920 DCHECK(current_wake_reason_ != MediaRouteProviderWakeReason::TOTAL_COUNT); 929 DCHECK(current_wake_reason_ != MediaRouteProviderWakeReason::TOTAL_COUNT);
921 current_wake_reason_ = MediaRouteProviderWakeReason::TOTAL_COUNT; 930 current_wake_reason_ = MediaRouteProviderWakeReason::TOTAL_COUNT;
922 } 931 }
923 932
924 } // namespace media_router 933 } // namespace media_router
OLDNEW
« no previous file with comments | « chrome/browser/media/router/media_router_mojo_impl.h ('k') | chrome/browser/media/router/media_router_mojo_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698