| Index: base/android/java/src/org/chromium/base/PathUtils.java
|
| diff --git a/base/android/java/src/org/chromium/base/PathUtils.java b/base/android/java/src/org/chromium/base/PathUtils.java
|
| index 00977d56d576ac94335c6ab0578a86c75b1c2833..1546e001b94f7bb08232759f7bbcddbbcf5a0a9c 100644
|
| --- a/base/android/java/src/org/chromium/base/PathUtils.java
|
| +++ b/base/android/java/src/org/chromium/base/PathUtils.java
|
| @@ -34,9 +34,13 @@ public abstract class PathUtils {
|
| private static final AtomicBoolean sInitializationStarted = new AtomicBoolean();
|
| private static AsyncTask<Void, Void, String[]> sDirPathFetchTask;
|
|
|
| - // If the AsyncTask started in setPrivateDataDirectorySuffix() fails to complete by the time we
|
| - // need the values, we will need the suffix so that we can restart the task synchronously on
|
| - // the UI thread.
|
| + // In setPrivateDataDirectorySuffix(), we store the app's context. If the AsyncTask started in
|
| + // setPrivateDataDirectorySuffix() fails to complete by the time we need the values, we will
|
| + // need the context so that we can restart the task synchronously on the UI thread.
|
| + private static Context sDataDirectoryAppContext;
|
| +
|
| + // We also store the directory path suffix from setPrivateDataDirectorySuffix() for the same
|
| + // reason as above.
|
| private static String sDataDirectorySuffix;
|
|
|
| // Prevent instantiation.
|
| @@ -97,14 +101,13 @@ public abstract class PathUtils {
|
| */
|
| private static String[] setPrivateDataDirectorySuffixInternal() {
|
| String[] paths = new String[NUM_DIRECTORIES];
|
| - Context appContext = ContextUtils.getApplicationContext();
|
| - paths[DATA_DIRECTORY] = appContext.getDir(
|
| - sDataDirectorySuffix, Context.MODE_PRIVATE).getPath();
|
| - paths[THUMBNAIL_DIRECTORY] = appContext.getDir(
|
| + paths[DATA_DIRECTORY] = sDataDirectoryAppContext.getDir(sDataDirectorySuffix,
|
| + Context.MODE_PRIVATE).getPath();
|
| + paths[THUMBNAIL_DIRECTORY] = sDataDirectoryAppContext.getDir(
|
| THUMBNAIL_DIRECTORY_NAME, Context.MODE_PRIVATE).getPath();
|
| - paths[DATABASE_DIRECTORY] = appContext.getDatabasePath("foo").getParent();
|
| - if (appContext.getCacheDir() != null) {
|
| - paths[CACHE_DIRECTORY] = appContext.getCacheDir().getPath();
|
| + paths[DATABASE_DIRECTORY] = sDataDirectoryAppContext.getDatabasePath("foo").getParent();
|
| + if (sDataDirectoryAppContext.getCacheDir() != null) {
|
| + paths[CACHE_DIRECTORY] = sDataDirectoryAppContext.getCacheDir().getPath();
|
| }
|
| return paths;
|
| }
|
| @@ -121,12 +124,12 @@ public abstract class PathUtils {
|
| * @param suffix The private data directory suffix.
|
| * @see Context#getDir(String, int)
|
| */
|
| - public static void setPrivateDataDirectorySuffix(String suffix) {
|
| + public static void setPrivateDataDirectorySuffix(String suffix, Context context) {
|
| // This method should only be called once, but many tests end up calling it multiple times,
|
| // so adding a guard here.
|
| if (!sInitializationStarted.getAndSet(true)) {
|
| - assert ContextUtils.getApplicationContext() != null;
|
| sDataDirectorySuffix = suffix;
|
| + sDataDirectoryAppContext = context.getApplicationContext();
|
| sDirPathFetchTask = new AsyncTask<Void, Void, String[]>() {
|
| @Override
|
| protected String[] doInBackground(Void... unused) {
|
|
|