OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.base; | 5 package org.chromium.base; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.pm.ApplicationInfo; | 8 import android.content.pm.ApplicationInfo; |
9 import android.os.AsyncTask; | 9 import android.os.AsyncTask; |
10 import android.os.Environment; | 10 import android.os.Environment; |
(...skipping 23 matching lines...) Expand all Loading... |
34 */ | 34 */ |
35 public static void setPrivateDataDirectorySuffix(String suffix, Context cont
ext) { | 35 public static void setPrivateDataDirectorySuffix(String suffix, Context cont
ext) { |
36 final Context appContext = context.getApplicationContext(); | 36 final Context appContext = context.getApplicationContext(); |
37 sDirPathFetchTask = new AsyncTask<String, Void, String[]>() { | 37 sDirPathFetchTask = new AsyncTask<String, Void, String[]>() { |
38 @Override | 38 @Override |
39 protected String[] doInBackground(String... dataDirectorySuffix) { | 39 protected String[] doInBackground(String... dataDirectorySuffix) { |
40 String[] paths = new String[NUM_DIRECTORIES]; | 40 String[] paths = new String[NUM_DIRECTORIES]; |
41 paths[DATA_DIRECTORY] = | 41 paths[DATA_DIRECTORY] = |
42 appContext.getDir(dataDirectorySuffix[0], Context.MODE_P
RIVATE).getPath(); | 42 appContext.getDir(dataDirectorySuffix[0], Context.MODE_P
RIVATE).getPath(); |
43 paths[DATABASE_DIRECTORY] = appContext.getDatabasePath("foo").ge
tParent(); | 43 paths[DATABASE_DIRECTORY] = appContext.getDatabasePath("foo").ge
tParent(); |
44 paths[CACHE_DIRECTORY] = appContext.getCacheDir().getPath(); | 44 // TODO(wnwen): Find a way to avoid calling this function in ren
derer process. |
| 45 if (appContext.getCacheDir() != null) { |
| 46 paths[CACHE_DIRECTORY] = appContext.getCacheDir().getPath(); |
| 47 } |
45 return paths; | 48 return paths; |
46 } | 49 } |
47 }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, suffix); | 50 }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, suffix); |
48 } | 51 } |
49 | 52 |
50 /** | 53 /** |
51 * @param index The index of the cached directory path. | 54 * @param index The index of the cached directory path. |
52 * @return The directory path requested, or null if not available. | 55 * @return The directory path requested, or null if not available. |
53 */ | 56 */ |
54 private static String getDirectoryPath(int index) { | 57 private static String getDirectoryPath(int index) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 118 |
116 /** | 119 /** |
117 * @return the external storage directory. | 120 * @return the external storage directory. |
118 */ | 121 */ |
119 @SuppressWarnings("unused") | 122 @SuppressWarnings("unused") |
120 @CalledByNative | 123 @CalledByNative |
121 public static String getExternalStorageDirectory() { | 124 public static String getExternalStorageDirectory() { |
122 return Environment.getExternalStorageDirectory().getAbsolutePath(); | 125 return Environment.getExternalStorageDirectory().getAbsolutePath(); |
123 } | 126 } |
124 } | 127 } |
OLD | NEW |