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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/AppIndexingUtil.java

Issue 2826803002: Add UMA for CopylessPaste cache (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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; 5 package org.chromium.chrome.browser;
6 6
7 import android.os.SystemClock; 7 import android.os.SystemClock;
8 import android.util.LruCache; 8 import android.util.LruCache;
9 import android.webkit.URLUtil; 9 import android.webkit.URLUtil;
10 10
11 import org.chromium.base.Callback; 11 import org.chromium.base.Callback;
12 import org.chromium.base.SysUtils; 12 import org.chromium.base.SysUtils;
13 import org.chromium.base.VisibleForTesting; 13 import org.chromium.base.VisibleForTesting;
14 import org.chromium.base.metrics.RecordHistogram;
14 import org.chromium.blink.mojom.document_metadata.CopylessPaste; 15 import org.chromium.blink.mojom.document_metadata.CopylessPaste;
15 import org.chromium.blink.mojom.document_metadata.WebPage; 16 import org.chromium.blink.mojom.document_metadata.WebPage;
16 import org.chromium.chrome.browser.historyreport.AppIndexingReporter; 17 import org.chromium.chrome.browser.historyreport.AppIndexingReporter;
17 import org.chromium.chrome.browser.tab.Tab; 18 import org.chromium.chrome.browser.tab.Tab;
18 import org.chromium.content_public.browser.RenderFrameHost; 19 import org.chromium.content_public.browser.RenderFrameHost;
19 import org.chromium.content_public.browser.WebContents; 20 import org.chromium.content_public.browser.WebContents;
20 import org.chromium.services.service_manager.InterfaceProvider; 21 import org.chromium.services.service_manager.InterfaceProvider;
21 22
22 /** 23 /**
23 * This is the top-level CopylessPaste metadata extraction for AppIndexing. 24 * This is the top-level CopylessPaste metadata extraction for AppIndexing.
24 */ 25 */
25 public class AppIndexingUtil { 26 public class AppIndexingUtil {
26 private static final int CACHE_SIZE = 100; 27 private static final int CACHE_SIZE = 100;
27 private static final int CACHE_VISIT_CUTOFF_MS = 60 * 60 * 1000; // 1 hour 28 private static final int CACHE_VISIT_CUTOFF_MS = 60 * 60 * 1000; // 1 hour
28 // Cache of recently seen urls. If a url is among the CACHE_SIZE most recent pages visited, and 29 // Cache of recently seen urls. If a url is among the CACHE_SIZE most recent pages visited, and
29 // the parse was in the last CACHE_VISIT_CUTOFF_MS milliseconds, then we don 't parse the page, 30 // the parse was in the last CACHE_VISIT_CUTOFF_MS milliseconds, then we don 't parse the page,
30 // and instead just report the view (not the content) to App Indexing. 31 // and instead just report the view (not the content) to App Indexing.
31 private LruCache<String, CacheEntry> mPageCache; 32 private LruCache<String, CacheEntry> mPageCache;
32 33
33 private static Callback<WebPage> sCallbackForTesting; 34 private static Callback<WebPage> sCallbackForTesting;
34 35
36 // Constants used to log UMA "enum" histograms about the cache state.
jwd 2017/04/19 18:49:16 Add that the values should not be changed or reuse
37 private static final int CACHE_HIT_WITH_ENTITY = 0;
38 private static final int CACHE_HIT_WITHOUT_ENTITY = 1;
39 private static final int CACHE_MISS = 2;
40 private static final int CACHE_HISTOGRAM_BOUNDARY = 3;
41
35 /** 42 /**
36 * Extracts entities from document metadata and reports it to on-device App Indexing. 43 * Extracts entities from document metadata and reports it to on-device App Indexing.
37 * This call can cache entities from recently parsed webpages, in which case , only the url and 44 * This call can cache entities from recently parsed webpages, in which case , only the url and
38 * title of the page is reported to App Indexing. 45 * title of the page is reported to App Indexing.
39 */ 46 */
40 public void extractCopylessPasteMetadata(final Tab tab) { 47 public void extractCopylessPasteMetadata(final Tab tab) {
41 final String url = tab.getUrl(); 48 final String url = tab.getUrl();
42 boolean isHttpOrHttps = URLUtil.isHttpsUrl(url) || URLUtil.isHttpUrl(url ); 49 boolean isHttpOrHttps = URLUtil.isHttpsUrl(url) || URLUtil.isHttpUrl(url );
43 if (!isEnabledForDevice() || tab.isIncognito() || !isHttpOrHttps) { 50 if (!isEnabledForDevice() || tab.isIncognito() || !isHttpOrHttps) {
44 return; 51 return;
45 } 52 }
46 53
47 // There are three conditions that can occur with respect to the cache. 54 // There are three conditions that can occur with respect to the cache.
48 // 1. Cache hit, and an entity was found previously. Report only the pag e view to App 55 // 1. Cache hit, and an entity was found previously. Report only the pag e view to App
49 // Indexing. 56 // Indexing.
50 // 2. Cache hit, but no entity was found. Ignore. 57 // 2. Cache hit, but no entity was found. Ignore.
51 // 3. Cache miss, we need to parse the page. 58 // 3. Cache miss, we need to parse the page.
52 if (wasPageVisitedRecently(url)) { 59 if (wasPageVisitedRecently(url)) {
53 if (lastPageVisitContainedEntity(url)) { 60 if (lastPageVisitContainedEntity(url)) {
54 // Condition 1 61 // Condition 1
62 RecordHistogram.recordEnumeratedHistogram(
63 "CopylessPaste.CacheHit", CACHE_HIT_WITH_ENTITY, CACHE_H ISTOGRAM_BOUNDARY);
55 getAppIndexingReporter().reportWebPageView(url, tab.getTitle()); 64 getAppIndexingReporter().reportWebPageView(url, tab.getTitle());
65 return;
56 } 66 }
57 // Condition 2 67 // Condition 2
68 RecordHistogram.recordEnumeratedHistogram(
69 "CopylessPaste.CacheHit", CACHE_HIT_WITHOUT_ENTITY, CACHE_HI STOGRAM_BOUNDARY);
58 } else { 70 } else {
59 // Condition 3 71 // Condition 3
72 RecordHistogram.recordEnumeratedHistogram(
73 "CopylessPaste.CacheHit", CACHE_MISS, CACHE_HISTOGRAM_BOUNDA RY);
60 CopylessPaste copylessPaste = getCopylessPasteInterface(tab); 74 CopylessPaste copylessPaste = getCopylessPasteInterface(tab);
61 if (copylessPaste == null) { 75 if (copylessPaste == null) {
62 return; 76 return;
63 } 77 }
64 copylessPaste.getEntities(new CopylessPaste.GetEntitiesResponse() { 78 copylessPaste.getEntities(new CopylessPaste.GetEntitiesResponse() {
65 @Override 79 @Override
66 public void call(WebPage webpage) { 80 public void call(WebPage webpage) {
67 putCacheEntry(url, webpage != null); 81 putCacheEntry(url, webpage != null);
68 if (sCallbackForTesting != null) { 82 if (sCallbackForTesting != null) {
69 sCallbackForTesting.onResult(webpage); 83 sCallbackForTesting.onResult(webpage);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 mPageCache = new LruCache<String, CacheEntry>(CACHE_SIZE); 161 mPageCache = new LruCache<String, CacheEntry>(CACHE_SIZE);
148 } 162 }
149 return mPageCache; 163 return mPageCache;
150 } 164 }
151 165
152 private static class CacheEntry { 166 private static class CacheEntry {
153 public long lastSeenTimeMs; 167 public long lastSeenTimeMs;
154 public boolean containedEntity; 168 public boolean containedEntity;
155 } 169 }
156 } 170 }
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698