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

Side by Side Diff: base/android/java/src/org/chromium/base/metrics/CachedMetrics.java

Issue 2435813002: Move Java CachedMetrics functionality to base/. (Closed)
Patch Set: Fix compile. Created 4 years, 2 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 2016 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 package org.chromium.chrome.browser.metrics; 5 package org.chromium.base.metrics;
6 6
7 import android.util.Pair;
8
9 import org.chromium.base.annotations.JNINamespace;
10 import org.chromium.base.library_loader.LibraryLoader; 7 import org.chromium.base.library_loader.LibraryLoader;
11 import org.chromium.base.metrics.RecordHistogram;
12 import org.chromium.base.metrics.RecordUserAction;
13 import org.chromium.content_public.browser.WebContents;
14 8
15 import java.util.ArrayList; 9 import java.util.ArrayList;
16 import java.util.List; 10 import java.util.List;
17 import java.util.concurrent.TimeUnit; 11 import java.util.concurrent.TimeUnit;
18 12
19 /** 13 /**
20 * Used for recording metrics about Chrome launches that need to be recorded bef ore the native 14 * Utility classes for recording UMA metrics before the native library
21 * library may have been loaded. Metrics are cached until the library is known to be loaded, then 15 * may have been loaded. Metrics are cached until the library is known
22 * committed to the MetricsService all at once. 16 * to be loaded, then committed to the MetricsService all at once.
23 */ 17 */
24 @JNINamespace("metrics") 18 public class CachedMetrics {
25 public class LaunchMetrics {
26
27 /** 19 /**
28 * Creating an instance of a subclass of this class automatically adds it to a list of objects 20 * Creating an instance of a subclass of this class automatically adds it to a list of objects
29 * that are committed when the native library is available. 21 * that are committed when the native library is available.
30 */ 22 */
31 private abstract static class CachedHistogram { 23 private abstract static class CachedHistogram {
32 private static final List<CachedHistogram> sEvents = new ArrayList<Cache dHistogram>(); 24 private static final List<CachedHistogram> sEvents = new ArrayList<Cache dHistogram>();
33 25
34 protected final String mHistogramName; 26 protected final String mHistogramName;
35 27
36 /** 28 /**
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 152
161 @Override 153 @Override
162 protected void commitAndClear() { 154 protected void commitAndClear() {
163 for (Long sample : mSamples) { 155 for (Long sample : mSamples) {
164 recordWithNative(sample); 156 recordWithNative(sample);
165 } 157 }
166 mSamples.clear(); 158 mSamples.clear();
167 } 159 }
168 } 160 }
169 161
170 // Each list item is a pair of the url and where it was added from e.g. from the add to
171 // homescreen menu item, an app banner, or unknown. The mapping of int sourc e values to
172 // their string names is found in the C++ ShortcutInfo struct.
173 private static final List<Pair<String, Integer>> sActivityUrls =
174 new ArrayList<Pair<String, Integer>>();
175 private static final List<Pair<String, Integer>> sTabUrls =
176 new ArrayList<Pair<String, Integer>>();
177
178 private static final List<Long> sWebappHistogramTimes = new ArrayList<Long>( );
179
180 /** 162 /**
181 * Records the launch of a standalone Activity for a URL (i.e. a WebappActiv ity) 163 * Calls out to native code to commit any cached histograms and events.
182 * added from a specific source. 164 * Should be called once the native library has been loaded.
183 * @param url URL that kicked off the Activity's creation.
184 * @param source integer id of the source from where the URL was added.
185 */ 165 */
186 public static void recordHomeScreenLaunchIntoStandaloneActivity(String url, int source) { 166 public static void commitCachedMetrics() {
187 sActivityUrls.add(new Pair<String, Integer>(url, source));
188 }
189
190 /**
191 * Records the launch of a Tab for a URL (i.e. a Home screen shortcut).
192 * @param url URL that kicked off the Tab's creation.
193 * @param source integer id of the source from where the URL was added.
194 */
195 public static void recordHomeScreenLaunchIntoTab(String url, int source) {
196 sTabUrls.add(new Pair<String, Integer>(url, source));
197 }
198
199 /**
200 * Records the time it took to look up from disk whether a MAC is valid duri ng webapp startup.
201 * @param time the number of milliseconds it took to finish.
202 */
203 public static void recordWebappHistogramTimes(long time) {
204 sWebappHistogramTimes.add(time);
205 }
206
207 /**
208 * Calls out to native code to record URLs that have been launched via the H ome screen.
209 * This intermediate step is necessary because Activity.onCreate() may be ca lled when
210 * the native library has not yet been loaded.
211 * @param webContents WebContents for the current Tab.
212 */
213 public static void commitLaunchMetrics(WebContents webContents) {
214 for (Pair<String, Integer> item : sActivityUrls) {
215 nativeRecordLaunch(true, item.first, item.second, webContents);
216 }
217 sActivityUrls.clear();
218
219 for (Pair<String, Integer> item : sTabUrls) {
220 nativeRecordLaunch(false, item.first, item.second, webContents);
221 }
222 sTabUrls.clear();
223
224 // Record generic cached events.
225 for (CachedHistogram event : CachedHistogram.sEvents) event.commitAndCle ar(); 167 for (CachedHistogram event : CachedHistogram.sEvents) event.commitAndCle ar();
226 } 168 }
227
228 /**
229 * Records metrics about the state of the homepage on launch.
230 * @param showHomeButton Whether the home button is shown.
231 * @param homepageIsNtp Whether the homepage is set to the NTP.
232 * @param homepageUrl The value of the homepage URL.
233 */
234 public static void recordHomePageLaunchMetrics(
235 boolean showHomeButton, boolean homepageIsNtp, String homepageUrl) {
236 if (homepageUrl == null) {
237 homepageUrl = "";
238 assert !showHomeButton : "Homepage should be disabled for a null URL ";
239 }
240 nativeRecordHomePageLaunchMetrics(showHomeButton, homepageIsNtp, homepag eUrl);
241 }
242
243 private static native void nativeRecordLaunch(
244 boolean standalone, String url, int source, WebContents webContents) ;
245 private static native void nativeRecordHomePageLaunchMetrics(
246 boolean showHomeButton, boolean homepageIsNtp, String homepageUrl);
247 } 169 }
OLDNEW
« no previous file with comments | « base/BUILD.gn ('k') | chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabBottomBarDelegate.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698