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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // Updates metrics reporting state managed by native code. |
| 97 static void ChangeMetricsReportingConsent(JNIEnv*, |
| 98 const JavaParamRef<jclass>&, |
| 99 jboolean consent) { |
| 100 UpdateMetricsPrefsOnPermissionChange(consent); |
| 101 |
| 102 // This function ensures a consent file in the data directory is either |
| 103 // created, or deleted, depending on consent. Starting up metrics services |
| 104 // will ensure that the consent file contains the ClientID. The ID is passed |
| 105 // to the renderer for crash reporting when things go wrong. |
| 106 content::BrowserThread::GetBlockingPool()->PostTask( |
| 107 FROM_HERE, base::Bind(base::IgnoreResult( |
| 108 GoogleUpdateSettings::SetCollectStatsConsent), |
| 109 consent)); |
| 110 } |
| 111 |
96 // Starts/stops the MetricsService when permissions have changed. | 112 // Starts/stops the MetricsService when permissions have changed. |
97 // There are three possible states: | 113 // There are three possible states: |
98 // * Logs are being recorded and being uploaded to the server. | 114 // * Logs are being recorded and being uploaded to the server. |
99 // * Logs are being recorded, but not being uploaded to the server. | 115 // * 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 | 116 // This happens when we've got permission to upload on Wi-Fi but we're on a |
101 // mobile connection (for example). | 117 // mobile connection (for example). |
102 // * Logs are neither being recorded or uploaded. | 118 // * Logs are neither being recorded or uploaded. |
103 static void UpdateMetricsServiceState(JNIEnv* env, | 119 static void UpdateMetricsServiceState(JNIEnv*, |
104 const JavaParamRef<jobject>& obj, | 120 const JavaParamRef<jclass>&, |
105 jboolean may_record, | 121 jboolean may_record, |
106 jboolean may_upload) { | 122 jboolean may_upload) { |
107 metrics::MetricsService* metrics = g_browser_process->metrics_service(); | 123 DCHECK(may_record || !may_upload); |
108 DCHECK(metrics); | |
109 | 124 |
110 if (metrics->recording_active() != may_record) { | 125 // This will also apply the consent state, taken from Chrome Local State |
111 UpdateMetricsPrefsOnPermissionChange(may_record); | 126 // prefs. |
112 | 127 g_browser_process->GetMetricsServicesManager()->UpdateUploadPermissions( |
113 // This function puts a consent file with the ClientID in the | 128 may_upload); |
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 } | 129 } |
125 | 130 |
126 // Renderer process crashed in the foreground. | 131 // Renderer process crashed in the foreground. |
127 static void LogRendererCrash(JNIEnv*, const JavaParamRef<jclass>&) { | 132 static void LogRendererCrash(JNIEnv*, const JavaParamRef<jclass>&) { |
128 DCHECK(g_browser_process); | 133 DCHECK(g_browser_process); |
129 // Increment the renderer crash count in stability metrics. | 134 // Increment the renderer crash count in stability metrics. |
130 PrefService* pref = g_browser_process->local_state(); | 135 PrefService* pref = g_browser_process->local_state(); |
131 DCHECK(pref); | 136 DCHECK(pref); |
132 int value = pref->GetInteger(metrics::prefs::kStabilityRendererCrashCount); | 137 int value = pref->GetInteger(metrics::prefs::kStabilityRendererCrashCount); |
133 pref->SetInteger(metrics::prefs::kStabilityRendererCrashCount, value + 1); | 138 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. | 222 // We should have only one UmaSessionStats instance. |
218 DCHECK(!g_uma_session_stats); | 223 DCHECK(!g_uma_session_stats); |
219 g_uma_session_stats = new UmaSessionStats(); | 224 g_uma_session_stats = new UmaSessionStats(); |
220 return reinterpret_cast<intptr_t>(g_uma_session_stats); | 225 return reinterpret_cast<intptr_t>(g_uma_session_stats); |
221 } | 226 } |
222 | 227 |
223 // Register native methods | 228 // Register native methods |
224 bool RegisterUmaSessionStats(JNIEnv* env) { | 229 bool RegisterUmaSessionStats(JNIEnv* env) { |
225 return RegisterNativesImpl(env); | 230 return RegisterNativesImpl(env); |
226 } | 231 } |
OLD | NEW |