Chromium Code Reviews| 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/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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 // Starts/stops the MetricsService when permissions have changed. |
| 97 // There are three possible states: | 97 // There are three possible states: |
| 98 // * Logs are being recorded and being uploaded to the server. | 98 // * Logs are being recorded and being uploaded to the server. |
| 99 // * Logs are being recorded, but not being uploaded to the server. | 99 // * 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 | 100 // This happens when we've got permission to upload on Wi-Fi but we're on a |
| 101 // mobile connection (for example). | 101 // mobile connection (for example). |
| 102 // * Logs are neither being recorded or uploaded. | 102 // * Logs are neither being recorded or uploaded. |
|
Ilya Sherman
2016/08/23 21:32:17
Could you please document |consent_change| as well
Ilya Sherman
2016/08/23 21:32:17
This list sounds like there ought to be an asserti
jwd
2016/08/23 23:00:58
Done.
jwd
2016/08/23 23:00:59
Re-worked some of the code to avoid that parameter
Ilya Sherman
2016/08/24 05:02:50
Now may_record is also unused. Is it still needed
jwd
2016/08/24 15:06:27
Well, it's needed for the DCHECK ;P. Note, there i
| |
| 103 static void UpdateMetricsServiceState(JNIEnv* env, | 103 static void UpdateMetricsServiceState(JNIEnv*, |
| 104 const JavaParamRef<jobject>& obj, | 104 const JavaParamRef<jclass>&, |
| 105 jboolean consent_change, | |
| 105 jboolean may_record, | 106 jboolean may_record, |
| 106 jboolean may_upload) { | 107 jboolean may_upload) { |
| 107 metrics::MetricsService* metrics = g_browser_process->metrics_service(); | 108 if (consent_change) { |
| 108 DCHECK(metrics); | |
| 109 | |
| 110 if (metrics->recording_active() != may_record) { | |
| 111 UpdateMetricsPrefsOnPermissionChange(may_record); | 109 UpdateMetricsPrefsOnPermissionChange(may_record); |
| 112 | 110 |
| 113 // This function puts a consent file with the ClientID in the | 111 // This function ensures a consent file in the data directory is either |
| 114 // data directory. The ID is passed to the renderer for crash | 112 // created, or deleted, depending on may_record. Starting up metrics |
| 115 // reporting when things go wrong. | 113 // services will ensure that the consent file contains the ClientID. The ID |
| 114 // is passed to the renderer for crash reporting when things go wrong. | |
| 116 content::BrowserThread::GetBlockingPool()->PostTask(FROM_HERE, | 115 content::BrowserThread::GetBlockingPool()->PostTask(FROM_HERE, |
| 117 base::Bind( | 116 base::Bind( |
| 118 base::IgnoreResult(GoogleUpdateSettings::SetCollectStatsConsent), | 117 base::IgnoreResult(GoogleUpdateSettings::SetCollectStatsConsent), |
| 119 may_record)); | 118 may_record)); |
| 120 } | 119 } |
| 121 | 120 |
| 122 g_browser_process->GetMetricsServicesManager()->UpdatePermissions( | 121 // This will also apply the consent state, taken from Chrome Local State |
| 123 may_record, may_upload); | 122 // prefs. |
| 123 g_browser_process->GetMetricsServicesManager()->UpdateUploadPermissions( | |
| 124 may_upload); | |
| 124 } | 125 } |
| 125 | 126 |
| 126 // Renderer process crashed in the foreground. | 127 // Renderer process crashed in the foreground. |
| 127 static void LogRendererCrash(JNIEnv*, const JavaParamRef<jclass>&) { | 128 static void LogRendererCrash(JNIEnv*, const JavaParamRef<jclass>&) { |
| 128 DCHECK(g_browser_process); | 129 DCHECK(g_browser_process); |
| 129 // Increment the renderer crash count in stability metrics. | 130 // Increment the renderer crash count in stability metrics. |
| 130 PrefService* pref = g_browser_process->local_state(); | 131 PrefService* pref = g_browser_process->local_state(); |
| 131 DCHECK(pref); | 132 DCHECK(pref); |
| 132 int value = pref->GetInteger(metrics::prefs::kStabilityRendererCrashCount); | 133 int value = pref->GetInteger(metrics::prefs::kStabilityRendererCrashCount); |
| 133 pref->SetInteger(metrics::prefs::kStabilityRendererCrashCount, value + 1); | 134 pref->SetInteger(metrics::prefs::kStabilityRendererCrashCount, value + 1); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 // We should have only one UmaSessionStats instance. | 218 // We should have only one UmaSessionStats instance. |
| 218 DCHECK(!g_uma_session_stats); | 219 DCHECK(!g_uma_session_stats); |
| 219 g_uma_session_stats = new UmaSessionStats(); | 220 g_uma_session_stats = new UmaSessionStats(); |
| 220 return reinterpret_cast<intptr_t>(g_uma_session_stats); | 221 return reinterpret_cast<intptr_t>(g_uma_session_stats); |
| 221 } | 222 } |
| 222 | 223 |
| 223 // Register native methods | 224 // Register native methods |
| 224 bool RegisterUmaSessionStats(JNIEnv* env) { | 225 bool RegisterUmaSessionStats(JNIEnv* env) { |
| 225 return RegisterNativesImpl(env); | 226 return RegisterNativesImpl(env); |
| 226 } | 227 } |
| OLD | NEW |