Luis Hector Chavez | 645501c | 2016-12-28 10:56:26 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/android/path_utils.h" |
| 6 | |
| 7 | #include "base/android/context_utils.h" |
| 8 | #include "base/android/jni_android.h" |
| 9 | #include "base/android/jni_string.h" |
| 10 | #include "base/android/scoped_java_ref.h" |
| 11 | #include "base/files/file_path.h" |
| 12 | |
| 13 | #include "jni/PathUtils_jni.h" |
| 14 | |
| 15 | namespace base { |
| 16 | namespace android { |
| 17 | |
| 18 | bool GetDataDirectory(FilePath* result) { |
| 19 | JNIEnv* env = AttachCurrentThread(); |
Jay Civelli | 8ac9103 | 2017-03-29 16:17:00 -0700 | [diff] [blame^] | 20 | ScopedJavaLocalRef<jstring> path = Java_PathUtils_getDataDirectory(env); |
Luis Hector Chavez | 645501c | 2016-12-28 10:56:26 -0800 | [diff] [blame] | 21 | FilePath data_path(ConvertJavaStringToUTF8(path)); |
| 22 | *result = data_path; |
| 23 | return true; |
| 24 | } |
| 25 | |
| 26 | bool GetDatabaseDirectory(FilePath* result) { |
| 27 | JNIEnv* env = AttachCurrentThread(); |
Jay Civelli | 8ac9103 | 2017-03-29 16:17:00 -0700 | [diff] [blame^] | 28 | ScopedJavaLocalRef<jstring> path = Java_PathUtils_getDatabaseDirectory(env); |
Luis Hector Chavez | 645501c | 2016-12-28 10:56:26 -0800 | [diff] [blame] | 29 | FilePath data_path(ConvertJavaStringToUTF8(path)); |
| 30 | *result = data_path; |
| 31 | return true; |
| 32 | } |
| 33 | |
| 34 | bool GetCacheDirectory(FilePath* result) { |
| 35 | JNIEnv* env = AttachCurrentThread(); |
Jay Civelli | 8ac9103 | 2017-03-29 16:17:00 -0700 | [diff] [blame^] | 36 | ScopedJavaLocalRef<jstring> path = Java_PathUtils_getCacheDirectory(env); |
Luis Hector Chavez | 645501c | 2016-12-28 10:56:26 -0800 | [diff] [blame] | 37 | FilePath cache_path(ConvertJavaStringToUTF8(path)); |
| 38 | *result = cache_path; |
| 39 | return true; |
| 40 | } |
| 41 | |
| 42 | bool GetThumbnailCacheDirectory(FilePath* result) { |
| 43 | JNIEnv* env = AttachCurrentThread(); |
| 44 | ScopedJavaLocalRef<jstring> path = |
Jay Civelli | 8ac9103 | 2017-03-29 16:17:00 -0700 | [diff] [blame^] | 45 | Java_PathUtils_getThumbnailCacheDirectory(env); |
Luis Hector Chavez | 645501c | 2016-12-28 10:56:26 -0800 | [diff] [blame] | 46 | FilePath thumbnail_cache_path(ConvertJavaStringToUTF8(path)); |
| 47 | *result = thumbnail_cache_path; |
| 48 | return true; |
| 49 | } |
| 50 | |
| 51 | bool GetDownloadsDirectory(FilePath* result) { |
| 52 | JNIEnv* env = AttachCurrentThread(); |
Jay Civelli | 8ac9103 | 2017-03-29 16:17:00 -0700 | [diff] [blame^] | 53 | ScopedJavaLocalRef<jstring> path = Java_PathUtils_getDownloadsDirectory(env); |
Luis Hector Chavez | 645501c | 2016-12-28 10:56:26 -0800 | [diff] [blame] | 54 | FilePath downloads_path(ConvertJavaStringToUTF8(path)); |
| 55 | *result = downloads_path; |
| 56 | return true; |
| 57 | } |
| 58 | |
| 59 | bool GetNativeLibraryDirectory(FilePath* result) { |
| 60 | JNIEnv* env = AttachCurrentThread(); |
| 61 | ScopedJavaLocalRef<jstring> path = |
Jay Civelli | 8ac9103 | 2017-03-29 16:17:00 -0700 | [diff] [blame^] | 62 | Java_PathUtils_getNativeLibraryDirectory(env); |
Luis Hector Chavez | 645501c | 2016-12-28 10:56:26 -0800 | [diff] [blame] | 63 | FilePath library_path(ConvertJavaStringToUTF8(path)); |
| 64 | *result = library_path; |
| 65 | return true; |
| 66 | } |
| 67 | |
| 68 | bool GetExternalStorageDirectory(FilePath* result) { |
| 69 | JNIEnv* env = AttachCurrentThread(); |
| 70 | ScopedJavaLocalRef<jstring> path = |
| 71 | Java_PathUtils_getExternalStorageDirectory(env); |
| 72 | FilePath storage_path(ConvertJavaStringToUTF8(path)); |
| 73 | *result = storage_path; |
| 74 | return true; |
| 75 | } |
| 76 | |
Luis Hector Chavez | 645501c | 2016-12-28 10:56:26 -0800 | [diff] [blame] | 77 | } // namespace android |
| 78 | } // namespace base |