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

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: Cleanups 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
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), 81 wakeup_attempt_count_(0),
82 current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT), 82 current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT),
83 provider_version_recorded_(false),
83 weak_factory_(this) { 84 weak_factory_(this) {
84 DCHECK(event_page_tracker_); 85 DCHECK(event_page_tracker_);
85 } 86 }
86 87
87 MediaRouterMojoImpl::~MediaRouterMojoImpl() { 88 MediaRouterMojoImpl::~MediaRouterMojoImpl() {
88 DCHECK(thread_checker_.CalledOnValidThread()); 89 DCHECK(thread_checker_.CalledOnValidThread());
89 } 90 }
90 91
91 // static 92 // static
92 void MediaRouterMojoImpl::BindToRequest( 93 void MediaRouterMojoImpl::BindToRequest(
93 const std::string& extension_id, 94 const extensions::Extension* extension,
94 content::BrowserContext* context, 95 content::BrowserContext* context,
95 mojo::InterfaceRequest<interfaces::MediaRouter> request) { 96 mojo::InterfaceRequest<interfaces::MediaRouter> request) {
96 MediaRouterMojoImpl* impl = static_cast<MediaRouterMojoImpl*>( 97 MediaRouterMojoImpl* impl = static_cast<MediaRouterMojoImpl*>(
97 MediaRouterFactory::GetApiForBrowserContext(context)); 98 MediaRouterFactory::GetApiForBrowserContext(context));
98 DCHECK(impl); 99 DCHECK(impl);
99 100
100 impl->BindToMojoRequest(std::move(request), extension_id); 101 impl->BindToMojoRequest(std::move(request), *extension);
101 } 102 }
102 103
103 void MediaRouterMojoImpl::BindToMojoRequest( 104 void MediaRouterMojoImpl::BindToMojoRequest(
104 mojo::InterfaceRequest<interfaces::MediaRouter> request, 105 mojo::InterfaceRequest<interfaces::MediaRouter> request,
105 const std::string& extension_id) { 106 const extensions::Extension& extension) {
106 DCHECK(thread_checker_.CalledOnValidThread()); 107 DCHECK(thread_checker_.CalledOnValidThread());
107 108
108 binding_.reset( 109 binding_.reset(
109 new mojo::Binding<interfaces::MediaRouter>(this, std::move(request))); 110 new mojo::Binding<interfaces::MediaRouter>(this, std::move(request)));
110 binding_->set_connection_error_handler(base::Bind( 111 binding_->set_connection_error_handler(base::Bind(
111 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this))); 112 &MediaRouterMojoImpl::OnConnectionError, base::Unretained(this)));
112 113
113 media_route_provider_extension_id_ = extension_id; 114 media_route_provider_extension_id_ = extension.id();
115 if (!provider_version_recorded_) {
116 MediaRouterMetrics::RecordMediaRouteProviderVersion(extension);
117 provider_version_recorded_ = true;
118 }
114 } 119 }
115 120
116 void MediaRouterMojoImpl::OnConnectionError() { 121 void MediaRouterMojoImpl::OnConnectionError() {
117 DCHECK(thread_checker_.CalledOnValidThread()); 122 DCHECK(thread_checker_.CalledOnValidThread());
118 123
119 media_route_provider_.reset(); 124 media_route_provider_.reset();
120 binding_.reset(); 125 binding_.reset();
121 126
122 // If |OnConnectionError| is invoked while there are pending requests, then 127 // 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 128 // it means we tried to wake the extension, but weren't able to complete the
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 } 827 }
823 } 828 }
824 829
825 void MediaRouterMojoImpl::AttemptWakeEventPage() { 830 void MediaRouterMojoImpl::AttemptWakeEventPage() {
826 ++wakeup_attempt_count_; 831 ++wakeup_attempt_count_;
827 if (wakeup_attempt_count_ > kMaxWakeupAttemptCount) { 832 if (wakeup_attempt_count_ > kMaxWakeupAttemptCount) {
828 DLOG_WITH_INSTANCE(ERROR) << "Attempted too many times to wake up event " 833 DLOG_WITH_INSTANCE(ERROR) << "Attempted too many times to wake up event "
829 << "page."; 834 << "page.";
830 DrainPendingRequests(); 835 DrainPendingRequests();
831 wakeup_attempt_count_ = 0; 836 wakeup_attempt_count_ = 0;
837 MediaRouterMetrics::RecordMediaRouteProviderWakeup(
838 MediaRouteProviderWakeup::ERROR_TOO_MANY_RETRIES);
832 return; 839 return;
833 } 840 }
834 841
835 DVLOG_WITH_INSTANCE(1) << "Attempting to wake up event page: attempt " 842 DVLOG_WITH_INSTANCE(1) << "Attempting to wake up event page: attempt "
836 << wakeup_attempt_count_; 843 << wakeup_attempt_count_;
837 844
838 // This return false if the extension is already awake. 845 // This return false if the extension is already awake.
839 // Callback is bound using WeakPtr because |event_page_tracker_| outlives 846 // Callback is bound using WeakPtr because |event_page_tracker_| outlives
840 // |this|. 847 // |this|.
841 if (!event_page_tracker_->WakeEventPage( 848 if (!event_page_tracker_->WakeEventPage(
(...skipping 14 matching lines...) Expand all
856 next_request.Run(); 863 next_request.Run();
857 864
858 pending_requests_.clear(); 865 pending_requests_.clear();
859 } 866 }
860 867
861 void MediaRouterMojoImpl::EventPageWakeComplete(bool success) { 868 void MediaRouterMojoImpl::EventPageWakeComplete(bool success) {
862 if (success) { 869 if (success) {
863 MediaRouterMetrics::RecordMediaRouteProviderWakeReason( 870 MediaRouterMetrics::RecordMediaRouteProviderWakeReason(
864 current_wake_reason_); 871 current_wake_reason_);
865 ClearWakeReason(); 872 ClearWakeReason();
873 MediaRouterMetrics::RecordMediaRouteProviderWakeup(
874 MediaRouteProviderWakeup::SUCCESS);
866 return; 875 return;
867 } 876 }
868 877
869 // This is likely an non-retriable error. Drop the pending requests. 878 // This is likely an non-retriable error. Drop the pending requests.
870 DLOG_WITH_INSTANCE(ERROR) 879 DLOG_WITH_INSTANCE(ERROR)
871 << "An error encountered while waking the event page."; 880 << "An error encountered while waking the event page.";
872 ClearWakeReason(); 881 ClearWakeReason();
873 DrainPendingRequests(); 882 DrainPendingRequests();
883 MediaRouterMetrics::RecordMediaRouteProviderWakeup(
884 MediaRouteProviderWakeup::ERROR_UNKNOWN);
874 } 885 }
875 886
876 void MediaRouterMojoImpl::DrainPendingRequests() { 887 void MediaRouterMojoImpl::DrainPendingRequests() {
877 DLOG_WITH_INSTANCE(ERROR) 888 DLOG_WITH_INSTANCE(ERROR)
878 << "Draining request queue. (queue-length=" << pending_requests_.size() 889 << "Draining request queue. (queue-length=" << pending_requests_.size()
879 << ")"; 890 << ")";
880 pending_requests_.clear(); 891 pending_requests_.clear();
881 } 892 }
882 893
883 void MediaRouterMojoImpl::SetWakeReason(MediaRouteProviderWakeReason reason) { 894 void MediaRouterMojoImpl::SetWakeReason(MediaRouteProviderWakeReason reason) {
884 DCHECK(reason != MediaRouteProviderWakeReason::TOTAL_COUNT); 895 DCHECK(reason != MediaRouteProviderWakeReason::TOTAL_COUNT);
885 if (current_wake_reason_ == MediaRouteProviderWakeReason::TOTAL_COUNT) 896 if (current_wake_reason_ == MediaRouteProviderWakeReason::TOTAL_COUNT)
886 current_wake_reason_ = reason; 897 current_wake_reason_ = reason;
887 } 898 }
888 899
889 void MediaRouterMojoImpl::ClearWakeReason() { 900 void MediaRouterMojoImpl::ClearWakeReason() {
890 DCHECK(current_wake_reason_ != MediaRouteProviderWakeReason::TOTAL_COUNT); 901 DCHECK(current_wake_reason_ != MediaRouteProviderWakeReason::TOTAL_COUNT);
891 current_wake_reason_ = MediaRouteProviderWakeReason::TOTAL_COUNT; 902 current_wake_reason_ = MediaRouteProviderWakeReason::TOTAL_COUNT;
892 } 903 }
893 904
894 } // namespace media_router 905 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698