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 #include "base/base_paths.h" | 5 #include "base/base_paths.h" |
6 | 6 |
7 #include <unistd.h> | 7 #include <unistd.h> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/path_utils.h" | 10 #include "base/android/path_utils.h" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/file_util.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 const char kSelfExe[] = "/proc/self/exe"; | 17 const char kSelfExe[] = "/proc/self/exe"; |
17 | 18 |
18 } // namespace | 19 } // namespace |
19 | 20 |
20 namespace base { | 21 namespace base { |
21 | 22 |
22 bool PathProviderAndroid(int key, FilePath* result) { | 23 bool PathProviderAndroid(int key, FilePath* result) { |
23 switch (key) { | 24 switch (key) { |
24 case base::FILE_EXE: { | 25 case base::FILE_EXE: { |
25 char bin_dir[PATH_MAX + 1]; | 26 char bin_dir[PATH_MAX + 1]; |
26 int bin_dir_size = readlink(kSelfExe, bin_dir, PATH_MAX); | 27 int bin_dir_size = readlink(kSelfExe, bin_dir, PATH_MAX); |
27 if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) { | 28 if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) { |
28 NOTREACHED() << "Unable to resolve " << kSelfExe << "."; | 29 NOTREACHED() << "Unable to resolve " << kSelfExe << "."; |
29 return false; | 30 return false; |
30 } | 31 } |
31 bin_dir[bin_dir_size] = 0; | 32 bin_dir[bin_dir_size] = 0; |
32 *result = FilePath(bin_dir); | 33 *result = FilePath(bin_dir); |
33 return true; | 34 return true; |
34 } | 35 } |
35 case base::FILE_MODULE: | 36 case base::FILE_MODULE: { |
36 // dladdr didn't work in Android as only the file name was returned. | 37 // dladdr didn't work in Android as only the file name was returned. |
37 NOTIMPLEMENTED(); | 38 NOTIMPLEMENTED(); |
38 return false; | 39 return false; |
| 40 } |
39 case base::DIR_MODULE: { | 41 case base::DIR_MODULE: { |
40 *result = FilePath(base::android::GetNativeLibraryDirectory()); | 42 *result = FilePath(base::android::GetNativeLibraryDirectory()); |
41 return true; | 43 return true; |
42 } | 44 } |
43 case base::DIR_SOURCE_ROOT: | 45 case base::DIR_SOURCE_ROOT: { |
44 // This const is only used for tests. Files in this directory are pushed | 46 // This const is only used for tests. Files in this directory are pushed |
45 // to the device via test script. | 47 // to the device via test script. |
46 *result = FilePath(FILE_PATH_LITERAL("/data/local/tmp/")); | 48 *result = FilePath(FILE_PATH_LITERAL("/data/local/tmp/")); |
47 return true; | 49 return true; |
48 case base::DIR_CACHE: | 50 } |
| 51 case base::DIR_CACHE: { |
49 *result = FilePath(base::android::GetCacheDirectory()); | 52 *result = FilePath(base::android::GetCacheDirectory()); |
50 return true; | 53 return true; |
51 case base::DIR_ANDROID_APP_DATA: | 54 } |
| 55 case base::DIR_ANDROID_APP_DATA: { |
52 *result = FilePath(base::android::GetDataDirectory()); | 56 *result = FilePath(base::android::GetDataDirectory()); |
53 return true; | 57 return true; |
54 default: | 58 } |
| 59 case base::DIR_HOME: { |
| 60 *result = file_util::GetHomeDir(); |
| 61 return true; |
| 62 } |
| 63 default: { |
55 // Note: the path system expects this function to override the default | 64 // Note: the path system expects this function to override the default |
56 // behavior. So no need to log an error if we don't support a given | 65 // behavior. So no need to log an error if we don't support a given |
57 // path. The system will just use the default. | 66 // path. The system will just use the default. |
58 return false; | 67 return false; |
| 68 } |
59 } | 69 } |
60 } | 70 } |
61 | 71 |
62 } // namespace base | 72 } // namespace base |
OLD | NEW |