OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Defines base::PathProviderPosix, default path provider on POSIX OSes that | 5 // Defines base::PathProviderPosix, default path provider on POSIX OSes that |
6 // don't have their own base_paths_OS.cc implementation (i.e. all but Mac and | 6 // don't have their own base_paths_OS.cc implementation (i.e. all but Mac and |
7 // Android). | 7 // Android). |
8 | 8 |
| 9 #include "base/base_paths.h" |
| 10 |
9 #include <limits.h> | 11 #include <limits.h> |
10 #include <stddef.h> | 12 #include <stddef.h> |
11 | 13 |
| 14 #include <memory> |
12 #include <ostream> | 15 #include <ostream> |
13 #include <string> | 16 #include <string> |
14 | 17 |
15 #include "base/base_paths.h" | |
16 #include "base/environment.h" | 18 #include "base/environment.h" |
17 #include "base/files/file_path.h" | 19 #include "base/files/file_path.h" |
18 #include "base/files/file_util.h" | 20 #include "base/files/file_util.h" |
19 #include "base/logging.h" | 21 #include "base/logging.h" |
20 #include "base/memory/scoped_ptr.h" | |
21 #include "base/nix/xdg_util.h" | 22 #include "base/nix/xdg_util.h" |
22 #include "base/path_service.h" | 23 #include "base/path_service.h" |
23 #include "base/process/process_metrics.h" | 24 #include "base/process/process_metrics.h" |
24 #include "build/build_config.h" | 25 #include "build/build_config.h" |
25 | 26 |
26 #if defined(OS_FREEBSD) | 27 #if defined(OS_FREEBSD) |
27 #include <sys/param.h> | 28 #include <sys/param.h> |
28 #include <sys/sysctl.h> | 29 #include <sys/sysctl.h> |
29 #elif defined(OS_SOLARIS) | 30 #elif defined(OS_SOLARIS) |
30 #include <stdlib.h> | 31 #include <stdlib.h> |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 if ((cpath = getenv("CHROME_EXE_PATH")) != NULL) | 73 if ((cpath = getenv("CHROME_EXE_PATH")) != NULL) |
73 *result = FilePath(cpath); | 74 *result = FilePath(cpath); |
74 else | 75 else |
75 *result = FilePath("/usr/local/chrome/chrome"); | 76 *result = FilePath("/usr/local/chrome/chrome"); |
76 return true; | 77 return true; |
77 #endif | 78 #endif |
78 } | 79 } |
79 case base::DIR_SOURCE_ROOT: { | 80 case base::DIR_SOURCE_ROOT: { |
80 // Allow passing this in the environment, for more flexibility in build | 81 // Allow passing this in the environment, for more flexibility in build |
81 // tree configurations (sub-project builds, gyp --output_dir, etc.) | 82 // tree configurations (sub-project builds, gyp --output_dir, etc.) |
82 scoped_ptr<base::Environment> env(base::Environment::Create()); | 83 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
83 std::string cr_source_root; | 84 std::string cr_source_root; |
84 if (env->GetVar("CR_SOURCE_ROOT", &cr_source_root)) { | 85 if (env->GetVar("CR_SOURCE_ROOT", &cr_source_root)) { |
85 path = FilePath(cr_source_root); | 86 path = FilePath(cr_source_root); |
86 if (base::PathExists(path)) { | 87 if (base::PathExists(path)) { |
87 *result = path; | 88 *result = path; |
88 return true; | 89 return true; |
89 } else { | 90 } else { |
90 DLOG(WARNING) << "CR_SOURCE_ROOT is set, but it appears to not " | 91 DLOG(WARNING) << "CR_SOURCE_ROOT is set, but it appears to not " |
91 << "point to a directory."; | 92 << "point to a directory."; |
92 } | 93 } |
93 } | 94 } |
94 // On POSIX, unit tests execute two levels deep from the source root. | 95 // On POSIX, unit tests execute two levels deep from the source root. |
95 // For example: out/{Debug|Release}/net_unittest | 96 // For example: out/{Debug|Release}/net_unittest |
96 if (PathService::Get(base::DIR_EXE, &path)) { | 97 if (PathService::Get(base::DIR_EXE, &path)) { |
97 *result = path.DirName().DirName(); | 98 *result = path.DirName().DirName(); |
98 return true; | 99 return true; |
99 } | 100 } |
100 | 101 |
101 DLOG(ERROR) << "Couldn't find your source root. " | 102 DLOG(ERROR) << "Couldn't find your source root. " |
102 << "Try running from your chromium/src directory."; | 103 << "Try running from your chromium/src directory."; |
103 return false; | 104 return false; |
104 } | 105 } |
105 case base::DIR_USER_DESKTOP: | 106 case base::DIR_USER_DESKTOP: |
106 *result = base::nix::GetXDGUserDirectory("DESKTOP", "Desktop"); | 107 *result = base::nix::GetXDGUserDirectory("DESKTOP", "Desktop"); |
107 return true; | 108 return true; |
108 case base::DIR_CACHE: { | 109 case base::DIR_CACHE: { |
109 scoped_ptr<base::Environment> env(base::Environment::Create()); | 110 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
110 FilePath cache_dir(base::nix::GetXDGDirectory(env.get(), "XDG_CACHE_HOME", | 111 FilePath cache_dir(base::nix::GetXDGDirectory(env.get(), "XDG_CACHE_HOME", |
111 ".cache")); | 112 ".cache")); |
112 *result = cache_dir; | 113 *result = cache_dir; |
113 return true; | 114 return true; |
114 } | 115 } |
115 } | 116 } |
116 return false; | 117 return false; |
117 } | 118 } |
118 | 119 |
119 } // namespace base | 120 } // namespace base |
OLD | NEW |