|
8 | 8 | #include <memory> |
9 | 9 | #include <string> |
10 | 10 |
|
| 11 | +#include "base/base_switches.h" |
11 | 12 | #include "base/command_line.h" |
12 | | -#include "base/debug/stack_trace.h" |
13 | 13 | #include "base/environment.h" |
14 | 14 | #include "base/files/file_util.h" |
15 | 15 | #include "base/logging.h" |
16 | 16 | #include "base/mac/bundle_locations.h" |
17 | 17 | #include "base/path_service.h" |
18 | 18 | #include "base/strings/string_split.h" |
19 | 19 | #include "chrome/common/chrome_paths.h" |
| 20 | +#include "chrome/common/chrome_switches.h" |
20 | 21 | #include "components/content_settings/core/common/content_settings_pattern.h" |
21 | 22 | #include "content/public/common/content_switches.h" |
22 | 23 | #include "electron/buildflags/buildflags.h" |
|
29 | 30 | #include "shell/browser/electron_gpu_client.h" |
30 | 31 | #include "shell/browser/feature_list.h" |
31 | 32 | #include "shell/browser/relauncher.h" |
| 33 | +#include "shell/common/application_info.h" |
32 | 34 | #include "shell/common/electron_paths.h" |
33 | 35 | #include "shell/common/options_switches.h" |
| 36 | +#include "shell/common/platform_util.h" |
34 | 37 | #include "shell/renderer/electron_renderer_client.h" |
35 | 38 | #include "shell/renderer/electron_sandboxed_renderer_client.h" |
36 | 39 | #include "shell/utility/electron_content_utility_client.h" |
|
47 | 50 | #endif |
48 | 51 |
|
49 | 52 | #if defined(OS_LINUX) |
| 53 | +#include "base/nix/xdg_util.h" |
50 | 54 | #include "components/crash/core/app/breakpad_linux.h" |
51 | 55 | #include "v8/include/v8-wasm-trap-handler-posix.h" |
52 | 56 | #include "v8/include/v8.h" |
@@ -107,28 +111,89 @@ void InvalidParameterHandler(const wchar_t*, |
107 | 111 |
|
108 | 112 | // TODO(nornagon): move path provider overriding to its own file in |
109 | 113 | // shell/common |
110 | | -bool GetDefaultCrashDumpsPath(base::FilePath* path) { |
| 114 | +bool ElectronPathProvider(int key, base::FilePath* result) { |
| 115 | + bool create_dir = false; |
111 | 116 | base::FilePath cur; |
112 | | - if (!base::PathService::Get(DIR_USER_DATA, &cur)) |
113 | | - return false; |
| 117 | + switch (key) { |
| 118 | + case chrome::DIR_USER_DATA: |
| 119 | + if (!base::PathService::Get(DIR_APP_DATA, &cur)) |
| 120 | + return false; |
| 121 | + cur = cur.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); |
| 122 | + create_dir = true; |
| 123 | + break; |
| 124 | + case DIR_CRASH_DUMPS: |
| 125 | + if (!base::PathService::Get(chrome::DIR_USER_DATA, &cur)) |
| 126 | + return false; |
114 | 127 | #if defined(OS_MAC) || defined(OS_WIN) |
115 | | - cur = cur.Append(FILE_PATH_LITERAL("Crashpad")); |
| 128 | + cur = cur.Append(FILE_PATH_LITERAL("Crashpad")); |
| 129 | +#else |
| 130 | + cur = cur.Append(FILE_PATH_LITERAL("Crash Reports")); |
| 131 | +#endif |
| 132 | + create_dir = true; |
| 133 | + break; |
| 134 | + case chrome::DIR_APP_DICTIONARIES: |
| 135 | + // TODO(nornagon): can we just default to using Chrome's logic here? |
| 136 | + if (!base::PathService::Get(chrome::DIR_USER_DATA, &cur)) |
| 137 | + return false; |
| 138 | + cur = cur.Append(base::FilePath::FromUTF8Unsafe("Dictionaries")); |
| 139 | + create_dir = true; |
| 140 | + break; |
| 141 | + case DIR_USER_CACHE: { |
| 142 | +#if defined(OS_POSIX) |
| 143 | + int parent_key = base::DIR_CACHE; |
116 | 144 | #else |
117 | | - cur = cur.Append(FILE_PATH_LITERAL("Crash Reports")); |
| 145 | + // On Windows, there's no OS-level centralized location for caches, so |
| 146 | + // store the cache in the app data directory. |
| 147 | + int parent_key = base::DIR_APP_DATA; |
118 | 148 | #endif |
| 149 | + if (!base::PathService::Get(parent_key, &cur)) |
| 150 | + return false; |
| 151 | + cur = cur.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); |
| 152 | + create_dir = true; |
| 153 | + break; |
| 154 | + } |
| 155 | +#if defined(OS_LINUX) |
| 156 | + case DIR_APP_DATA: { |
| 157 | + auto env = base::Environment::Create(); |
| 158 | + cur = base::nix::GetXDGDirectory( |
| 159 | + env.get(), base::nix::kXdgConfigHomeEnvVar, base::nix::kDotConfigDir); |
| 160 | + break; |
| 161 | + } |
| 162 | +#endif |
| 163 | +#if defined(OS_WIN) |
| 164 | + case DIR_RECENT: |
| 165 | + if (!platform_util::GetFolderPath(DIR_RECENT, &cur)) |
| 166 | + return false; |
| 167 | + create_dir = true; |
| 168 | + break; |
| 169 | +#endif |
| 170 | + case DIR_APP_LOGS: |
| 171 | +#if defined(OS_MAC) |
| 172 | + if (!base::PathService::Get(base::DIR_HOME, &cur)) |
| 173 | + return false; |
| 174 | + cur = cur.Append(FILE_PATH_LITERAL("Library")); |
| 175 | + cur = cur.Append(FILE_PATH_LITERAL("Logs")); |
| 176 | + cur = cur.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); |
| 177 | +#else |
| 178 | + if (!base::PathService::Get(chrome::DIR_USER_DATA, &cur)) |
| 179 | + return false; |
| 180 | + cur = cur.Append(base::FilePath::FromUTF8Unsafe("logs")); |
| 181 | +#endif |
| 182 | + create_dir = true; |
| 183 | + break; |
| 184 | + default: |
| 185 | + return false; |
| 186 | + } |
| 187 | + |
119 | 188 | // TODO(bauerb): http://crbug.com/259796 |
120 | 189 | base::ThreadRestrictions::ScopedAllowIO allow_io; |
121 | | - if (!base::PathExists(cur) && !base::CreateDirectory(cur)) |
| 190 | + if (create_dir && !base::PathExists(cur) && !base::CreateDirectory(cur)) { |
122 | 191 | return false; |
123 | | - *path = cur; |
124 | | - return true; |
125 | | -} |
126 | | - |
127 | | -bool ElectronPathProvider(int key, base::FilePath* path) { |
128 | | - if (key == DIR_CRASH_DUMPS) { |
129 | | - return GetDefaultCrashDumpsPath(path); |
130 | 192 | } |
131 | | - return false; |
| 193 | + |
| 194 | + *result = cur; |
| 195 | + |
| 196 | + return true; |
132 | 197 | } |
133 | 198 |
|
134 | 199 | void RegisterPathProvider() { |
@@ -281,6 +346,13 @@ void ElectronMainDelegate::PreSandboxStartup() { |
281 | 346 | std::string process_type = |
282 | 347 | command_line->GetSwitchValueASCII(::switches::kProcessType); |
283 | 348 |
|
| 349 | + base::FilePath user_data_dir = |
| 350 | + command_line->GetSwitchValuePath(::switches::kUserDataDir); |
| 351 | + if (!user_data_dir.empty()) { |
| 352 | + base::PathService::OverrideAndCreateIfNeeded(chrome::DIR_USER_DATA, |
| 353 | + user_data_dir, false, true); |
| 354 | + } |
| 355 | + |
284 | 356 | #if !defined(MAS_BUILD) |
285 | 357 | crash_reporter::InitializeCrashKeys(); |
286 | 358 | #endif |
|
0 commit comments