| 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; |
| 11 | 11 |
| 12 import java.io.File; |
| 12 import java.util.concurrent.ExecutionException; | 13 import java.util.concurrent.ExecutionException; |
| 13 | 14 |
| 14 /** | 15 /** |
| 15 * This class provides the path related methods for the native library. | 16 * This class provides the path related methods for the native library. |
| 16 */ | 17 */ |
| 17 public abstract class PathUtils { | 18 public abstract class PathUtils { |
| 19 private static final String THUMBNAIL_DIRECTORY = "textures"; |
| 18 | 20 |
| 19 private static final int DATA_DIRECTORY = 0; | 21 private static final int DATA_DIRECTORY = 0; |
| 20 private static final int DATABASE_DIRECTORY = 1; | 22 private static final int DATABASE_DIRECTORY = 1; |
| 21 private static final int CACHE_DIRECTORY = 2; | 23 private static final int CACHE_DIRECTORY = 2; |
| 22 private static final int NUM_DIRECTORIES = 3; | 24 private static final int NUM_DIRECTORIES = 3; |
| 23 private static AsyncTask<String, Void, String[]> sDirPathFetchTask; | 25 private static AsyncTask<String, Void, String[]> sDirPathFetchTask; |
| 24 | 26 |
| 27 private static File sThumbnailDirectory; |
| 28 |
| 25 // Prevent instantiation. | 29 // Prevent instantiation. |
| 26 private PathUtils() {} | 30 private PathUtils() {} |
| 27 | 31 |
| 28 /** | 32 /** |
| 29 * Starts an asynchronous task to fetch the path of the directory where priv
ate data is to be | 33 * Starts an asynchronous task to fetch the path of the directory where priv
ate data is to be |
| 30 * stored by the application. | 34 * stored by the application. |
| 31 * | 35 * |
| 32 * @param suffix The private data directory suffix. | 36 * @param suffix The private data directory suffix. |
| 33 * @see Context#getDir(String, int) | 37 * @see Context#getDir(String, int) |
| 34 */ | 38 */ |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 /** | 88 /** |
| 85 * @return the cache directory. | 89 * @return the cache directory. |
| 86 */ | 90 */ |
| 87 @SuppressWarnings("unused") | 91 @SuppressWarnings("unused") |
| 88 @CalledByNative | 92 @CalledByNative |
| 89 public static String getCacheDirectory(Context appContext) { | 93 public static String getCacheDirectory(Context appContext) { |
| 90 assert sDirPathFetchTask != null : "setDataDirectorySuffix must be calle
d first."; | 94 assert sDirPathFetchTask != null : "setDataDirectorySuffix must be calle
d first."; |
| 91 return getDirectoryPath(CACHE_DIRECTORY); | 95 return getDirectoryPath(CACHE_DIRECTORY); |
| 92 } | 96 } |
| 93 | 97 |
| 98 public static File getThumbnailCacheDirectory(Context appContext) { |
| 99 if (sThumbnailDirectory == null) { |
| 100 sThumbnailDirectory = appContext.getDir(THUMBNAIL_DIRECTORY, Context
.MODE_PRIVATE); |
| 101 } |
| 102 return sThumbnailDirectory; |
| 103 } |
| 104 |
| 105 @CalledByNative |
| 106 public static String getThumbnailCacheDirectoryPath(Context appContext) { |
| 107 return getThumbnailCacheDirectory(appContext).getAbsolutePath(); |
| 108 } |
| 109 |
| 94 /** | 110 /** |
| 95 * @return the public downloads directory. | 111 * @return the public downloads directory. |
| 96 */ | 112 */ |
| 97 @SuppressWarnings("unused") | 113 @SuppressWarnings("unused") |
| 98 @CalledByNative | 114 @CalledByNative |
| 99 private static String getDownloadsDirectory(Context appContext) { | 115 private static String getDownloadsDirectory(Context appContext) { |
| 100 return Environment.getExternalStoragePublicDirectory( | 116 return Environment.getExternalStoragePublicDirectory( |
| 101 Environment.DIRECTORY_DOWNLOADS).getPath(); | 117 Environment.DIRECTORY_DOWNLOADS).getPath(); |
| 102 } | 118 } |
| 103 | 119 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 118 | 134 |
| 119 /** | 135 /** |
| 120 * @return the external storage directory. | 136 * @return the external storage directory. |
| 121 */ | 137 */ |
| 122 @SuppressWarnings("unused") | 138 @SuppressWarnings("unused") |
| 123 @CalledByNative | 139 @CalledByNative |
| 124 public static String getExternalStorageDirectory() { | 140 public static String getExternalStorageDirectory() { |
| 125 return Environment.getExternalStorageDirectory().getAbsolutePath(); | 141 return Environment.getExternalStorageDirectory().getAbsolutePath(); |
| 126 } | 142 } |
| 127 } | 143 } |
| OLD | NEW |