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

Side by Side Diff: chrome/browser/android/metrics/uma_session_stats.cc

Issue 2248243002: Enabling sampling of UMA and crash reports on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Theresa's and dfalcantara's comments with sync Created 4 years, 3 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/android/metrics/uma_session_stats.h" 5 #include "chrome/browser/android/metrics/uma_session_stats.h"
6 6
7 #include "base/android/jni_array.h" 7 #include "base/android/jni_array.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 86 }
87 87
88 // static 88 // static
89 void UmaSessionStats::RegisterSyntheticMultiGroupFieldTrial( 89 void UmaSessionStats::RegisterSyntheticMultiGroupFieldTrial(
90 const std::string& trial_name, 90 const std::string& trial_name,
91 const std::vector<uint32_t>& group_name_hashes) { 91 const std::vector<uint32_t>& group_name_hashes) {
92 ChromeMetricsServiceAccessor::RegisterSyntheticMultiGroupFieldTrial( 92 ChromeMetricsServiceAccessor::RegisterSyntheticMultiGroupFieldTrial(
93 trial_name, group_name_hashes); 93 trial_name, group_name_hashes);
94 } 94 }
95 95
96 // Starts/stops the MetricsService when permissions have changed. 96 // Updates metrics reporting state managed by native code. This should only be
97 // called when consent is changing, and UpdateMetricsServiceState() should be
98 // called immediately after for metrics services to be started or stopped as
99 // needed. This is enforced by UmaSessionStats.changeMetricsReportingConsent on
100 // the Java side.
101 static void ChangeMetricsReportingConsent(JNIEnv*,
102 const JavaParamRef<jclass>&,
103 jboolean consent) {
104 UpdateMetricsPrefsOnPermissionChange(consent);
105
106 // This function ensures a consent file in the data directory is either
107 // created, or deleted, depending on consent. Starting up metrics services
108 // will ensure that the consent file contains the ClientID. The ID is passed
109 // to the renderer for crash reporting when things go wrong.
110 content::BrowserThread::GetBlockingPool()->PostTask(
111 FROM_HERE, base::Bind(base::IgnoreResult(
112 GoogleUpdateSettings::SetCollectStatsConsent),
113 consent));
114 }
115
116 // Starts/stops the MetricsService based on existing consent and upload
117 // preferences.
97 // There are three possible states: 118 // There are three possible states:
98 // * Logs are being recorded and being uploaded to the server. 119 // * Logs are being recorded and being uploaded to the server.
99 // * Logs are being recorded, but not being uploaded to the server. 120 // * Logs are being recorded, but not being uploaded to the server.
100 // This happens when we've got permission to upload on Wi-Fi but we're on a 121 // This happens when we've got permission to upload on Wi-Fi but we're on a
101 // mobile connection (for example). 122 // mobile connection (for example).
102 // * Logs are neither being recorded or uploaded. 123 // * Logs are neither being recorded or uploaded.
103 static void UpdateMetricsServiceState(JNIEnv* env, 124 // If logs aren't being recorded, then |may_upload| is ignored.
104 const JavaParamRef<jobject>& obj, 125 //
105 jboolean may_record, 126 // This can be called at any time when consent hasn't changed, such as
127 // connection type change, or start up. If consent has changed, then
128 // ChangeMetricsReportingConsent() should be called first.
129 static void UpdateMetricsServiceState(JNIEnv*,
130 const JavaParamRef<jclass>&,
106 jboolean may_upload) { 131 jboolean may_upload) {
107 metrics::MetricsService* metrics = g_browser_process->metrics_service(); 132 // This will also apply the consent state, taken from Chrome Local State
108 DCHECK(metrics); 133 // prefs.
109 134 g_browser_process->GetMetricsServicesManager()->UpdateUploadPermissions(
110 if (metrics->recording_active() != may_record) { 135 may_upload);
111 UpdateMetricsPrefsOnPermissionChange(may_record);
112
113 // This function puts a consent file with the ClientID in the
114 // data directory. The ID is passed to the renderer for crash
115 // reporting when things go wrong.
116 content::BrowserThread::GetBlockingPool()->PostTask(FROM_HERE,
117 base::Bind(
118 base::IgnoreResult(GoogleUpdateSettings::SetCollectStatsConsent),
119 may_record));
120 }
121
122 g_browser_process->GetMetricsServicesManager()->UpdatePermissions(
123 may_record, may_upload);
124 } 136 }
125 137
126 // Renderer process crashed in the foreground. 138 // Renderer process crashed in the foreground.
127 static void LogRendererCrash(JNIEnv*, const JavaParamRef<jclass>&) { 139 static void LogRendererCrash(JNIEnv*, const JavaParamRef<jclass>&) {
128 DCHECK(g_browser_process); 140 DCHECK(g_browser_process);
129 // Increment the renderer crash count in stability metrics. 141 // Increment the renderer crash count in stability metrics.
130 PrefService* pref = g_browser_process->local_state(); 142 PrefService* pref = g_browser_process->local_state();
131 DCHECK(pref); 143 DCHECK(pref);
132 int value = pref->GetInteger(metrics::prefs::kStabilityRendererCrashCount); 144 int value = pref->GetInteger(metrics::prefs::kStabilityRendererCrashCount);
133 pref->SetInteger(metrics::prefs::kStabilityRendererCrashCount, value + 1); 145 pref->SetInteger(metrics::prefs::kStabilityRendererCrashCount, value + 1);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // We should have only one UmaSessionStats instance. 229 // We should have only one UmaSessionStats instance.
218 DCHECK(!g_uma_session_stats); 230 DCHECK(!g_uma_session_stats);
219 g_uma_session_stats = new UmaSessionStats(); 231 g_uma_session_stats = new UmaSessionStats();
220 return reinterpret_cast<intptr_t>(g_uma_session_stats); 232 return reinterpret_cast<intptr_t>(g_uma_session_stats);
221 } 233 }
222 234
223 // Register native methods 235 // Register native methods
224 bool RegisterUmaSessionStats(JNIEnv* env) { 236 bool RegisterUmaSessionStats(JNIEnv* env) {
225 return RegisterNativesImpl(env); 237 return RegisterNativesImpl(env);
226 } 238 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698