1 // Copyright 2006-2008 The Chromium Authors 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 #include "build/build_config.h" 11 12 namespace base { 13 PathProvider(int key,FilePath * result)14bool PathProvider(int key, FilePath* result) { 15 // NOTE: DIR_CURRENT is a special case in PathService::Get 16 17 switch (key) { 18 case DIR_EXE: 19 if (!PathService::Get(FILE_EXE, result)) 20 return false; 21 *result = result->DirName(); 22 return true; 23 #if !BUILDFLAG(IS_FUCHSIA) 24 case DIR_MODULE: 25 if (!PathService::Get(FILE_MODULE, result)) 26 return false; 27 *result = result->DirName(); 28 return true; 29 case DIR_ASSETS: 30 return PathService::Get(DIR_MODULE, result); 31 #endif // !BUILDFLAG(IS_FUCHSIA) 32 case DIR_TEMP: 33 return GetTempDir(result); 34 case DIR_HOME: 35 *result = GetHomeDir(); 36 return true; 37 case DIR_GEN_TEST_DATA_ROOT: 38 #if !BUILDFLAG(IS_FUCHSIA) 39 // On most platforms, all build output is in the same directory, so 40 // use DIR_MODULE to get the path to the current binary. 41 return PathService::Get(DIR_MODULE, result); 42 #endif // !BUILDFLAG(IS_FUCHSIA) 43 case DIR_TEST_DATA: { 44 FilePath test_data_path; 45 if (!PathService::Get(DIR_SRC_TEST_DATA_ROOT, &test_data_path)) 46 return false; 47 test_data_path = test_data_path.Append(FILE_PATH_LITERAL("base")); 48 test_data_path = test_data_path.Append(FILE_PATH_LITERAL("test")); 49 test_data_path = test_data_path.Append(FILE_PATH_LITERAL("data")); 50 if (!PathExists(test_data_path)) // We don't want to create this. 51 return false; 52 *result = test_data_path; 53 return true; 54 } 55 } 56 57 return false; 58 } 59 60 } // namespace base 61