From 23911c85198ae5dd2ed9d7046d5106e3982d1f2e Mon Sep 17 00:00:00 2001 From: wnwen Date: Tue, 21 Apr 2015 10:43:45 -0700 Subject: Migrate the rest of PathUtils calls to run in background. Follow-up for http://crrev.com/1091843002, to have all callers start async tasks in order to fetch directory paths to avoid I/O on the UI thread. BUG=473353 Review URL: https://codereview.chromium.org/1093223002 Cr-Commit-Position: refs/heads/master@{#326065} --- .../java/src/org/chromium/base/PathUtils.java | 43 +++------------------- 1 file changed, 6 insertions(+), 37 deletions(-) (limited to 'base') diff --git a/base/android/java/src/org/chromium/base/PathUtils.java b/base/android/java/src/org/chromium/base/PathUtils.java index bcd850c..edaa634 100644 --- a/base/android/java/src/org/chromium/base/PathUtils.java +++ b/base/android/java/src/org/chromium/base/PathUtils.java @@ -16,8 +16,6 @@ import java.util.concurrent.ExecutionException; */ public abstract class PathUtils { - private static String sDataDirectorySuffix; - private static final int DATA_DIRECTORY = 0; private static final int DATABASE_DIRECTORY = 1; private static final int CACHE_DIRECTORY = 2; @@ -28,22 +26,6 @@ public abstract class PathUtils { private PathUtils() {} /** - * Sets the suffix that should be used for the directory where private data is to be stored - * by the application. - * - * TODO(wnwen): Remove this after all clients have migrated and add asserts for not null. - * - * @param suffix The private data directory suffix. - * @see Context#getDir(String, int) - * @deprecated - */ - @Deprecated - public static void setPrivateDataDirectorySuffix(String suffix) { - sDirPathFetchTask = null; - sDataDirectorySuffix = suffix; - } - - /** * Starts an asynchronous task to fetch the path of the directory where private data is to be * stored by the application. * @@ -51,7 +33,6 @@ public abstract class PathUtils { * @see Context#getDir(String, int) */ public static void setPrivateDataDirectorySuffix(String suffix, final Context appContext) { - sDataDirectorySuffix = null; sDirPathFetchTask = new AsyncTask() { @Override protected String[] doInBackground(String... dataDirectorySuffix) { @@ -83,15 +64,8 @@ public abstract class PathUtils { */ @CalledByNative public static String getDataDirectory(Context appContext) { - if (sDataDirectorySuffix == null && sDirPathFetchTask == null) { - throw new IllegalStateException( - "setDataDirectorySuffix must be called before getDataDirectory"); - } else if (sDirPathFetchTask != null) { - return getDirectoryPath(DATA_DIRECTORY); - } else { - // Temporarily allow UI thread directory fetching until all callers have been migrated. - return appContext.getDir(sDataDirectorySuffix, Context.MODE_PRIVATE).getPath(); - } + assert sDirPathFetchTask != null : "setDataDirectorySuffix must be called first."; + return getDirectoryPath(DATA_DIRECTORY); } /** @@ -99,11 +73,8 @@ public abstract class PathUtils { */ @CalledByNative public static String getDatabaseDirectory(Context appContext) { - if (sDirPathFetchTask != null) { - return getDirectoryPath(DATABASE_DIRECTORY); - } - // Context.getDatabasePath() returns path for the provided filename. - return appContext.getDatabasePath("foo").getParent(); + assert sDirPathFetchTask != null : "setDataDirectorySuffix must be called first."; + return getDirectoryPath(DATABASE_DIRECTORY); } /** @@ -112,10 +83,8 @@ public abstract class PathUtils { @SuppressWarnings("unused") @CalledByNative public static String getCacheDirectory(Context appContext) { - if (sDirPathFetchTask != null) { - return getDirectoryPath(CACHE_DIRECTORY); - } - return appContext.getCacheDir().getPath(); + assert sDirPathFetchTask != null : "setDataDirectorySuffix must be called first."; + return getDirectoryPath(CACHE_DIRECTORY); } /** -- cgit v1.1