blob: 31bc55401af4a8087b3319ba4f35d796e918c376 [file] [log] [blame]
license.botf003cfe2008-08-24 09:55:55 +09001// Copyright (c) 2006-2008 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.
initial.commit3f4a7322008-07-27 06:49:38 +09004
5#include "base/base_paths.h"
6
brettw@chromium.org59eef1f2013-02-24 14:40:52 +09007#include "base/files/file_path.h"
brettw@chromium.org01f3da42014-08-14 05:22:14 +09008#include "base/files/file_util.h"
initial.commit3f4a7322008-07-27 06:49:38 +09009#include "base/path_service.h"
10
initial.commit3f4a7322008-07-27 06:49:38 +090011namespace base {
12
evanm@google.com3e9d5d72008-11-20 01:50:03 +090013bool PathProvider(int key, FilePath* result) {
gab@chromium.org97fc1e62012-09-21 01:24:52 +090014 // NOTE: DIR_CURRENT is a special case in PathService::Get
initial.commit3f4a7322008-07-27 06:49:38 +090015
initial.commit3f4a7322008-07-27 06:49:38 +090016 switch (key) {
tfarina@chromium.orge6598042013-03-28 09:40:04 +090017 case DIR_EXE:
brettw@chromium.org49de1af2014-02-20 05:34:23 +090018 PathService::Get(FILE_EXE, result);
19 *result = result->DirName();
20 return true;
tfarina@chromium.orge6598042013-03-28 09:40:04 +090021 case DIR_MODULE:
brettw@chromium.org49de1af2014-02-20 05:34:23 +090022 PathService::Get(FILE_MODULE, result);
23 *result = result->DirName();
24 return true;
tfarina@chromium.orge6598042013-03-28 09:40:04 +090025 case DIR_TEMP:
brettw@chromium.org49de1af2014-02-20 05:34:23 +090026 if (!GetTempDir(result))
initial.commit3f4a7322008-07-27 06:49:38 +090027 return false;
brettw@chromium.org49de1af2014-02-20 05:34:23 +090028 return true;
29 case base::DIR_HOME:
30 *result = GetHomeDir();
31 return true;
maniscalco33f28802015-12-12 03:23:13 +090032 case DIR_TEST_DATA: {
33 FilePath test_data_path;
34 if (!PathService::Get(DIR_SOURCE_ROOT, &test_data_path))
tfarina@chromium.orge6598042013-03-28 09:40:04 +090035 return false;
maniscalco33f28802015-12-12 03:23:13 +090036 test_data_path = test_data_path.Append(FILE_PATH_LITERAL("base"));
37 test_data_path = test_data_path.Append(FILE_PATH_LITERAL("test"));
38 test_data_path = test_data_path.Append(FILE_PATH_LITERAL("data"));
39 if (!PathExists(test_data_path)) // We don't want to create this.
tfarina@chromium.orge6598042013-03-28 09:40:04 +090040 return false;
maniscalco33f28802015-12-12 03:23:13 +090041 *result = test_data_path;
brettw@chromium.org49de1af2014-02-20 05:34:23 +090042 return true;
maniscalco33f28802015-12-12 03:23:13 +090043 }
initial.commit3f4a7322008-07-27 06:49:38 +090044 default:
45 return false;
46 }
initial.commit3f4a7322008-07-27 06:49:38 +090047}
48
49} // namespace base