[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #include "base/base_paths.h" | ||||
6 | |||||
7 | #include <unistd.h> | ||||
8 | |||||
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 9 | #include "base/android/jni_android.h" |
10 | #include "base/android/path_utils.h" | ||||
11 | #include "base/file_path.h" | ||||
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 12 | #include "base/logging.h" |
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 13 | |
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 14 | namespace { |
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 15 | |
16 | const char kSelfExe[] = "/proc/self/exe"; | ||||
17 | |||||
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 18 | } // namespace |
19 | |||||
20 | namespace base { | ||||
21 | |||||
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 22 | bool PathProviderAndroid(int key, FilePath* result) { |
23 | switch (key) { | ||||
24 | case base::FILE_EXE: { | ||||
25 | char bin_dir[PATH_MAX + 1]; | ||||
26 | int bin_dir_size = readlink(kSelfExe, bin_dir, PATH_MAX); | ||||
27 | if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) { | ||||
28 | NOTREACHED() << "Unable to resolve " << kSelfExe << "."; | ||||
29 | return false; | ||||
30 | } | ||||
31 | bin_dir[bin_dir_size] = 0; | ||||
32 | *result = FilePath(bin_dir); | ||||
33 | return true; | ||||
34 | } | ||||
35 | case base::FILE_MODULE: | ||||
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 36 | // dladdr didn't work in Android as only the file name was returned. |
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 37 | NOTIMPLEMENTED(); |
38 | return false; | ||||
39 | case base::DIR_MODULE: { | ||||
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 40 | *result = FilePath(base::android::GetDataDirectory()).DirName() |
41 | .Append("lib"); | ||||
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 42 | return true; |
43 | } | ||||
44 | case base::DIR_SOURCE_ROOT: | ||||
45 | // This const is only used for tests. Files in this directory are pushed | ||||
46 | // to the device via test script. | ||||
47 | *result = FilePath(FILE_PATH_LITERAL("/data/local/tmp/")); | ||||
48 | return true; | ||||
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 49 | case base::DIR_CACHE: |
50 | *result = FilePath(base::android::GetCacheDirectory()); | ||||
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 51 | return true; |
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 52 | case base::DIR_ANDROID_APP_DATA: |
53 | *result = FilePath(base::android::GetDataDirectory()); | ||||
54 | return true; | ||||
[email protected] | f7d6997 | 2011-06-21 22:34:50 | [diff] [blame] | 55 | default: |
56 | // 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 | ||||
58 | // path. The system will just use the default. | ||||
59 | return false; | ||||
60 | } | ||||
61 | } | ||||
62 | |||||
63 | } // namespace base |