| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| 10 #include "base/android/path_utils.h" |
| 11 #include "base/file_path.h" |
| 9 #include "base/logging.h" | 12 #include "base/logging.h" |
| 10 #include "base/android_os.h" | 13 |
| 14 namespace { |
| 15 |
| 16 const char kSelfExe[] = "/proc/self/exe"; |
| 17 |
| 18 } // namespace |
| 11 | 19 |
| 12 namespace base { | 20 namespace base { |
| 13 | 21 |
| 14 const char kSelfExe[] = "/proc/self/exe"; | |
| 15 | |
| 16 bool PathProviderAndroid(int key, FilePath* result) { | 22 bool PathProviderAndroid(int key, FilePath* result) { |
| 17 switch (key) { | 23 switch (key) { |
| 18 case base::FILE_EXE: { | 24 case base::FILE_EXE: { |
| 19 char bin_dir[PATH_MAX + 1]; | 25 char bin_dir[PATH_MAX + 1]; |
| 20 int bin_dir_size = readlink(kSelfExe, bin_dir, PATH_MAX); | 26 int bin_dir_size = readlink(kSelfExe, bin_dir, PATH_MAX); |
| 21 if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) { | 27 if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) { |
| 22 NOTREACHED() << "Unable to resolve " << kSelfExe << "."; | 28 NOTREACHED() << "Unable to resolve " << kSelfExe << "."; |
| 23 return false; | 29 return false; |
| 24 } | 30 } |
| 25 bin_dir[bin_dir_size] = 0; | 31 bin_dir[bin_dir_size] = 0; |
| 26 *result = FilePath(bin_dir); | 32 *result = FilePath(bin_dir); |
| 27 return true; | 33 return true; |
| 28 } | 34 } |
| 29 case base::FILE_MODULE: | 35 case base::FILE_MODULE: |
| 30 // TODO(port): Find out whether we can use dladdr to implement this, and | 36 // dladdr didn't work in Android as only the file name was returned. |
| 31 // then use DIR_MODULE's default implementation in base_file.cc. | |
| 32 NOTIMPLEMENTED(); | 37 NOTIMPLEMENTED(); |
| 33 return false; | 38 return false; |
| 34 case base::DIR_MODULE: { | 39 case base::DIR_MODULE: { |
| 35 AndroidOS* aos = AndroidOS::GetSharedInstance(); | 40 *result = FilePath(base::android::GetDataDirectory()).DirName() |
| 36 DCHECK(aos); | 41 .Append("lib"); |
| 37 *result = aos->GetLibDirectory(); | |
| 38 return true; | 42 return true; |
| 39 } | 43 } |
| 40 case base::DIR_SOURCE_ROOT: | 44 case base::DIR_SOURCE_ROOT: |
| 41 // This const is only used for tests. Files in this directory are pushed | 45 // This const is only used for tests. Files in this directory are pushed |
| 42 // to the device via test script. | 46 // to the device via test script. |
| 43 *result = FilePath(FILE_PATH_LITERAL("/data/local/tmp/")); | 47 *result = FilePath(FILE_PATH_LITERAL("/data/local/tmp/")); |
| 44 return true; | 48 return true; |
| 45 case base::DIR_CACHE: { | 49 case base::DIR_CACHE: |
| 46 AndroidOS* aos = AndroidOS::GetSharedInstance(); | 50 *result = FilePath(base::android::GetCacheDirectory()); |
| 47 DCHECK(aos); | |
| 48 *result = aos->GetCacheDirectory(); | |
| 49 return true; | 51 return true; |
| 50 } | 52 case base::DIR_ANDROID_APP_DATA: |
| 53 *result = FilePath(base::android::GetDataDirectory()); |
| 54 return true; |
| 51 default: | 55 default: |
| 52 // Note: the path system expects this function to override the default | 56 // Note: the path system expects this function to override the default |
| 53 // behavior. So no need to log an error if we don't support a given | 57 // behavior. So no need to log an error if we don't support a given |
| 54 // path. The system will just use the default. | 58 // path. The system will just use the default. |
| 55 return false; | 59 return false; |
| 56 } | 60 } |
| 57 } | 61 } |
| 58 | 62 |
| 59 } // namespace base | 63 } // namespace base |
| OLD | NEW |