blob: 9d04b764df03b667481518c0b83e2e3bb542b8df [file] [log] [blame]
[email protected]f7d69972011-06-21 22:34:501// 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]61c86c62011-08-02 16:11:169#include "base/android/jni_android.h"
10#include "base/android/path_utils.h"
11#include "base/file_path.h"
[email protected]f7d69972011-06-21 22:34:5012#include "base/logging.h"
[email protected]f7d69972011-06-21 22:34:5013
[email protected]61c86c62011-08-02 16:11:1614namespace {
[email protected]f7d69972011-06-21 22:34:5015
16const char kSelfExe[] = "/proc/self/exe";
17
[email protected]61c86c62011-08-02 16:11:1618} // namespace
19
20namespace base {
21
[email protected]f7d69972011-06-21 22:34:5022bool 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]61c86c62011-08-02 16:11:1636 // dladdr didn't work in Android as only the file name was returned.
[email protected]f7d69972011-06-21 22:34:5037 NOTIMPLEMENTED();
38 return false;
39 case base::DIR_MODULE: {
[email protected]61c86c62011-08-02 16:11:1640 *result = FilePath(base::android::GetDataDirectory()).DirName()
41 .Append("lib");
[email protected]f7d69972011-06-21 22:34:5042 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]61c86c62011-08-02 16:11:1649 case base::DIR_CACHE:
50 *result = FilePath(base::android::GetCacheDirectory());
[email protected]f7d69972011-06-21 22:34:5051 return true;
[email protected]61c86c62011-08-02 16:11:1652 case base::DIR_ANDROID_APP_DATA:
53 *result = FilePath(base::android::GetDataDirectory());
54 return true;
[email protected]f7d69972011-06-21 22:34:5055 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