Fixed compile warnings.
[chromium-blink-merge.git] / base / base_paths_android.cc
blob9d04b764df03b667481518c0b83e2e3bb542b8df
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"
7 #include <unistd.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"
14 namespace {
16 const char kSelfExe[] = "/proc/self/exe";
18 } // namespace
20 namespace base {
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;
31 bin_dir[bin_dir_size] = 0;
32 *result = FilePath(bin_dir);
33 return true;
35 case base::FILE_MODULE:
36 // dladdr didn't work in Android as only the file name was returned.
37 NOTIMPLEMENTED();
38 return false;
39 case base::DIR_MODULE: {
40 *result = FilePath(base::android::GetDataDirectory()).DirName()
41 .Append("lib");
42 return true;
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;
49 case base::DIR_CACHE:
50 *result = FilePath(base::android::GetCacheDirectory());
51 return true;
52 case base::DIR_ANDROID_APP_DATA:
53 *result = FilePath(base::android::GetDataDirectory());
54 return true;
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;
63 } // namespace base