Fix emulator build error
[platform/framework/web/chromium-efl.git] / base / android / path_utils.cc
1 // Copyright 2012 The Chromium Authors
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
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h"
9 #include "base/android/jni_string.h"
10 #include "base/android/scoped_java_ref.h"
11 #include "base/files/file_path.h"
12
13 #include "base/base_jni/PathUtils_jni.h"
14
15 namespace base {
16 namespace android {
17
18 bool GetDataDirectory(FilePath* result) {
19   JNIEnv* env = AttachCurrentThread();
20   ScopedJavaLocalRef<jstring> path = Java_PathUtils_getDataDirectory(env);
21   FilePath data_path(ConvertJavaStringToUTF8(path));
22   *result = data_path;
23   return true;
24 }
25
26 bool GetCacheDirectory(FilePath* result) {
27   JNIEnv* env = AttachCurrentThread();
28   ScopedJavaLocalRef<jstring> path = Java_PathUtils_getCacheDirectory(env);
29   FilePath cache_path(ConvertJavaStringToUTF8(path));
30   *result = cache_path;
31   return true;
32 }
33
34 bool GetThumbnailCacheDirectory(FilePath* result) {
35   JNIEnv* env = AttachCurrentThread();
36   ScopedJavaLocalRef<jstring> path =
37       Java_PathUtils_getThumbnailCacheDirectory(env);
38   FilePath thumbnail_cache_path(ConvertJavaStringToUTF8(path));
39   *result = thumbnail_cache_path;
40   return true;
41 }
42
43 bool GetDownloadsDirectory(FilePath* result) {
44   JNIEnv* env = AttachCurrentThread();
45   ScopedJavaLocalRef<jstring> path = Java_PathUtils_getDownloadsDirectory(env);
46   FilePath downloads_path(ConvertJavaStringToUTF8(path));
47   *result = downloads_path;
48   return true;
49 }
50
51 std::vector<FilePath> GetAllPrivateDownloadsDirectories() {
52   std::vector<std::string> dirs;
53   JNIEnv* env = AttachCurrentThread();
54   auto jarray = Java_PathUtils_getAllPrivateDownloadsDirectories(env);
55   base::android::AppendJavaStringArrayToStringVector(env, jarray, &dirs);
56
57   std::vector<base::FilePath> file_paths;
58   for (const auto& dir : dirs)
59     file_paths.emplace_back(dir);
60   return file_paths;
61 }
62
63 std::vector<FilePath> GetSecondaryStorageDownloadDirectories() {
64   std::vector<std::string> dirs;
65   JNIEnv* env = AttachCurrentThread();
66   auto jarray = Java_PathUtils_getExternalDownloadVolumesNames(env);
67   base::android::AppendJavaStringArrayToStringVector(env, jarray, &dirs);
68
69   std::vector<base::FilePath> file_paths;
70   for (const auto& dir : dirs)
71     file_paths.emplace_back(dir);
72   return file_paths;
73 }
74
75 bool GetNativeLibraryDirectory(FilePath* result) {
76   JNIEnv* env = AttachCurrentThread();
77   ScopedJavaLocalRef<jstring> path =
78       Java_PathUtils_getNativeLibraryDirectory(env);
79   FilePath library_path(ConvertJavaStringToUTF8(path));
80   *result = library_path;
81   return true;
82 }
83
84 bool GetExternalStorageDirectory(FilePath* result) {
85   JNIEnv* env = AttachCurrentThread();
86   ScopedJavaLocalRef<jstring> path =
87       Java_PathUtils_getExternalStorageDirectory(env);
88   FilePath storage_path(ConvertJavaStringToUTF8(path));
89   *result = storage_path;
90   return true;
91 }
92
93 }  // namespace android
94 }  // namespace base