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/logging.h"
10 #include "base/android_os.h"
14 const char kSelfExe
[] = "/proc/self/exe";
16 bool PathProviderAndroid(int key
, FilePath
* result
) {
18 case base::FILE_EXE
: {
19 char bin_dir
[PATH_MAX
+ 1];
20 int bin_dir_size
= readlink(kSelfExe
, bin_dir
, PATH_MAX
);
21 if (bin_dir_size
< 0 || bin_dir_size
> PATH_MAX
) {
22 NOTREACHED() << "Unable to resolve " << kSelfExe
<< ".";
25 bin_dir
[bin_dir_size
] = 0;
26 *result
= FilePath(bin_dir
);
29 case base::FILE_MODULE
:
30 // TODO(port): Find out whether we can use dladdr to implement this, and
31 // then use DIR_MODULE's default implementation in base_file.cc.
34 case base::DIR_MODULE
: {
35 AndroidOS
* aos
= AndroidOS::GetSharedInstance();
37 *result
= aos
->GetLibDirectory();
40 case base::DIR_SOURCE_ROOT
:
41 // This const is only used for tests. Files in this directory are pushed
42 // to the device via test script.
43 *result
= FilePath(FILE_PATH_LITERAL("/data/local/tmp/"));
45 case base::DIR_CACHE
: {
46 AndroidOS
* aos
= AndroidOS::GetSharedInstance();
48 *result
= aos
->GetCacheDirectory();
52 // 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
54 // path. The system will just use the default.