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

Unified Diff: base/android/java/src/org/chromium/base/ResourceExtractor.java

Issue 851503003: Update from https://crrev.com/311076 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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 | « DEPS ('k') | base/android/jni_array.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/android/java/src/org/chromium/base/ResourceExtractor.java
diff --git a/base/android/java/src/org/chromium/base/ResourceExtractor.java b/base/android/java/src/org/chromium/base/ResourceExtractor.java
index 37fea6c863de3eb1d4941be7afb6adcf8f6b3463..5beb07dcb8975cc6743c2a18894a7d3d6b41ba5c 100644
--- a/base/android/java/src/org/chromium/base/ResourceExtractor.java
+++ b/base/android/java/src/org/chromium/base/ResourceExtractor.java
@@ -4,12 +4,15 @@
package org.chromium.base;
+import android.annotation.TargetApi;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.os.AsyncTask;
+import android.os.Build;
+import android.os.Trace;
import android.preference.PreferenceManager;
import android.util.Log;
@@ -52,15 +55,20 @@ public class ResourceExtractor {
public ExtractTask() {
}
- @Override
- protected Void doInBackground(Void... unused) {
+ private void doInBackgroundImpl() {
final File outputDir = getOutputDir();
if (!outputDir.exists() && !outputDir.mkdirs()) {
Log.e(LOGTAG, "Unable to create pak resources directory!");
- return null;
+ return;
}
- String timestampFile = checkPakTimestamp(outputDir);
+ String timestampFile = null;
+ beginTraceSection("checkPakTimeStamp");
+ try {
+ timestampFile = checkPakTimestamp(outputDir);
+ } finally {
+ endTraceSection();
+ }
if (timestampFile != null) {
deleteFiles();
}
@@ -72,7 +80,7 @@ public class ResourceExtractor {
String currentLanguage = currentLocale.split("-", 2)[0];
if (prefs.getString(LAST_LANGUAGE, "").equals(currentLanguage)
- && filenames.size() >= sMandatoryPaks.length) {
+ && filenames.size() >= sMandatoryPaks.length) {
boolean filesPresent = true;
for (String file : filenames) {
if (!new File(outputDir, file).exists()) {
@@ -80,7 +88,7 @@ public class ResourceExtractor {
break;
}
}
- if (filesPresent) return null;
+ if (filesPresent) return;
} else {
prefs.edit().putString(LAST_LANGUAGE, currentLanguage).apply();
}
@@ -93,9 +101,9 @@ public class ResourceExtractor {
if (sExtractImplicitLocalePak) {
if (p.length() > 0) p.append('|');
- // As well as the minimum required set of .paks above, we'll also add all .paks that
- // we have for the user's currently selected language.
-
+ // As well as the minimum required set of .paks above, we'll
+ // also add all .paks that we have for the user's currently
+ // selected language.
p.append(currentLanguage);
p.append("(-\\w+)?\\.pak");
}
@@ -103,6 +111,7 @@ public class ResourceExtractor {
Pattern paksToInstall = Pattern.compile(p.toString());
AssetManager manager = mContext.getResources().getAssets();
+ beginTraceSection("WalkAssets");
try {
// Loop through every asset file that we have in the APK, and look for the
// ones that we need to extract by trying to match the Patterns that we
@@ -114,16 +123,16 @@ public class ResourceExtractor {
continue;
}
boolean isAppDataFile = file.equals(ICU_DATA_FILENAME)
- || file.equals(V8_NATIVES_DATA_FILENAME)
- || file.equals(V8_SNAPSHOT_DATA_FILENAME);
- File output = new File(isAppDataFile
- ? getAppDataDir() : outputDir, file);
+ || file.equals(V8_NATIVES_DATA_FILENAME)
+ || file.equals(V8_SNAPSHOT_DATA_FILENAME);
+ File output = new File(isAppDataFile ? getAppDataDir() : outputDir, file);
if (output.exists()) {
continue;
}
InputStream is = null;
OutputStream os = null;
+ beginTraceSection("ExtractResource");
try {
is = manager.open(file);
os = new FileOutputStream(output);
@@ -159,6 +168,7 @@ public class ResourceExtractor {
if (os != null) {
os.close();
}
+ endTraceSection(); // ExtractResource
}
}
}
@@ -169,11 +179,12 @@ public class ResourceExtractor {
// this happens with regularity.
Log.w(LOGTAG, "Exception unpacking required pak resources: " + e.getMessage());
deleteFiles();
- return null;
+ return;
+ } finally {
+ endTraceSection(); // WalkAssets
}
// Finished, write out a timestamp file if we need to.
-
if (timestampFile != null) {
try {
new File(outputDir, timestampFile).createNewFile();
@@ -186,6 +197,20 @@ public class ResourceExtractor {
// TODO(yusufo): Figure out why remove is required here.
prefs.edit().remove(PAK_FILENAMES).apply();
prefs.edit().putStringSet(PAK_FILENAMES, filenames).apply();
+ }
+
+ @Override
+ protected Void doInBackground(Void... unused) {
+ // TODO(lizeb): Use chrome tracing here (and above in
+ // doInBackgroundImpl) when it will be possible. This is currently
+ // not doable since the native library is not loaded yet, and the
+ // TraceEvent calls are dropped before this point.
+ beginTraceSection("ResourceExtractor.ExtractTask.doInBackground");
+ try {
+ doInBackgroundImpl();
+ } finally {
+ endTraceSection();
+ }
return null;
}
@@ -233,6 +258,18 @@ public class ResourceExtractor {
// timestamp file is already up-to date.
return null;
}
+
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
+ private void beginTraceSection(String section) {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) return;
+ Trace.beginSection(section);
+ }
+
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
+ private void endTraceSection() {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) return;
+ Trace.endSection();
+ }
}
private final Context mContext;
« no previous file with comments | « DEPS ('k') | base/android/jni_array.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698