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

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

Issue 2412623002: Reland "Move PathUtils to use ContextUtils." (Closed)
Patch Set: Created 4 years, 2 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
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) {

Powered by Google App Engine
This is Rietveld 408576698