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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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. |
103 static void UpdateMetricsServiceState(JNIEnv* env, | 103 static void UpdateMetricsServiceState(JNIEnv* env, |
104 const JavaParamRef<jobject>& obj, | 104 const JavaParamRef<jobject>& obj, |
105 jboolean may_record, | 105 jboolean may_record, |
106 jboolean may_upload) { | 106 jboolean may_upload) { |
107 metrics::MetricsService* metrics = g_browser_process->metrics_service(); | 107 // Used to detect when consent to record changes. Initiallized to false to |
108 DCHECK(metrics); | 108 // treat the startup path as a change when consent has been given. |
Alexei Svitkine (slow)
2016/08/18 06:16:39
Hmm, I am bit confused by this.
In my CL that add
jwd
2016/08/18 15:47:56
Shoot, yeah, should have caught that. But I do bel
Alexei Svitkine (slow)
2016/08/18 16:00:30
I think we should try to get to (4) eventually - m
jwd
2016/08/18 21:00:47
Currently, non-trivial, since the Update call is d
jwd
2016/08/23 18:40:03
Added the is_change parameter, and made it so that
| |
109 static bool last_may_record = false; | |
109 | 110 |
110 if (metrics->recording_active() != may_record) { | 111 if (last_may_record != may_record) { |
112 last_may_record = may_record; | |
113 | |
111 UpdateMetricsPrefsOnPermissionChange(may_record); | 114 UpdateMetricsPrefsOnPermissionChange(may_record); |
112 | 115 |
113 // This function puts a consent file with the ClientID in the | 116 // This function ensures a consent file in the data directory is either |
114 // data directory. The ID is passed to the renderer for crash | 117 // created, or deleted, depending on may_record. Starting up metrics |
115 // reporting when things go wrong. | 118 // services will ensure that the consent file contains the ClientID. The ID |
119 // is passed to the renderer for crash reporting when things go wrong. | |
116 content::BrowserThread::GetBlockingPool()->PostTask(FROM_HERE, | 120 content::BrowserThread::GetBlockingPool()->PostTask(FROM_HERE, |
117 base::Bind( | 121 base::Bind( |
118 base::IgnoreResult(GoogleUpdateSettings::SetCollectStatsConsent), | 122 base::IgnoreResult(GoogleUpdateSettings::SetCollectStatsConsent), |
119 may_record)); | 123 may_record)); |
120 } | 124 } |
121 | 125 |
122 g_browser_process->GetMetricsServicesManager()->UpdatePermissions( | 126 // This will also apply the consent state, taken from Chrome Local State |
123 may_record, may_upload); | 127 // prefs. |
128 g_browser_process->GetMetricsServicesManager()->UpdateUploadPermissions( | |
129 may_upload); | |
124 } | 130 } |
125 | 131 |
126 // Renderer process crashed in the foreground. | 132 // Renderer process crashed in the foreground. |
127 static void LogRendererCrash(JNIEnv*, const JavaParamRef<jclass>&) { | 133 static void LogRendererCrash(JNIEnv*, const JavaParamRef<jclass>&) { |
128 DCHECK(g_browser_process); | 134 DCHECK(g_browser_process); |
129 // Increment the renderer crash count in stability metrics. | 135 // Increment the renderer crash count in stability metrics. |
130 PrefService* pref = g_browser_process->local_state(); | 136 PrefService* pref = g_browser_process->local_state(); |
131 DCHECK(pref); | 137 DCHECK(pref); |
132 int value = pref->GetInteger(metrics::prefs::kStabilityRendererCrashCount); | 138 int value = pref->GetInteger(metrics::prefs::kStabilityRendererCrashCount); |
133 pref->SetInteger(metrics::prefs::kStabilityRendererCrashCount, value + 1); | 139 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. | 223 // We should have only one UmaSessionStats instance. |
218 DCHECK(!g_uma_session_stats); | 224 DCHECK(!g_uma_session_stats); |
219 g_uma_session_stats = new UmaSessionStats(); | 225 g_uma_session_stats = new UmaSessionStats(); |
220 return reinterpret_cast<intptr_t>(g_uma_session_stats); | 226 return reinterpret_cast<intptr_t>(g_uma_session_stats); |
221 } | 227 } |
222 | 228 |
223 // Register native methods | 229 // Register native methods |
224 bool RegisterUmaSessionStats(JNIEnv* env) { | 230 bool RegisterUmaSessionStats(JNIEnv* env) { |
225 return RegisterNativesImpl(env); | 231 return RegisterNativesImpl(env); |
226 } | 232 } |
OLD | NEW |