blob: 3d86177bfa072b16dfcb62489b51c4a0a0787100 [file] [log] [blame]
[email protected]6fa1e7ef2012-03-14 11:24:041// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]61c86c62011-08-02 16:11:162// 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]61c86c62011-08-02 16:11:167#include "base/android/jni_android.h"
8#include "base/android/jni_string.h"
[email protected]f98d7b92011-09-09 10:17:359#include "base/android/scoped_java_ref.h"
[email protected]18011cb72012-10-02 22:03:3310#include "base/file_path.h"
[email protected]61c86c62011-08-02 16:11:1611
[email protected]e46f66152012-07-19 20:02:5512#include "jni/PathUtils_jni.h"
[email protected]61c86c62011-08-02 16:11:1613
14namespace base {
15namespace android {
16
[email protected]18011cb72012-10-02 22:03:3317bool GetDataDirectory(FilePath* result) {
[email protected]61c86c62011-08-02 16:11:1618 JNIEnv* env = AttachCurrentThread();
[email protected]6fa1e7ef2012-03-14 11:24:0419 ScopedJavaLocalRef<jstring> path =
20 Java_PathUtils_getDataDirectory(env, GetApplicationContext());
[email protected]18011cb72012-10-02 22:03:3321 FilePath data_path(ConvertJavaStringToUTF8(path));
22 *result = data_path;
23 return true;
[email protected]61c86c62011-08-02 16:11:1624}
25
[email protected]18011cb72012-10-02 22:03:3326bool GetCacheDirectory(FilePath* result) {
[email protected]61c86c62011-08-02 16:11:1627 JNIEnv* env = AttachCurrentThread();
[email protected]6fa1e7ef2012-03-14 11:24:0428 ScopedJavaLocalRef<jstring> path =
29 Java_PathUtils_getCacheDirectory(env, GetApplicationContext());
[email protected]18011cb72012-10-02 22:03:3330 FilePath cache_path(ConvertJavaStringToUTF8(path));
31 *result = cache_path;
32 return true;
[email protected]6fa1e7ef2012-03-14 11:24:0433}
34
[email protected]18011cb72012-10-02 22:03:3335bool GetDownloadsDirectory(FilePath* result) {
[email protected]6fa1e7ef2012-03-14 11:24:0436 JNIEnv* env = AttachCurrentThread();
37 ScopedJavaLocalRef<jstring> path =
38 Java_PathUtils_getDownloadsDirectory(env, GetApplicationContext());
[email protected]18011cb72012-10-02 22:03:3339 FilePath downloads_path(ConvertJavaStringToUTF8(path));
40 *result = downloads_path;
41 return true;
[email protected]61c86c62011-08-02 16:11:1642}
43
[email protected]18011cb72012-10-02 22:03:3344bool GetNativeLibraryDirectory(FilePath* result) {
[email protected]672898b2012-07-02 20:04:0445 JNIEnv* env = AttachCurrentThread();
46 ScopedJavaLocalRef<jstring> path =
47 Java_PathUtils_getNativeLibraryDirectory(env, GetApplicationContext());
[email protected]18011cb72012-10-02 22:03:3348 FilePath library_path(ConvertJavaStringToUTF8(path));
49 *result = library_path;
50 return true;
[email protected]672898b2012-07-02 20:04:0451}
52
[email protected]18011cb72012-10-02 22:03:3353bool GetExternalStorageDirectory(FilePath* result) {
[email protected]fa67f76c2012-08-24 10:08:2754 JNIEnv* env = AttachCurrentThread();
55 ScopedJavaLocalRef<jstring> path =
56 Java_PathUtils_getExternalStorageDirectory(env);
[email protected]18011cb72012-10-02 22:03:3357 FilePath storage_path(ConvertJavaStringToUTF8(path));
58 *result = storage_path;
59 return true;
[email protected]fa67f76c2012-08-24 10:08:2760}
61
[email protected]61c86c62011-08-02 16:11:1662bool RegisterPathUtils(JNIEnv* env) {
63 return RegisterNativesImpl(env);
64}
65
66} // namespace android
67} // namespace base