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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java

Issue 2812243002: [Remote suggestions] Log favicon fetch result for both code paths (Closed)
Patch Set: Comments 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/ntp_snippets/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java
index 2dad1b217748cba66943d746ed405674f9201c46..a5dc53af7e8699f24eabb2560294e79c92df18c5 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java
@@ -205,14 +205,15 @@ public class SnippetArticleViewHolder extends CardViewHolder implements Impressi
// from moving later.
setDefaultFaviconOnView();
try {
+ long faviconFetchStartTimeMs = SystemClock.elapsedRealtime();
Michael van Ouwerkerk 2017/04/13 10:16:22 One way to slightly reduce the omnipresense of thi
jkrcal 2017/04/13 11:37:31 This does not work for fetchFaviconFromLocalCache
URI pageUrl = new URI(mArticle.mUrl);
if (!article.isArticle() || !SnippetsConfig.isFaviconsFromNewServerEnabled()) {
// The old code path. Remove when the experiment is successful.
// Currently, we have to use this for non-articles, due to privacy.
- fetchFaviconFromLocalCache(pageUrl, true);
+ fetchFaviconFromLocalCache(pageUrl, true, faviconFetchStartTimeMs);
} else {
// The new code path.
- fetchFaviconFromLocalCacheOrGoogleServer();
+ fetchFaviconFromLocalCacheOrGoogleServer(faviconFetchStartTimeMs);
}
} catch (URISyntaxException e) {
// Do nothing, stick to the default favicon.
@@ -402,27 +403,52 @@ public class SnippetArticleViewHolder extends CardViewHolder implements Impressi
transitionDrawable.startTransition(FADE_IN_ANIMATION_TIME_MS);
}
- private void fetchFaviconFromLocalCacheOrGoogleServer() {
+ private void fetchFaviconFromLocalCacheOrGoogleServer(final long faviconFetchStartTimeMs) {
// Set the desired size to 0 to specify we do not want to resize in c++, we'll resize here.
mUiDelegate.getSuggestionsSource().fetchSuggestionFavicon(mArticle,
PUBLISHER_FAVICON_MINIMUM_SIZE_PX, /* desiredSizePx */ 0, new Callback<Bitmap>() {
@Override
public void onResult(Bitmap image) {
+ recordFaviconFetchTime(faviconFetchStartTimeMs);
if (image == null) return;
setFaviconOnView(image);
}
});
}
- private void fetchFaviconFromLocalCache(final URI snippetUri, final boolean fallbackToService) {
+ private void recordFaviconFetchTime(long faviconFetchStartTimeMs) {
+ RecordHistogram.recordMediumTimesHistogram(
+ "NewTabPage.ContentSuggestions.ArticleFaviconFetchTime",
+ SystemClock.elapsedRealtime() - faviconFetchStartTimeMs, TimeUnit.MILLISECONDS);
+ }
+
+ private void recordFaviconFetchResult(
+ @FaviconFetchResult int result, long faviconFetchStartTimeMs) {
+ // Record the histogram for articles only to have a fair comparision.
+ if (!mArticle.isArticle()) return;
+ RecordHistogram.recordEnumeratedHistogram(
+ "NewTabPage.ContentSuggestions.ArticleFaviconFetchResult", result,
+ FaviconFetchResult.COUNT);
+ recordFaviconFetchTime(faviconFetchStartTimeMs);
+ }
+
+ private void fetchFaviconFromLocalCache(final URI snippetUri, final boolean fallbackToService,
+ final long faviconFetchStartTimeMs) {
mUiDelegate.getLocalFaviconImageForURL(
getSnippetDomain(snippetUri), mPublisherFaviconSizePx, new FaviconImageCallback() {
@Override
public void onFaviconAvailable(Bitmap image, String iconUrl) {
if (image != null) {
setFaviconOnView(image);
+ recordFaviconFetchResult(fallbackToService
+ ? FaviconFetchResult.SUCCESS_CACHED
+ : FaviconFetchResult.SUCCESS_FETCHED,
+ faviconFetchStartTimeMs);
} else if (fallbackToService) {
- fetchFaviconFromService(snippetUri);
+ if (!fetchFaviconFromService(snippetUri, faviconFetchStartTimeMs)) {
+ recordFaviconFetchResult(
+ FaviconFetchResult.FAILURE, faviconFetchStartTimeMs);
+ }
}
// Else do nothing, we already have the placeholder set.
}
@@ -431,10 +457,11 @@ public class SnippetArticleViewHolder extends CardViewHolder implements Impressi
// TODO(crbug.com/635567): Fix this properly.
@SuppressLint("DefaultLocale")
- private void fetchFaviconFromService(final URI snippetUri) {
- if (!mUseFaviconService) return;
+ private boolean fetchFaviconFromService(
+ final URI snippetUri, final long faviconFetchStartTimeMs) {
+ if (!mUseFaviconService) return false;
int sizePx = getFaviconServiceSupportedSize();
- if (sizePx == 0) return;
+ if (sizePx == 0) return false;
// Replace the default icon by another one from the service when it is fetched.
mUiDelegate.ensureIconIsAvailable(
@@ -443,11 +470,17 @@ public class SnippetArticleViewHolder extends CardViewHolder implements Impressi
/*useLargeIcon=*/false, /*isTemporary=*/true, new IconAvailabilityCallback() {
@Override
public void onIconAvailabilityChecked(boolean newlyAvailable) {
- if (!newlyAvailable) return;
+ if (!newlyAvailable) {
+ recordFaviconFetchResult(
+ FaviconFetchResult.FAILURE, faviconFetchStartTimeMs);
+ return;
+ }
// The download succeeded, the favicon is in the cache; fetch it.
- fetchFaviconFromLocalCache(snippetUri, /*fallbackToService=*/false);
+ fetchFaviconFromLocalCache(
+ snippetUri, /*fallbackToService=*/false, faviconFetchStartTimeMs);
}
});
+ return true;
}
private int getFaviconServiceSupportedSize() {
« no previous file with comments | « no previous file | components/ntp_snippets/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698