xref: /aosp_15_r20/external/libchrome/base/base_paths.cc (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file.
4*635a8641SAndroid Build Coastguard Worker 
5*635a8641SAndroid Build Coastguard Worker #include "base/base_paths.h"
6*635a8641SAndroid Build Coastguard Worker 
7*635a8641SAndroid Build Coastguard Worker #include "base/files/file_path.h"
8*635a8641SAndroid Build Coastguard Worker #include "base/files/file_util.h"
9*635a8641SAndroid Build Coastguard Worker #include "base/path_service.h"
10*635a8641SAndroid Build Coastguard Worker 
11*635a8641SAndroid Build Coastguard Worker namespace base {
12*635a8641SAndroid Build Coastguard Worker 
PathProvider(int key,FilePath * result)13*635a8641SAndroid Build Coastguard Worker bool PathProvider(int key, FilePath* result) {
14*635a8641SAndroid Build Coastguard Worker   // NOTE: DIR_CURRENT is a special case in PathService::Get
15*635a8641SAndroid Build Coastguard Worker 
16*635a8641SAndroid Build Coastguard Worker   switch (key) {
17*635a8641SAndroid Build Coastguard Worker     case DIR_EXE:
18*635a8641SAndroid Build Coastguard Worker       if (!PathService::Get(FILE_EXE, result))
19*635a8641SAndroid Build Coastguard Worker         return false;
20*635a8641SAndroid Build Coastguard Worker       *result = result->DirName();
21*635a8641SAndroid Build Coastguard Worker       return true;
22*635a8641SAndroid Build Coastguard Worker     case DIR_MODULE:
23*635a8641SAndroid Build Coastguard Worker       if (!PathService::Get(FILE_MODULE, result))
24*635a8641SAndroid Build Coastguard Worker         return false;
25*635a8641SAndroid Build Coastguard Worker       *result = result->DirName();
26*635a8641SAndroid Build Coastguard Worker       return true;
27*635a8641SAndroid Build Coastguard Worker     case DIR_ASSETS:
28*635a8641SAndroid Build Coastguard Worker       return PathService::Get(DIR_MODULE, result);
29*635a8641SAndroid Build Coastguard Worker     case DIR_TEMP:
30*635a8641SAndroid Build Coastguard Worker       return GetTempDir(result);
31*635a8641SAndroid Build Coastguard Worker     case base::DIR_HOME:
32*635a8641SAndroid Build Coastguard Worker       *result = GetHomeDir();
33*635a8641SAndroid Build Coastguard Worker       return true;
34*635a8641SAndroid Build Coastguard Worker     case DIR_TEST_DATA: {
35*635a8641SAndroid Build Coastguard Worker       FilePath test_data_path;
36*635a8641SAndroid Build Coastguard Worker       if (!PathService::Get(DIR_SOURCE_ROOT, &test_data_path))
37*635a8641SAndroid Build Coastguard Worker         return false;
38*635a8641SAndroid Build Coastguard Worker       test_data_path = test_data_path.Append(FILE_PATH_LITERAL("base"));
39*635a8641SAndroid Build Coastguard Worker       test_data_path = test_data_path.Append(FILE_PATH_LITERAL("test"));
40*635a8641SAndroid Build Coastguard Worker       test_data_path = test_data_path.Append(FILE_PATH_LITERAL("data"));
41*635a8641SAndroid Build Coastguard Worker       if (!PathExists(test_data_path))  // We don't want to create this.
42*635a8641SAndroid Build Coastguard Worker         return false;
43*635a8641SAndroid Build Coastguard Worker       *result = test_data_path;
44*635a8641SAndroid Build Coastguard Worker       return true;
45*635a8641SAndroid Build Coastguard Worker     }
46*635a8641SAndroid Build Coastguard Worker     default:
47*635a8641SAndroid Build Coastguard Worker       return false;
48*635a8641SAndroid Build Coastguard Worker   }
49*635a8641SAndroid Build Coastguard Worker }
50*635a8641SAndroid Build Coastguard Worker 
51*635a8641SAndroid Build Coastguard Worker }  // namespace base
52