[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] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 10 | #include "base/files/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(); |
wnwen | 9c8dc6d | 2016-09-08 13:32:12 | [diff] [blame] | 19 | ScopedJavaLocalRef<jstring> path = Java_PathUtils_getDataDirectory(env); |
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 20 | FilePath data_path(ConvertJavaStringToUTF8(path)); |
21 | *result = data_path; | ||||
22 | return true; | ||||
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 23 | } |
24 | |||||
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 25 | bool GetCacheDirectory(FilePath* result) { |
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 26 | JNIEnv* env = AttachCurrentThread(); |
wnwen | 9c8dc6d | 2016-09-08 13:32:12 | [diff] [blame] | 27 | ScopedJavaLocalRef<jstring> path = Java_PathUtils_getCacheDirectory(env); |
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 28 | FilePath cache_path(ConvertJavaStringToUTF8(path)); |
29 | *result = cache_path; | ||||
30 | return true; | ||||
[email protected] | 6fa1e7ef | 2012-03-14 11:24:04 | [diff] [blame] | 31 | } |
32 | |||||
wnwen | a56aa7b | 2015-07-09 14:30:32 | [diff] [blame] | 33 | bool GetThumbnailCacheDirectory(FilePath* result) { |
34 | JNIEnv* env = AttachCurrentThread(); | ||||
35 | ScopedJavaLocalRef<jstring> path = | ||||
wnwen | 9c8dc6d | 2016-09-08 13:32:12 | [diff] [blame] | 36 | Java_PathUtils_getThumbnailCacheDirectory(env); |
wnwen | a56aa7b | 2015-07-09 14:30:32 | [diff] [blame] | 37 | FilePath thumbnail_cache_path(ConvertJavaStringToUTF8(path)); |
38 | *result = thumbnail_cache_path; | ||||
39 | return true; | ||||
40 | } | ||||
41 | |||||
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 42 | bool GetDownloadsDirectory(FilePath* result) { |
[email protected] | 6fa1e7ef | 2012-03-14 11:24:04 | [diff] [blame] | 43 | JNIEnv* env = AttachCurrentThread(); |
wnwen | 9c8dc6d | 2016-09-08 13:32:12 | [diff] [blame] | 44 | ScopedJavaLocalRef<jstring> path = Java_PathUtils_getDownloadsDirectory(env); |
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 45 | FilePath downloads_path(ConvertJavaStringToUTF8(path)); |
46 | *result = downloads_path; | ||||
47 | return true; | ||||
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 48 | } |
49 | |||||
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 50 | bool GetNativeLibraryDirectory(FilePath* result) { |
[email protected] | 672898b | 2012-07-02 20:04:04 | [diff] [blame] | 51 | JNIEnv* env = AttachCurrentThread(); |
52 | ScopedJavaLocalRef<jstring> path = | ||||
wnwen | 9c8dc6d | 2016-09-08 13:32:12 | [diff] [blame] | 53 | Java_PathUtils_getNativeLibraryDirectory(env); |
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 54 | FilePath library_path(ConvertJavaStringToUTF8(path)); |
55 | *result = library_path; | ||||
56 | return true; | ||||
[email protected] | 672898b | 2012-07-02 20:04:04 | [diff] [blame] | 57 | } |
58 | |||||
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 59 | bool GetExternalStorageDirectory(FilePath* result) { |
[email protected] | fa67f76c | 2012-08-24 10:08:27 | [diff] [blame] | 60 | JNIEnv* env = AttachCurrentThread(); |
61 | ScopedJavaLocalRef<jstring> path = | ||||
62 | Java_PathUtils_getExternalStorageDirectory(env); | ||||
[email protected] | 18011cb7 | 2012-10-02 22:03:33 | [diff] [blame] | 63 | FilePath storage_path(ConvertJavaStringToUTF8(path)); |
64 | *result = storage_path; | ||||
65 | return true; | ||||
[email protected] | fa67f76c | 2012-08-24 10:08:27 | [diff] [blame] | 66 | } |
67 | |||||
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 68 | } // namespace android |
69 | } // namespace base |