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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/offlinepages/evaluation/OfflinePageEvaluationBridge.java

Issue 2562283004: [Offline Pages] Use async log writing to avoid violating StrictMode. (Closed)
Patch Set: More comments. Created 4 years 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 | no next file » | 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/offlinepages/evaluation/OfflinePageEvaluationBridge.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/evaluation/OfflinePageEvaluationBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/evaluation/OfflinePageEvaluationBridge.java
index 5be2a6e165ea8b6c057b03c09a77915a3d49e004..dfd5d201bc82e6a7490fee83120f9e129b43bf50 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/evaluation/OfflinePageEvaluationBridge.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/evaluation/OfflinePageEvaluationBridge.java
@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.offlinepages.evaluation;
+import android.os.AsyncTask;
+
import org.chromium.base.Callback;
import org.chromium.base.Log;
import org.chromium.base.ObserverList;
@@ -64,6 +66,25 @@ public class OfflinePageEvaluationBridge {
}
/**
+ * Class used for writing logs to external log file asynchronously to prevent violating strict
+ * mode during test.
+ */
+ private class LogTask extends AsyncTask<String, Void, Void> {
+ @Override
+ protected Void doInBackground(String... strings) {
+ try {
+ synchronized (mLogOutput) {
+ mLogOutput.write(strings[0]);
+ mLogOutput.flush();
+ }
+ } catch (IOException e) {
+ Log.e(TAG, e.getMessage(), e);
+ }
+ return null;
+ }
+ }
+
+ /**
* Get the instance of the evaluation bridge.
* @param profile The profile used to get bridge.
* @param useEvaluationScheduler True if using the evaluation scheduler instead of the
@@ -166,6 +187,8 @@ public class OfflinePageEvaluationBridge {
}
public void setLogOutputFile(File outputFile) throws IOException {
+ // This open file operation shouldn't happen on UI thread.
+ assert !ThreadUtils.runningOnUiThread();
mLogOutput = new FileWriter(outputFile);
}
@@ -178,15 +201,13 @@ public class OfflinePageEvaluationBridge {
@CalledByNative
public void log(String sourceTag, String message) {
- try {
- Date date = new Date(System.currentTimeMillis());
- SimpleDateFormat formatter =
- new SimpleDateFormat("MM-dd HH:mm:ss.SSS", Locale.getDefault());
- mLogOutput.write(formatter.format(date) + ": " + sourceTag + " | " + message
- + System.getProperty("line.separator"));
- } catch (IOException e) {
- Log.e(TAG, e.getMessage(), e);
- }
+ Date date = new Date(System.currentTimeMillis());
+ SimpleDateFormat formatter =
+ new SimpleDateFormat("MM-dd HH:mm:ss.SSS", Locale.getDefault());
+ String logString = formatter.format(date) + ": " + sourceTag + " | " + message
+ + System.getProperty("line.separator");
+ LogTask logTask = new LogTask();
+ logTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, logString);
}
public void closeLog() {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698