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

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

Issue 1312153003: jni_generator: Pass object parameters as JavaParamRef. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 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_string.h" 7 #include "base/android/jni_string.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 group_name); 85 group_name);
86 } 86 }
87 87
88 // Starts/stops the MetricsService when permissions have changed. 88 // Starts/stops the MetricsService when permissions have changed.
89 // There are three possible states: 89 // There are three possible states:
90 // * Logs are being recorded and being uploaded to the server. 90 // * Logs are being recorded and being uploaded to the server.
91 // * Logs are being recorded, but not being uploaded to the server. 91 // * Logs are being recorded, but not being uploaded to the server.
92 // This happens when we've got permission to upload on Wi-Fi but we're on a 92 // This happens when we've got permission to upload on Wi-Fi but we're on a
93 // mobile connection (for example). 93 // mobile connection (for example).
94 // * Logs are neither being recorded or uploaded. 94 // * Logs are neither being recorded or uploaded.
95 static void UpdateMetricsServiceState(JNIEnv* env, jobject obj, 95 static void UpdateMetricsServiceState(JNIEnv* env,
96 jboolean may_record, jboolean may_upload) { 96 const JavaParamRef<jobject>& obj,
97 jboolean may_record,
98 jboolean may_upload) {
97 metrics::MetricsService* metrics = g_browser_process->metrics_service(); 99 metrics::MetricsService* metrics = g_browser_process->metrics_service();
98 DCHECK(metrics); 100 DCHECK(metrics);
99 101
100 if (metrics->recording_active() != may_record) { 102 if (metrics->recording_active() != may_record) {
101 // This function puts a consent file with the ClientID in the 103 // This function puts a consent file with the ClientID in the
102 // data directory. The ID is passed to the renderer for crash 104 // data directory. The ID is passed to the renderer for crash
103 // reporting when things go wrong. 105 // reporting when things go wrong.
104 content::BrowserThread::GetBlockingPool()->PostTask(FROM_HERE, 106 content::BrowserThread::GetBlockingPool()->PostTask(FROM_HERE,
105 base::Bind( 107 base::Bind(
106 base::IgnoreResult(GoogleUpdateSettings::SetCollectStatsConsent), 108 base::IgnoreResult(GoogleUpdateSettings::SetCollectStatsConsent),
107 may_record)); 109 may_record));
108 } 110 }
109 111
110 g_browser_process->GetMetricsServicesManager()->UpdatePermissions( 112 g_browser_process->GetMetricsServicesManager()->UpdatePermissions(
111 may_record, may_upload); 113 may_record, may_upload);
112 } 114 }
113 115
114 // Renderer process crashed in the foreground. 116 // Renderer process crashed in the foreground.
115 static void LogRendererCrash(JNIEnv* env, jclass clazz, jboolean is_paused) { 117 static void LogRendererCrash(JNIEnv* env,
118 const JavaParamRef<jclass>& clazz,
119 jboolean is_paused) {
116 DCHECK(g_browser_process); 120 DCHECK(g_browser_process);
117 121
118 if (!is_paused) { 122 if (!is_paused) {
119 // Increment the renderer crash count in stability metrics. 123 // Increment the renderer crash count in stability metrics.
120 PrefService* pref = g_browser_process->local_state(); 124 PrefService* pref = g_browser_process->local_state();
121 DCHECK(pref); 125 DCHECK(pref);
122 int value = pref->GetInteger(prefs::kStabilityRendererCrashCount); 126 int value = pref->GetInteger(prefs::kStabilityRendererCrashCount);
123 pref->SetInteger(prefs::kStabilityRendererCrashCount, value + 1); 127 pref->SetInteger(prefs::kStabilityRendererCrashCount, value + 1);
124 } 128 }
125 129
126 // Note: When we are paused, any UI metric we increment may not make it to 130 // Note: When we are paused, any UI metric we increment may not make it to
127 // the disk before we are killed. Treat the count below as a lower bound. 131 // the disk before we are killed. Treat the count below as a lower bound.
128 content::RecordAction(base::UserMetricsAction("MobileRendererCrashed")); 132 content::RecordAction(base::UserMetricsAction("MobileRendererCrashed"));
129 } 133 }
130 134
131 static void RegisterExternalExperiment(JNIEnv* env, 135 static void RegisterExternalExperiment(JNIEnv* env,
132 jclass clazz, 136 const JavaParamRef<jclass>& clazz,
133 jint study_id, 137 jint study_id,
134 jint experiment_id) { 138 jint experiment_id) {
135 const std::string group_name_utf8 = base::IntToString(experiment_id); 139 const std::string group_name_utf8 = base::IntToString(experiment_id);
136 140
137 variations::ActiveGroupId active_group; 141 variations::ActiveGroupId active_group;
138 active_group.name = static_cast<uint32>(study_id); 142 active_group.name = static_cast<uint32>(study_id);
139 active_group.group = metrics::HashName(group_name_utf8); 143 active_group.group = metrics::HashName(group_name_utf8);
140 variations::AssociateGoogleVariationIDForceHashes( 144 variations::AssociateGoogleVariationIDForceHashes(
141 variations::GOOGLE_WEB_PROPERTIES, active_group, 145 variations::GOOGLE_WEB_PROPERTIES, active_group,
142 static_cast<variations::VariationID>(experiment_id)); 146 static_cast<variations::VariationID>(experiment_id));
143 147
144 UmaSessionStats::RegisterSyntheticFieldTrialWithNameHash( 148 UmaSessionStats::RegisterSyntheticFieldTrialWithNameHash(
145 static_cast<uint32_t>(study_id), group_name_utf8); 149 static_cast<uint32_t>(study_id), group_name_utf8);
146 } 150 }
147 151
148 static void RegisterSyntheticFieldTrial(JNIEnv* env, 152 static void RegisterSyntheticFieldTrial(
149 jclass clazz, 153 JNIEnv* env,
150 jstring jtrial_name, 154 const JavaParamRef<jclass>& clazz,
151 jstring jgroup_name) { 155 const JavaParamRef<jstring>& jtrial_name,
156 const JavaParamRef<jstring>& jgroup_name) {
152 std::string trial_name(ConvertJavaStringToUTF8(env, jtrial_name)); 157 std::string trial_name(ConvertJavaStringToUTF8(env, jtrial_name));
153 std::string group_name(ConvertJavaStringToUTF8(env, jgroup_name)); 158 std::string group_name(ConvertJavaStringToUTF8(env, jgroup_name));
154 UmaSessionStats::RegisterSyntheticFieldTrial(trial_name, group_name); 159 UmaSessionStats::RegisterSyntheticFieldTrial(trial_name, group_name);
155 } 160 }
156 161
157 static void RecordMultiWindowSession(JNIEnv*, jclass, 162 static void RecordMultiWindowSession(JNIEnv*,
163 const JavaParamRef<jclass>&,
158 jint area_percent, 164 jint area_percent,
159 jint instance_count) { 165 jint instance_count) {
160 UMA_HISTOGRAM_PERCENTAGE("MobileStartup.MobileMultiWindowSession", 166 UMA_HISTOGRAM_PERCENTAGE("MobileStartup.MobileMultiWindowSession",
161 area_percent); 167 area_percent);
162 // Make sure the bucket count is the same as the range. This currently 168 // Make sure the bucket count is the same as the range. This currently
163 // expects no more than 10 simultaneous multi window instances. 169 // expects no more than 10 simultaneous multi window instances.
164 UMA_HISTOGRAM_CUSTOM_COUNTS("MobileStartup.MobileMultiWindowInstances", 170 UMA_HISTOGRAM_CUSTOM_COUNTS("MobileStartup.MobileMultiWindowInstances",
165 instance_count, 171 instance_count,
166 1 /* min */, 172 1 /* min */,
167 10 /* max */, 173 10 /* max */,
168 10 /* bucket count */); 174 10 /* bucket count */);
169 } 175 }
170 176
171 static void RecordTabCountPerLoad(JNIEnv*, jclass, jint num_tabs) { 177 static void RecordTabCountPerLoad(JNIEnv*,
178 const JavaParamRef<jclass>&,
179 jint num_tabs) {
172 // Record how many tabs total are open. 180 // Record how many tabs total are open.
173 UMA_HISTOGRAM_CUSTOM_COUNTS("Tabs.TabCountPerLoad", num_tabs, 1, 200, 50); 181 UMA_HISTOGRAM_CUSTOM_COUNTS("Tabs.TabCountPerLoad", num_tabs, 1, 200, 50);
174 } 182 }
175 183
176 static void RecordPageLoaded(JNIEnv*, jclass, jboolean is_desktop_user_agent) { 184 static void RecordPageLoaded(JNIEnv*,
185 const JavaParamRef<jclass>&,
186 jboolean is_desktop_user_agent) {
177 // Should be called whenever a page has been loaded. 187 // Should be called whenever a page has been loaded.
178 content::RecordAction(UserMetricsAction("MobilePageLoaded")); 188 content::RecordAction(UserMetricsAction("MobilePageLoaded"));
179 if (is_desktop_user_agent) { 189 if (is_desktop_user_agent) {
180 content::RecordAction( 190 content::RecordAction(
181 UserMetricsAction("MobilePageLoadedDesktopUserAgent")); 191 UserMetricsAction("MobilePageLoadedDesktopUserAgent"));
182 } 192 }
183 } 193 }
184 194
185 static void RecordPageLoadedWithKeyboard(JNIEnv*, jclass) { 195 static void RecordPageLoadedWithKeyboard(JNIEnv*, const JavaParamRef<jclass>&) {
186 content::RecordAction(UserMetricsAction("MobilePageLoadedWithKeyboard")); 196 content::RecordAction(UserMetricsAction("MobilePageLoadedWithKeyboard"));
187 } 197 }
188 198
189 static jlong Init(JNIEnv* env, jclass obj) { 199 static jlong Init(JNIEnv* env, const JavaParamRef<jclass>& obj) {
190 // We should have only one UmaSessionStats instance. 200 // We should have only one UmaSessionStats instance.
191 DCHECK(!g_uma_session_stats); 201 DCHECK(!g_uma_session_stats);
192 g_uma_session_stats = new UmaSessionStats(); 202 g_uma_session_stats = new UmaSessionStats();
193 return reinterpret_cast<intptr_t>(g_uma_session_stats); 203 return reinterpret_cast<intptr_t>(g_uma_session_stats);
194 } 204 }
195 205
196 // Register native methods 206 // Register native methods
197 bool RegisterUmaSessionStats(JNIEnv* env) { 207 bool RegisterUmaSessionStats(JNIEnv* env) {
198 return RegisterNativesImpl(env); 208 return RegisterNativesImpl(env);
199 } 209 }
OLDNEW
« no previous file with comments | « chrome/browser/android/metrics/launch_metrics.cc ('k') | chrome/browser/android/metrics/variations_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698