summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorwnwen <wnwen@chromium.org>2015-08-10 12:29:59 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-10 19:30:32 +0000
commit4a7568dffab924d3710a68949dca0717bdad3352 (patch)
tree580e87271baa863fbf78c54c51716d4e04cf605b /base
parent8fc82b21621f21ea8d2d8cb483cb14295d1f6e1f (diff)
downloadchromium_src-4a7568dffab924d3710a68949dca0717bdad3352.zip
chromium_src-4a7568dffab924d3710a68949dca0717bdad3352.tar.gz
chromium_src-4a7568dffab924d3710a68949dca0717bdad3352.tar.bz2
Pre-cache downloads directory path in PathUtils.
When Chrome tabs are swiped away and user starts Chrome again, their default downloads directory is requested. This causes a StrictMode policy violation since it results in a ~60ms disk read. Thus by adding this call to the initial AsyncTask we save that time when the directory is requested by native. This must only be called in the browser process as the sandbox processes do not need to make the call nor can they make the call(results in NPE). BUG=508615 Review URL: https://codereview.chromium.org/1281273003 Cr-Commit-Position: refs/heads/master@{#342672}
Diffstat (limited to 'base')
-rw-r--r--base/android/java/src/org/chromium/base/PathUtils.java10
1 files changed, 7 insertions, 3 deletions
diff --git a/base/android/java/src/org/chromium/base/PathUtils.java b/base/android/java/src/org/chromium/base/PathUtils.java
index 8d676fa..05697e2 100644
--- a/base/android/java/src/org/chromium/base/PathUtils.java
+++ b/base/android/java/src/org/chromium/base/PathUtils.java
@@ -23,7 +23,8 @@ public abstract class PathUtils {
private static final int DATA_DIRECTORY = 0;
private static final int DATABASE_DIRECTORY = 1;
private static final int CACHE_DIRECTORY = 2;
- private static final int NUM_DIRECTORIES = 3;
+ private static final int DOWNLOADS_DIRECTORY = 3;
+ private static final int NUM_DIRECTORIES = 4;
private static AsyncTask<String, Void, String[]> sDirPathFetchTask;
private static File sThumbnailDirectory;
@@ -49,7 +50,10 @@ public abstract class PathUtils {
paths[DATABASE_DIRECTORY] = appContext.getDatabasePath("foo").getParent();
// TODO(wnwen): Find a way to avoid calling this function in renderer process.
if (appContext.getCacheDir() != null) {
+ // These paths are only available in the browser process.
paths[CACHE_DIRECTORY] = appContext.getCacheDir().getPath();
+ paths[DOWNLOADS_DIRECTORY] = Environment.getExternalStoragePublicDirectory(
+ Environment.DIRECTORY_DOWNLOADS).getPath();
}
return paths;
}
@@ -115,8 +119,8 @@ public abstract class PathUtils {
@SuppressWarnings("unused")
@CalledByNative
private static String getDownloadsDirectory(Context appContext) {
- return Environment.getExternalStoragePublicDirectory(
- Environment.DIRECTORY_DOWNLOADS).getPath();
+ assert sDirPathFetchTask != null : "setDataDirectorySuffix must be called first.";
+ return getDirectoryPath(DOWNLOADS_DIRECTORY);
}
/**