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 // Defines base::PathProviderAndroid which replaces base::PathProviderPosix for |
6 // Android in base/path_service.cc. | 6 // Android in base/path_service.cc. |
7 | 7 |
8 #include <limits.h> | 8 #include <limits.h> |
9 #include <unistd.h> | 9 #include <unistd.h> |
10 | 10 |
11 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
12 #include "base/android/path_utils.h" | 12 #include "base/android/path_utils.h" |
13 #include "base/base_paths.h" | 13 #include "base/base_paths.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/process/process_metrics.h" | 17 #include "base/process/process_metrics.h" |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 | 20 |
21 bool PathProviderAndroid(int key, FilePath* result) { | 21 bool PathProviderAndroid(int key, FilePath* result) { |
22 switch (key) { | 22 switch (key) { |
23 case base::FILE_EXE: { | 23 case base::FILE_EXE: { |
24 char bin_dir[PATH_MAX + 1]; | 24 char bin_dir[PATH_MAX + 1]; |
25 int bin_dir_size = readlink(kProcSelfExe, bin_dir, PATH_MAX); | 25 int bin_dir_size = readlink(kProcSelfExe, bin_dir, PATH_MAX); |
26 // TODO(falken): This PCHECK is for debugging crbug.com/600226. | 26 if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) { |
27 // Revert to NOTREACHED when the cause of the bug is understood. | 27 NOTREACHED() << "Unable to resolve " << kProcSelfExe << "."; |
28 PCHECK(bin_dir_size > 0 && bin_dir_size <= PATH_MAX) | 28 return false; |
29 << "Unable to resolve " << kProcSelfExe | 29 } |
30 << ". bin_dir_size=" << bin_dir_size; | |
31 bin_dir[bin_dir_size] = 0; | 30 bin_dir[bin_dir_size] = 0; |
32 *result = FilePath(bin_dir); | 31 *result = FilePath(bin_dir); |
33 return true; | 32 return true; |
34 } | 33 } |
35 case base::FILE_MODULE: | 34 case base::FILE_MODULE: |
36 // dladdr didn't work in Android as only the file name was returned. | 35 // dladdr didn't work in Android as only the file name was returned. |
37 NOTIMPLEMENTED(); | 36 NOTIMPLEMENTED(); |
38 return false; | 37 return false; |
39 case base::DIR_MODULE: | 38 case base::DIR_MODULE: |
40 return base::android::GetNativeLibraryDirectory(result); | 39 return base::android::GetNativeLibraryDirectory(result); |
(...skipping 12 matching lines...) Expand all Loading... |
53 return base::android::GetExternalStorageDirectory(result); | 52 return base::android::GetExternalStorageDirectory(result); |
54 default: | 53 default: |
55 // Note: the path system expects this function to override the default | 54 // 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 | 55 // behavior. So no need to log an error if we don't support a given |
57 // path. The system will just use the default. | 56 // path. The system will just use the default. |
58 return false; | 57 return false; |
59 } | 58 } |
60 } | 59 } |
61 | 60 |
62 } // namespace base | 61 } // namespace base |
OLD | NEW |