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 1546e001b94f7bb08232759f7bbcddbbcf5a0a9c..00977d56d576ac94335c6ab0578a86c75b1c2833 100644 |
--- a/base/android/java/src/org/chromium/base/PathUtils.java |
+++ b/base/android/java/src/org/chromium/base/PathUtils.java |
@@ -34,13 +34,9 @@ public abstract class PathUtils { |
private static final AtomicBoolean sInitializationStarted = new AtomicBoolean(); |
private static AsyncTask<Void, Void, String[]> sDirPathFetchTask; |
- // 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. |
+ // 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. |
private static String sDataDirectorySuffix; |
// Prevent instantiation. |
@@ -101,13 +97,14 @@ public abstract class PathUtils { |
*/ |
private static String[] setPrivateDataDirectorySuffixInternal() { |
String[] paths = new String[NUM_DIRECTORIES]; |
- paths[DATA_DIRECTORY] = sDataDirectoryAppContext.getDir(sDataDirectorySuffix, |
- Context.MODE_PRIVATE).getPath(); |
- paths[THUMBNAIL_DIRECTORY] = sDataDirectoryAppContext.getDir( |
+ Context appContext = ContextUtils.getApplicationContext(); |
+ paths[DATA_DIRECTORY] = appContext.getDir( |
+ sDataDirectorySuffix, Context.MODE_PRIVATE).getPath(); |
+ paths[THUMBNAIL_DIRECTORY] = appContext.getDir( |
THUMBNAIL_DIRECTORY_NAME, Context.MODE_PRIVATE).getPath(); |
- paths[DATABASE_DIRECTORY] = sDataDirectoryAppContext.getDatabasePath("foo").getParent(); |
- if (sDataDirectoryAppContext.getCacheDir() != null) { |
- paths[CACHE_DIRECTORY] = sDataDirectoryAppContext.getCacheDir().getPath(); |
+ paths[DATABASE_DIRECTORY] = appContext.getDatabasePath("foo").getParent(); |
+ if (appContext.getCacheDir() != null) { |
+ paths[CACHE_DIRECTORY] = appContext.getCacheDir().getPath(); |
} |
return paths; |
} |
@@ -124,12 +121,12 @@ public abstract class PathUtils { |
* @param suffix The private data directory suffix. |
* @see Context#getDir(String, int) |
*/ |
- public static void setPrivateDataDirectorySuffix(String suffix, Context context) { |
+ public static void setPrivateDataDirectorySuffix(String suffix) { |
// 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) { |