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.
5 #include "base/base_paths.h"
9 #include "base/android/jni_android.h"
10 #include "base/android/path_utils.h"
11 #include "base/file_path.h"
12 #include "base/logging.h"
16 const char kSelfExe
[] = "/proc/self/exe";
22 bool PathProviderAndroid(int key
, FilePath
* result
) {
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
<< ".";
31 bin_dir
[bin_dir_size
] = 0;
32 *result
= FilePath(bin_dir
);
35 case base::FILE_MODULE
:
36 // dladdr didn't work in Android as only the file name was returned.
39 case base::DIR_MODULE
: {
40 *result
= FilePath(base::android::GetDataDirectory()).DirName()
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/"));
50 *result
= FilePath(base::android::GetCacheDirectory());
52 case base::DIR_ANDROID_APP_DATA
:
53 *result
= FilePath(base::android::GetDataDirectory());
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.