OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Defines base::PathProviderAndroid which replaces base::PathProviderPosix for | 5 #include "base/base_paths.h" |
6 // Android in base/path_service.cc. | |
7 | 6 |
8 #include <unistd.h> | 7 #include <unistd.h> |
9 | 8 |
10 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
11 #include "base/android/path_utils.h" | 10 #include "base/android/path_utils.h" |
12 #include "base/base_paths.h" | |
13 #include "base/file_path.h" | 11 #include "base/file_path.h" |
14 #include "base/file_util.h" | 12 #include "base/file_util.h" |
15 #include "base/logging.h" | 13 #include "base/logging.h" |
16 #include "base/process_util.h" | 14 #include "base/process_util.h" |
17 | 15 |
18 namespace base { | 16 namespace base { |
19 | 17 |
20 bool PathProviderAndroid(int key, FilePath* result) { | 18 bool PathProviderAndroid(int key, FilePath* result) { |
21 switch (key) { | 19 switch (key) { |
22 case base::FILE_EXE: { | 20 case base::FILE_EXE: { |
23 char bin_dir[PATH_MAX + 1]; | 21 char bin_dir[PATH_MAX + 1]; |
24 int bin_dir_size = readlink(kProcSelfExe, bin_dir, PATH_MAX); | 22 int bin_dir_size = readlink(kProcSelfExe, bin_dir, PATH_MAX); |
25 if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) { | 23 if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) { |
26 NOTREACHED() << "Unable to resolve " << kProcSelfExe << "."; | 24 NOTREACHED() << "Unable to resolve " << kProcSelfExe << "."; |
27 return false; | 25 return false; |
28 } | 26 } |
29 bin_dir[bin_dir_size] = 0; | 27 bin_dir[bin_dir_size] = 0; |
30 *result = FilePath(bin_dir); | 28 *result = FilePath(bin_dir); |
31 return true; | 29 return true; |
32 } | 30 } |
33 case base::FILE_MODULE: | 31 case base::FILE_MODULE: { |
34 // dladdr didn't work in Android as only the file name was returned. | 32 // dladdr didn't work in Android as only the file name was returned. |
35 NOTIMPLEMENTED(); | 33 NOTIMPLEMENTED(); |
36 return false; | 34 return false; |
37 case base::DIR_MODULE: | 35 } |
| 36 case base::DIR_MODULE: { |
38 *result = FilePath(base::android::GetNativeLibraryDirectory()); | 37 *result = FilePath(base::android::GetNativeLibraryDirectory()); |
39 return true; | 38 return true; |
40 case base::DIR_SOURCE_ROOT: | 39 } |
| 40 case base::DIR_SOURCE_ROOT: { |
41 // This const is only used for tests. | 41 // This const is only used for tests. |
42 *result = FilePath(base::android::GetExternalStorageDirectory()); | 42 *result = FilePath(base::android::GetExternalStorageDirectory()); |
43 return true; | 43 return true; |
44 case base::DIR_USER_DESKTOP: | 44 } |
45 // Android doesn't support GetUserDesktop. | 45 case base::DIR_CACHE: { |
46 NOTIMPLEMENTED(); | |
47 return false; | |
48 case base::DIR_CACHE: | |
49 *result = FilePath(base::android::GetCacheDirectory()); | 46 *result = FilePath(base::android::GetCacheDirectory()); |
50 return true; | 47 return true; |
51 case base::DIR_ANDROID_APP_DATA: | 48 } |
| 49 case base::DIR_ANDROID_APP_DATA: { |
52 *result = FilePath(base::android::GetDataDirectory()); | 50 *result = FilePath(base::android::GetDataDirectory()); |
53 return true; | 51 return true; |
54 case base::DIR_HOME: | 52 } |
| 53 case base::DIR_HOME: { |
55 *result = file_util::GetHomeDir(); | 54 *result = file_util::GetHomeDir(); |
56 return true; | 55 return true; |
57 case base::DIR_ANDROID_EXTERNAL_STORAGE: | 56 } |
| 57 case base::DIR_ANDROID_EXTERNAL_STORAGE: { |
58 *result = FilePath(base::android::GetExternalStorageDirectory()); | 58 *result = FilePath(base::android::GetExternalStorageDirectory()); |
59 return true; | 59 return true; |
60 default: | 60 } |
| 61 default: { |
61 // Note: the path system expects this function to override the default | 62 // Note: the path system expects this function to override the default |
62 // behavior. So no need to log an error if we don't support a given | 63 // behavior. So no need to log an error if we don't support a given |
63 // path. The system will just use the default. | 64 // path. The system will just use the default. |
64 return false; | 65 return false; |
| 66 } |
65 } | 67 } |
66 } | 68 } |
67 | 69 |
68 } // namespace base | 70 } // namespace base |
OLD | NEW |