aurimas@chromium.org | 59cc7cf | 2012-07-03 05:04:04 +0900 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
michaelbai@google.com | 2251c62 | 2011-06-22 07:34:50 +0900 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
gab@chromium.org | 97fc1e6 | 2012-09-21 01:24:52 +0900 | [diff] [blame^] | 5 | // Defines base::PathProviderAndroid which replaces base::PathProviderPosix for |
| 6 | // Android in base/path_service.cc. |
michaelbai@google.com | 2251c62 | 2011-06-22 07:34:50 +0900 | [diff] [blame] | 7 | |
| 8 | #include <unistd.h> |
| 9 | |
michaelbai@google.com | 686190b | 2011-08-03 01:11:16 +0900 | [diff] [blame] | 10 | #include "base/android/jni_android.h" |
| 11 | #include "base/android/path_utils.h" |
gab@chromium.org | 97fc1e6 | 2012-09-21 01:24:52 +0900 | [diff] [blame^] | 12 | #include "base/base_paths.h" |
michaelbai@google.com | 686190b | 2011-08-03 01:11:16 +0900 | [diff] [blame] | 13 | #include "base/file_path.h" |
jar@chromium.org | 702215c | 2012-07-24 02:32:08 +0900 | [diff] [blame] | 14 | #include "base/file_util.h" |
michaelbai@google.com | 2251c62 | 2011-06-22 07:34:50 +0900 | [diff] [blame] | 15 | #include "base/logging.h" |
thestig@chromium.org | 0c1da82 | 2012-09-15 19:51:05 +0900 | [diff] [blame] | 16 | #include "base/process_util.h" |
michaelbai@google.com | 686190b | 2011-08-03 01:11:16 +0900 | [diff] [blame] | 17 | |
| 18 | namespace base { |
| 19 | |
michaelbai@google.com | 2251c62 | 2011-06-22 07:34:50 +0900 | [diff] [blame] | 20 | bool PathProviderAndroid(int key, FilePath* result) { |
| 21 | switch (key) { |
| 22 | case base::FILE_EXE: { |
| 23 | char bin_dir[PATH_MAX + 1]; |
thestig@chromium.org | 0c1da82 | 2012-09-15 19:51:05 +0900 | [diff] [blame] | 24 | int bin_dir_size = readlink(kProcSelfExe, bin_dir, PATH_MAX); |
michaelbai@google.com | 2251c62 | 2011-06-22 07:34:50 +0900 | [diff] [blame] | 25 | if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) { |
thestig@chromium.org | 0c1da82 | 2012-09-15 19:51:05 +0900 | [diff] [blame] | 26 | NOTREACHED() << "Unable to resolve " << kProcSelfExe << "."; |
michaelbai@google.com | 2251c62 | 2011-06-22 07:34:50 +0900 | [diff] [blame] | 27 | return false; |
| 28 | } |
| 29 | bin_dir[bin_dir_size] = 0; |
| 30 | *result = FilePath(bin_dir); |
| 31 | return true; |
| 32 | } |
gab@chromium.org | 97fc1e6 | 2012-09-21 01:24:52 +0900 | [diff] [blame^] | 33 | case base::FILE_MODULE: |
michaelbai@google.com | 686190b | 2011-08-03 01:11:16 +0900 | [diff] [blame] | 34 | // dladdr didn't work in Android as only the file name was returned. |
michaelbai@google.com | 2251c62 | 2011-06-22 07:34:50 +0900 | [diff] [blame] | 35 | NOTIMPLEMENTED(); |
| 36 | return false; |
gab@chromium.org | 97fc1e6 | 2012-09-21 01:24:52 +0900 | [diff] [blame^] | 37 | case base::DIR_MODULE: |
aurimas@chromium.org | 59cc7cf | 2012-07-03 05:04:04 +0900 | [diff] [blame] | 38 | *result = FilePath(base::android::GetNativeLibraryDirectory()); |
michaelbai@google.com | 2251c62 | 2011-06-22 07:34:50 +0900 | [diff] [blame] | 39 | return true; |
gab@chromium.org | 97fc1e6 | 2012-09-21 01:24:52 +0900 | [diff] [blame^] | 40 | case base::DIR_SOURCE_ROOT: |
nileshagrawal@chromium.org | 1b1c391 | 2012-09-05 03:50:48 +0900 | [diff] [blame] | 41 | // This const is only used for tests. |
| 42 | *result = FilePath(base::android::GetExternalStorageDirectory()); |
michaelbai@google.com | 2251c62 | 2011-06-22 07:34:50 +0900 | [diff] [blame] | 43 | return true; |
gab@chromium.org | 97fc1e6 | 2012-09-21 01:24:52 +0900 | [diff] [blame^] | 44 | case base::DIR_USER_DESKTOP: |
| 45 | // Android doesn't support GetUserDesktop. |
| 46 | NOTIMPLEMENTED(); |
| 47 | return false; |
| 48 | case base::DIR_CACHE: |
michaelbai@google.com | 686190b | 2011-08-03 01:11:16 +0900 | [diff] [blame] | 49 | *result = FilePath(base::android::GetCacheDirectory()); |
michaelbai@google.com | 2251c62 | 2011-06-22 07:34:50 +0900 | [diff] [blame] | 50 | return true; |
gab@chromium.org | 97fc1e6 | 2012-09-21 01:24:52 +0900 | [diff] [blame^] | 51 | case base::DIR_ANDROID_APP_DATA: |
michaelbai@google.com | 686190b | 2011-08-03 01:11:16 +0900 | [diff] [blame] | 52 | *result = FilePath(base::android::GetDataDirectory()); |
| 53 | return true; |
gab@chromium.org | 97fc1e6 | 2012-09-21 01:24:52 +0900 | [diff] [blame^] | 54 | case base::DIR_HOME: |
jar@chromium.org | 702215c | 2012-07-24 02:32:08 +0900 | [diff] [blame] | 55 | *result = file_util::GetHomeDir(); |
| 56 | return true; |
gab@chromium.org | 97fc1e6 | 2012-09-21 01:24:52 +0900 | [diff] [blame^] | 57 | case base::DIR_ANDROID_EXTERNAL_STORAGE: |
nileshagrawal@chromium.org | a4be12c | 2012-08-24 19:08:27 +0900 | [diff] [blame] | 58 | *result = FilePath(base::android::GetExternalStorageDirectory()); |
| 59 | return true; |
gab@chromium.org | 97fc1e6 | 2012-09-21 01:24:52 +0900 | [diff] [blame^] | 60 | default: |
michaelbai@google.com | 2251c62 | 2011-06-22 07:34:50 +0900 | [diff] [blame] | 61 | // 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 | // path. The system will just use the default. |
| 64 | return false; |
michaelbai@google.com | 2251c62 | 2011-06-22 07:34:50 +0900 | [diff] [blame] | 65 | } |
| 66 | } |
| 67 | |
| 68 | } // namespace base |