| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "base/android/path_utils.h" | 5 #include "base/android/path_utils.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/android/scoped_java_ref.h" | 9 #include "base/android/scoped_java_ref.h" |
| 10 #include "base/file_path.h" |
| 10 | 11 |
| 11 #include "jni/PathUtils_jni.h" | 12 #include "jni/PathUtils_jni.h" |
| 12 | 13 |
| 13 namespace base { | 14 namespace base { |
| 14 namespace android { | 15 namespace android { |
| 15 | 16 |
| 16 std::string GetDataDirectory() { | 17 bool GetDataDirectory(FilePath* result) { |
| 17 JNIEnv* env = AttachCurrentThread(); | 18 JNIEnv* env = AttachCurrentThread(); |
| 18 ScopedJavaLocalRef<jstring> path = | 19 ScopedJavaLocalRef<jstring> path = |
| 19 Java_PathUtils_getDataDirectory(env, GetApplicationContext()); | 20 Java_PathUtils_getDataDirectory(env, GetApplicationContext()); |
| 20 return ConvertJavaStringToUTF8(path); | 21 FilePath data_path(ConvertJavaStringToUTF8(path)); |
| 22 *result = data_path; |
| 23 return true; |
| 21 } | 24 } |
| 22 | 25 |
| 23 std::string GetCacheDirectory() { | 26 bool GetCacheDirectory(FilePath* result) { |
| 24 JNIEnv* env = AttachCurrentThread(); | 27 JNIEnv* env = AttachCurrentThread(); |
| 25 ScopedJavaLocalRef<jstring> path = | 28 ScopedJavaLocalRef<jstring> path = |
| 26 Java_PathUtils_getCacheDirectory(env, GetApplicationContext()); | 29 Java_PathUtils_getCacheDirectory(env, GetApplicationContext()); |
| 27 return ConvertJavaStringToUTF8(path); | 30 FilePath cache_path(ConvertJavaStringToUTF8(path)); |
| 31 *result = cache_path; |
| 32 return true; |
| 28 } | 33 } |
| 29 | 34 |
| 30 std::string GetDownloadsDirectory() { | 35 bool GetDownloadsDirectory(FilePath* result) { |
| 31 JNIEnv* env = AttachCurrentThread(); | 36 JNIEnv* env = AttachCurrentThread(); |
| 32 ScopedJavaLocalRef<jstring> path = | 37 ScopedJavaLocalRef<jstring> path = |
| 33 Java_PathUtils_getDownloadsDirectory(env, GetApplicationContext()); | 38 Java_PathUtils_getDownloadsDirectory(env, GetApplicationContext()); |
| 34 return ConvertJavaStringToUTF8(path); | 39 FilePath downloads_path(ConvertJavaStringToUTF8(path)); |
| 40 *result = downloads_path; |
| 41 return true; |
| 35 } | 42 } |
| 36 | 43 |
| 37 std::string GetNativeLibraryDirectory() { | 44 bool GetNativeLibraryDirectory(FilePath* result) { |
| 38 JNIEnv* env = AttachCurrentThread(); | 45 JNIEnv* env = AttachCurrentThread(); |
| 39 ScopedJavaLocalRef<jstring> path = | 46 ScopedJavaLocalRef<jstring> path = |
| 40 Java_PathUtils_getNativeLibraryDirectory(env, GetApplicationContext()); | 47 Java_PathUtils_getNativeLibraryDirectory(env, GetApplicationContext()); |
| 41 return ConvertJavaStringToUTF8(path); | 48 FilePath library_path(ConvertJavaStringToUTF8(path)); |
| 49 *result = library_path; |
| 50 return true; |
| 42 } | 51 } |
| 43 | 52 |
| 44 std::string GetExternalStorageDirectory() { | 53 bool GetExternalStorageDirectory(FilePath* result) { |
| 45 JNIEnv* env = AttachCurrentThread(); | 54 JNIEnv* env = AttachCurrentThread(); |
| 46 ScopedJavaLocalRef<jstring> path = | 55 ScopedJavaLocalRef<jstring> path = |
| 47 Java_PathUtils_getExternalStorageDirectory(env); | 56 Java_PathUtils_getExternalStorageDirectory(env); |
| 48 return ConvertJavaStringToUTF8(path); | 57 FilePath storage_path(ConvertJavaStringToUTF8(path)); |
| 58 *result = storage_path; |
| 59 return true; |
| 49 } | 60 } |
| 50 | 61 |
| 51 bool RegisterPathUtils(JNIEnv* env) { | 62 bool RegisterPathUtils(JNIEnv* env) { |
| 52 return RegisterNativesImpl(env); | 63 return RegisterNativesImpl(env); |
| 53 } | 64 } |
| 54 | 65 |
| 55 } // namespace android | 66 } // namespace android |
| 56 } // namespace base | 67 } // namespace base |
| OLD | NEW |