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 GetDataDirectory(FilePath * result)18bool GetDataDirectory(FilePath* result) { 19 JNIEnv* env = AttachCurrentThread(); 20 ScopedJavaLocalRef<jstring> path = Java_PathUtils_getDataDirectory(env); 21 FilePath data_path(ConvertJavaStringToUTF8(path)); 22 *result = data_path; 23 return true; 24 } 25 GetDatabaseDirectory(FilePath * result)26bool GetDatabaseDirectory(FilePath* result) { 27 JNIEnv* env = AttachCurrentThread(); 28 ScopedJavaLocalRef<jstring> path = Java_PathUtils_getDatabaseDirectory(env); 29 FilePath data_path(ConvertJavaStringToUTF8(path)); 30 *result = data_path; 31 return true; 32 } 33 GetCacheDirectory(FilePath * result)34bool GetCacheDirectory(FilePath* result) { 35 JNIEnv* env = AttachCurrentThread(); 36 ScopedJavaLocalRef<jstring> path = Java_PathUtils_getCacheDirectory(env); 37 FilePath cache_path(ConvertJavaStringToUTF8(path)); 38 *result = cache_path; 39 return true; 40 } 41 GetThumbnailCacheDirectory(FilePath * result)42bool GetThumbnailCacheDirectory(FilePath* result) { 43 JNIEnv* env = AttachCurrentThread(); 44 ScopedJavaLocalRef<jstring> path = 45 Java_PathUtils_getThumbnailCacheDirectory(env); 46 FilePath thumbnail_cache_path(ConvertJavaStringToUTF8(path)); 47 *result = thumbnail_cache_path; 48 return true; 49 } 50 GetDownloadsDirectory(FilePath * result)51bool GetDownloadsDirectory(FilePath* result) { 52 JNIEnv* env = AttachCurrentThread(); 53 ScopedJavaLocalRef<jstring> path = Java_PathUtils_getDownloadsDirectory(env); 54 FilePath downloads_path(ConvertJavaStringToUTF8(path)); 55 *result = downloads_path; 56 return true; 57 } 58 GetNativeLibraryDirectory(FilePath * result)59bool GetNativeLibraryDirectory(FilePath* result) { 60 JNIEnv* env = AttachCurrentThread(); 61 ScopedJavaLocalRef<jstring> path = 62 Java_PathUtils_getNativeLibraryDirectory(env); 63 FilePath library_path(ConvertJavaStringToUTF8(path)); 64 *result = library_path; 65 return true; 66 } 67 GetExternalStorageDirectory(FilePath * result)68bool 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 77 } // namespace android 78 } // namespace base 79