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 = 21 Java_PathUtils_getDataDirectory(env, GetApplicationContext()); 22 FilePath data_path(ConvertJavaStringToUTF8(path)); 23 *result = data_path; 24 return true; 25 } 26 GetDatabaseDirectory(FilePath * result)27bool GetDatabaseDirectory(FilePath* result) { 28 JNIEnv* env = AttachCurrentThread(); 29 ScopedJavaLocalRef<jstring> path = 30 Java_PathUtils_getDatabaseDirectory(env, GetApplicationContext()); 31 FilePath data_path(ConvertJavaStringToUTF8(path)); 32 *result = data_path; 33 return true; 34 } 35 GetCacheDirectory(FilePath * result)36bool GetCacheDirectory(FilePath* result) { 37 JNIEnv* env = AttachCurrentThread(); 38 ScopedJavaLocalRef<jstring> path = 39 Java_PathUtils_getCacheDirectory(env, GetApplicationContext()); 40 FilePath cache_path(ConvertJavaStringToUTF8(path)); 41 *result = cache_path; 42 return true; 43 } 44 GetThumbnailCacheDirectory(FilePath * result)45bool GetThumbnailCacheDirectory(FilePath* result) { 46 JNIEnv* env = AttachCurrentThread(); 47 ScopedJavaLocalRef<jstring> path = 48 Java_PathUtils_getThumbnailCacheDirectory(env, GetApplicationContext()); 49 FilePath thumbnail_cache_path(ConvertJavaStringToUTF8(path)); 50 *result = thumbnail_cache_path; 51 return true; 52 } 53 GetDownloadsDirectory(FilePath * result)54bool GetDownloadsDirectory(FilePath* result) { 55 JNIEnv* env = AttachCurrentThread(); 56 ScopedJavaLocalRef<jstring> path = 57 Java_PathUtils_getDownloadsDirectory(env, GetApplicationContext()); 58 FilePath downloads_path(ConvertJavaStringToUTF8(path)); 59 *result = downloads_path; 60 return true; 61 } 62 GetNativeLibraryDirectory(FilePath * result)63bool GetNativeLibraryDirectory(FilePath* result) { 64 JNIEnv* env = AttachCurrentThread(); 65 ScopedJavaLocalRef<jstring> path = 66 Java_PathUtils_getNativeLibraryDirectory(env, GetApplicationContext()); 67 FilePath library_path(ConvertJavaStringToUTF8(path)); 68 *result = library_path; 69 return true; 70 } 71 GetExternalStorageDirectory(FilePath * result)72bool GetExternalStorageDirectory(FilePath* result) { 73 JNIEnv* env = AttachCurrentThread(); 74 ScopedJavaLocalRef<jstring> path = 75 Java_PathUtils_getExternalStorageDirectory(env); 76 FilePath storage_path(ConvertJavaStringToUTF8(path)); 77 *result = storage_path; 78 return true; 79 } 80 RegisterPathUtils(JNIEnv * env)81bool RegisterPathUtils(JNIEnv* env) { 82 return RegisterNativesImpl(env); 83 } 84 85 } // namespace android 86 } // namespace base 87