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

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

Issue 2263333002: Disable StrictMode for disk reads during Snippet formatting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Timed only text formatting. Created 4 years, 4 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 | tools/metrics/histograms/histograms.xml » ('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 9d35c8cf5674a68b8a751df3eee51a4149a99ff9..eb3fe3bf2ddad6ce4930bd14aaad9b7b4da27bba 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
@@ -11,6 +11,8 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.media.ThumbnailUtils;
+import android.os.StrictMode;
+import android.os.SystemClock;
import android.support.v4.text.BidiFormatter;
import android.text.format.DateUtils;
import android.view.ContextMenu;
@@ -44,6 +46,7 @@ import org.chromium.components.variations.VariationsAssociatedData;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.concurrent.TimeUnit;
/**
* A class that represents the view for a single card snippet.
@@ -284,13 +287,27 @@ public class SnippetArticleViewHolder extends CardViewHolder
mHeadlineTextView.setText(mArticle.mTitle);
- // We format the publisher here so that having a publisher name in an RTL language doesn't
- // mess up the formatting on an LTR device and vice versa.
- String publisherAttribution = String.format(PUBLISHER_FORMAT_STRING,
- BidiFormatter.getInstance().unicodeWrap(mArticle.mPublisher),
- DateUtils.getRelativeTimeSpanString(mArticle.mPublishTimestampMilliseconds,
- System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS));
- mPublisherTextView.setText(publisherAttribution);
+ // DateUtils.getRelativeTimeSpanString(...) calls through to TimeZone.getDefault(). If this
+ // has never been called before it loads the current time zone from disk. In most likelihood
+ // this will have been called previously and the current time zone will have been cached,
+ // but in some cases (eg instrumentation tests) it will cause a strict mode violation.
+ StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
+ try {
+ long time = SystemClock.elapsedRealtime();
+ CharSequence relativeTimeSpan = DateUtils.getRelativeTimeSpanString(
+ mArticle.mPublishTimestampMilliseconds, System.currentTimeMillis(),
+ DateUtils.MINUTE_IN_MILLIS);
+ RecordHistogram.recordTimesHistogram("Android.StrictMode.SnippetUIBuildTime",
+ SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS);
+
+ // We format the publisher here so that having a publisher name in an RTL language
+ // doesn't mess up the formatting on an LTR device and vice versa.
+ String publisherAttribution = String.format(PUBLISHER_FORMAT_STRING,
+ BidiFormatter.getInstance().unicodeWrap(mArticle.mPublisher), relativeTimeSpan);
+ mPublisherTextView.setText(publisherAttribution);
+ } finally {
+ StrictMode.setThreadPolicy(oldPolicy);
+ }
// The favicon of the publisher should match the textview height.
int widthSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
« 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