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