| 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 FilePath bin_dir; |
| 25 int bin_dir_size = readlink(kProcSelfExe, bin_dir, PATH_MAX); | 25 if (!ReadSymbolicLink(FilePath(kProcSelfExe), &bin_dir)) { |
| 26 if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) { | |
| 27 NOTREACHED() << "Unable to resolve " << kProcSelfExe << "."; | 26 NOTREACHED() << "Unable to resolve " << kProcSelfExe << "."; |
| 28 return false; | 27 return false; |
| 29 } | 28 } |
| 30 bin_dir[bin_dir_size] = 0; | 29 *result = bin_dir; |
| 31 *result = FilePath(bin_dir); | |
| 32 return true; | 30 return true; |
| 33 } | 31 } |
| 34 case base::FILE_MODULE: | 32 case base::FILE_MODULE: |
| 35 // dladdr didn't work in Android as only the file name was returned. | 33 // dladdr didn't work in Android as only the file name was returned. |
| 36 NOTIMPLEMENTED(); | 34 NOTIMPLEMENTED(); |
| 37 return false; | 35 return false; |
| 38 case base::DIR_MODULE: | 36 case base::DIR_MODULE: |
| 39 return base::android::GetNativeLibraryDirectory(result); | 37 return base::android::GetNativeLibraryDirectory(result); |
| 40 case base::DIR_SOURCE_ROOT: | 38 case base::DIR_SOURCE_ROOT: |
| 41 // Used only by tests. | 39 // Used only by tests. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 54 return base::android::GetExternalStorageDirectory(result); | 52 return base::android::GetExternalStorageDirectory(result); |
| 55 default: | 53 default: |
| 56 // Note: the path system expects this function to override the default | 54 // Note: the path system expects this function to override the default |
| 57 // 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 |
| 58 // path. The system will just use the default. | 56 // path. The system will just use the default. |
| 59 return false; | 57 return false; |
| 60 } | 58 } |
| 61 } | 59 } |
| 62 | 60 |
| 63 } // namespace base | 61 } // namespace base |
| OLD | NEW |