peter@chromium.org | f63cdf1 | 2012-03-14 20:24:04 +0900 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
michaelbai@google.com | 686190b | 2011-08-03 01:11:16 +0900 | [diff] [blame] | 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 | |
michaelbai@google.com | 686190b | 2011-08-03 01:11:16 +0900 | [diff] [blame] | 7 | #include "base/android/jni_android.h" |
| 8 | #include "base/android/jni_string.h" |
joth@chromium.org | ed27f3a | 2011-09-09 19:17:35 +0900 | [diff] [blame] | 9 | #include "base/android/scoped_java_ref.h" |
aurimas@chromium.org | e91c48c | 2012-10-03 07:03:33 +0900 | [diff] [blame^] | 10 | #include "base/file_path.h" |
michaelbai@google.com | 686190b | 2011-08-03 01:11:16 +0900 | [diff] [blame] | 11 | |
bulach@chromium.org | 4c248ed | 2012-07-20 05:02:55 +0900 | [diff] [blame] | 12 | #include "jni/PathUtils_jni.h" |
michaelbai@google.com | 686190b | 2011-08-03 01:11:16 +0900 | [diff] [blame] | 13 | |
| 14 | namespace base { |
| 15 | namespace android { |
| 16 | |
aurimas@chromium.org | e91c48c | 2012-10-03 07:03:33 +0900 | [diff] [blame^] | 17 | bool GetDataDirectory(FilePath* result) { |
michaelbai@google.com | 686190b | 2011-08-03 01:11:16 +0900 | [diff] [blame] | 18 | JNIEnv* env = AttachCurrentThread(); |
peter@chromium.org | f63cdf1 | 2012-03-14 20:24:04 +0900 | [diff] [blame] | 19 | ScopedJavaLocalRef<jstring> path = |
| 20 | Java_PathUtils_getDataDirectory(env, GetApplicationContext()); |
aurimas@chromium.org | e91c48c | 2012-10-03 07:03:33 +0900 | [diff] [blame^] | 21 | FilePath data_path(ConvertJavaStringToUTF8(path)); |
| 22 | *result = data_path; |
| 23 | return true; |
michaelbai@google.com | 686190b | 2011-08-03 01:11:16 +0900 | [diff] [blame] | 24 | } |
| 25 | |
aurimas@chromium.org | e91c48c | 2012-10-03 07:03:33 +0900 | [diff] [blame^] | 26 | bool GetCacheDirectory(FilePath* result) { |
michaelbai@google.com | 686190b | 2011-08-03 01:11:16 +0900 | [diff] [blame] | 27 | JNIEnv* env = AttachCurrentThread(); |
peter@chromium.org | f63cdf1 | 2012-03-14 20:24:04 +0900 | [diff] [blame] | 28 | ScopedJavaLocalRef<jstring> path = |
| 29 | Java_PathUtils_getCacheDirectory(env, GetApplicationContext()); |
aurimas@chromium.org | e91c48c | 2012-10-03 07:03:33 +0900 | [diff] [blame^] | 30 | FilePath cache_path(ConvertJavaStringToUTF8(path)); |
| 31 | *result = cache_path; |
| 32 | return true; |
peter@chromium.org | f63cdf1 | 2012-03-14 20:24:04 +0900 | [diff] [blame] | 33 | } |
| 34 | |
aurimas@chromium.org | e91c48c | 2012-10-03 07:03:33 +0900 | [diff] [blame^] | 35 | bool GetDownloadsDirectory(FilePath* result) { |
peter@chromium.org | f63cdf1 | 2012-03-14 20:24:04 +0900 | [diff] [blame] | 36 | JNIEnv* env = AttachCurrentThread(); |
| 37 | ScopedJavaLocalRef<jstring> path = |
| 38 | Java_PathUtils_getDownloadsDirectory(env, GetApplicationContext()); |
aurimas@chromium.org | e91c48c | 2012-10-03 07:03:33 +0900 | [diff] [blame^] | 39 | FilePath downloads_path(ConvertJavaStringToUTF8(path)); |
| 40 | *result = downloads_path; |
| 41 | return true; |
michaelbai@google.com | 686190b | 2011-08-03 01:11:16 +0900 | [diff] [blame] | 42 | } |
| 43 | |
aurimas@chromium.org | e91c48c | 2012-10-03 07:03:33 +0900 | [diff] [blame^] | 44 | bool GetNativeLibraryDirectory(FilePath* result) { |
aurimas@chromium.org | 59cc7cf | 2012-07-03 05:04:04 +0900 | [diff] [blame] | 45 | JNIEnv* env = AttachCurrentThread(); |
| 46 | ScopedJavaLocalRef<jstring> path = |
| 47 | Java_PathUtils_getNativeLibraryDirectory(env, GetApplicationContext()); |
aurimas@chromium.org | e91c48c | 2012-10-03 07:03:33 +0900 | [diff] [blame^] | 48 | FilePath library_path(ConvertJavaStringToUTF8(path)); |
| 49 | *result = library_path; |
| 50 | return true; |
aurimas@chromium.org | 59cc7cf | 2012-07-03 05:04:04 +0900 | [diff] [blame] | 51 | } |
| 52 | |
aurimas@chromium.org | e91c48c | 2012-10-03 07:03:33 +0900 | [diff] [blame^] | 53 | bool GetExternalStorageDirectory(FilePath* result) { |
nileshagrawal@chromium.org | a4be12c | 2012-08-24 19:08:27 +0900 | [diff] [blame] | 54 | JNIEnv* env = AttachCurrentThread(); |
| 55 | ScopedJavaLocalRef<jstring> path = |
| 56 | Java_PathUtils_getExternalStorageDirectory(env); |
aurimas@chromium.org | e91c48c | 2012-10-03 07:03:33 +0900 | [diff] [blame^] | 57 | FilePath storage_path(ConvertJavaStringToUTF8(path)); |
| 58 | *result = storage_path; |
| 59 | return true; |
nileshagrawal@chromium.org | a4be12c | 2012-08-24 19:08:27 +0900 | [diff] [blame] | 60 | } |
| 61 | |
michaelbai@google.com | 686190b | 2011-08-03 01:11:16 +0900 | [diff] [blame] | 62 | bool RegisterPathUtils(JNIEnv* env) { |
| 63 | return RegisterNativesImpl(env); |
| 64 | } |
| 65 | |
| 66 | } // namespace android |
| 67 | } // namespace base |