1// 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.
4
5#include "base/base_paths.h"
6
7#include "base/files/file_path.h"
8#include "base/files/file_util.h"
9#include "base/path_service.h"
10
11namespace base {
12
13bool PathProvider(int key, FilePath* result) {
14  // NOTE: DIR_CURRENT is a special case in PathService::Get
15
16  switch (key) {
17    case DIR_EXE:
18      PathService::Get(FILE_EXE, result);
19      *result = result->DirName();
20      return true;
21    case DIR_MODULE:
22      PathService::Get(FILE_MODULE, result);
23      *result = result->DirName();
24      return true;
25    case DIR_TEMP:
26      if (!GetTempDir(result))
27        return false;
28      return true;
29    case base::DIR_HOME:
30      *result = GetHomeDir();
31      return true;
32    case DIR_TEST_DATA: {
33      FilePath test_data_path;
34      if (!PathService::Get(DIR_SOURCE_ROOT, &test_data_path))
35        return false;
36      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.
40        return false;
41      *result = test_data_path;
42      return true;
43    }
44    default:
45      return false;
46  }
47}
48
49}  // namespace base
50