Port Android relocation packer to chromium build
[chromium-blink-merge.git] / chrome / common / chrome_paths.cc
blob3cee502a40ad27df49287838e07968794698d47c
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
3 // found in the LICENSE file.
5 #include "chrome/common/chrome_paths.h"
7 #include "base/files/file_util.h"
8 #include "base/lazy_instance.h"
9 #include "base/logging.h"
10 #include "base/mac/bundle_locations.h"
11 #include "base/path_service.h"
12 #include "base/strings/string_util.h"
13 #include "base/sys_info.h"
14 #include "base/threading/thread_restrictions.h"
15 #include "base/version.h"
16 #include "chrome/common/chrome_constants.h"
17 #include "chrome/common/chrome_paths_internal.h"
18 #include "chrome/common/widevine_cdm_constants.h"
19 #include "ui/base/ui_base_paths.h"
21 #if defined(OS_ANDROID)
22 #include "base/android/path_utils.h"
23 #include "base/base_paths_android.h"
24 #endif
26 #if defined(OS_MACOSX)
27 #include "base/mac/foundation_util.h"
28 #endif
30 #if defined(OS_WIN)
31 #include "base/win/registry.h"
32 #endif
34 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
36 namespace {
38 #if defined(OS_WIN)
39 const wchar_t kFlashRegistryRoot[] = L"SOFTWARE\\Macromedia\\FlashPlayerPepper";
41 const wchar_t kFlashPlayerPathValueName[] = L"PlayerPath";
42 #endif
44 // File name of the internal Flash plugin on different platforms.
45 const base::FilePath::CharType kInternalFlashPluginFileName[] =
46 #if defined(OS_MACOSX)
47 FILE_PATH_LITERAL("Flash Player Plugin for Chrome.plugin");
48 #elif defined(OS_WIN)
49 FILE_PATH_LITERAL("gcswf32.dll");
50 #else // OS_LINUX, etc.
51 FILE_PATH_LITERAL("libgcflashplayer.so");
52 #endif
54 // The Pepper Flash plugins are in a directory with this name.
55 const base::FilePath::CharType kPepperFlashBaseDirectory[] =
56 FILE_PATH_LITERAL("PepperFlash");
58 #if defined(OS_WIN)
59 const base::FilePath::CharType kPepperFlashSystemBaseDirectory[] =
60 FILE_PATH_LITERAL("Macromed\\Flash");
61 #elif defined(OS_MACOSX) && !defined(OS_IOS)
62 const base::FilePath::CharType kPepperFlashSystemBaseDirectory[] =
63 FILE_PATH_LITERAL("Internet Plug-Ins/PepperFlashPlayer");
64 #endif
66 const base::FilePath::CharType kInternalNaClPluginFileName[] =
67 FILE_PATH_LITERAL("internal-nacl-plugin");
69 const base::FilePath::CharType kEffectsPluginFileName[] =
70 #if defined(OS_WIN)
71 FILE_PATH_LITERAL("pepper/libppeffects.dll");
72 #elif defined(OS_MACOSX)
73 FILE_PATH_LITERAL("pepper/libppeffects.plugin");
74 #else // Linux and Chrome OS
75 FILE_PATH_LITERAL("pepper/libppeffects.so");
76 #endif
78 #if defined(OS_POSIX) && !defined(OS_MACOSX)
80 const base::FilePath::CharType kO1DPluginFileName[] =
81 FILE_PATH_LITERAL("pepper/libppo1d.so");
83 const base::FilePath::CharType kGTalkPluginFileName[] =
84 FILE_PATH_LITERAL("pepper/libppgoogletalk.so");
86 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
88 #if defined(OS_LINUX)
89 // The path to the external extension <id>.json files.
90 // /usr/share seems like a good choice, see: http://www.pathname.com/fhs/
91 const base::FilePath::CharType kFilepathSinglePrefExtensions[] =
92 #if defined(GOOGLE_CHROME_BUILD)
93 FILE_PATH_LITERAL("/usr/share/google-chrome/extensions");
94 #else
95 FILE_PATH_LITERAL("/usr/share/chromium/extensions");
96 #endif // defined(GOOGLE_CHROME_BUILD)
97 #endif // defined(OS_LINUX)
99 static base::LazyInstance<base::FilePath>
100 g_invalid_specified_user_data_dir = LAZY_INSTANCE_INITIALIZER;
102 // Gets the path for internal plugins.
103 bool GetInternalPluginsDirectory(base::FilePath* result) {
104 #if defined(OS_MACOSX) && !defined(OS_IOS)
105 // If called from Chrome, get internal plugins from a subdirectory of the
106 // framework.
107 if (base::mac::AmIBundled()) {
108 *result = chrome::GetFrameworkBundlePath();
109 DCHECK(!result->empty());
110 *result = result->Append("Internet Plug-Ins");
111 return true;
113 // In tests, just look in the module directory (below).
114 #endif
116 // The rest of the world expects plugins in the module directory.
117 return PathService::Get(base::DIR_MODULE, result);
120 #if defined(OS_WIN)
121 // Gets the Flash path if installed on the system.
122 bool GetSystemFlashDirectory(base::FilePath* out_path) {
123 base::win::RegKey path_key(HKEY_LOCAL_MACHINE, kFlashRegistryRoot, KEY_READ);
124 base::string16 path_str;
125 if (FAILED(path_key.ReadValue(kFlashPlayerPathValueName, &path_str)))
126 return false;
127 base::FilePath plugin_path = base::FilePath(path_str).DirName();
129 *out_path = plugin_path;
130 return true;
132 #endif
134 } // namespace
136 namespace chrome {
138 bool PathProvider(int key, base::FilePath* result) {
139 // Some keys are just aliases...
140 switch (key) {
141 case chrome::DIR_APP:
142 return PathService::Get(base::DIR_MODULE, result);
143 case chrome::DIR_LOGS:
144 #ifdef NDEBUG
145 // Release builds write to the data dir
146 return PathService::Get(chrome::DIR_USER_DATA, result);
147 #else
148 // Debug builds write next to the binary (in the build tree)
149 #if defined(OS_MACOSX)
150 if (!PathService::Get(base::DIR_EXE, result))
151 return false;
152 if (base::mac::AmIBundled()) {
153 // If we're called from chrome, dump it beside the app (outside the
154 // app bundle), if we're called from a unittest, we'll already
155 // outside the bundle so use the exe dir.
156 // exe_dir gave us .../Chromium.app/Contents/MacOS/Chromium.
157 *result = result->DirName();
158 *result = result->DirName();
159 *result = result->DirName();
161 return true;
162 #else
163 return PathService::Get(base::DIR_EXE, result);
164 #endif // defined(OS_MACOSX)
165 #endif // NDEBUG
166 case chrome::FILE_RESOURCE_MODULE:
167 return PathService::Get(base::FILE_MODULE, result);
170 // Assume that we will not need to create the directory if it does not exist.
171 // This flag can be set to true for the cases where we want to create it.
172 bool create_dir = false;
174 base::FilePath cur;
175 switch (key) {
176 case chrome::DIR_USER_DATA:
177 if (!GetDefaultUserDataDirectory(&cur)) {
178 NOTREACHED();
179 return false;
181 create_dir = true;
182 break;
183 case chrome::DIR_USER_DOCUMENTS:
184 if (!GetUserDocumentsDirectory(&cur))
185 return false;
186 create_dir = true;
187 break;
188 case chrome::DIR_USER_MUSIC:
189 if (!GetUserMusicDirectory(&cur))
190 return false;
191 break;
192 case chrome::DIR_USER_PICTURES:
193 if (!GetUserPicturesDirectory(&cur))
194 return false;
195 break;
196 case chrome::DIR_USER_VIDEOS:
197 if (!GetUserVideosDirectory(&cur))
198 return false;
199 break;
200 case chrome::DIR_DEFAULT_DOWNLOADS_SAFE:
201 #if defined(OS_WIN) || defined(OS_LINUX)
202 if (!GetUserDownloadsDirectorySafe(&cur))
203 return false;
204 break;
205 #else
206 // Fall through for all other platforms.
207 #endif
208 case chrome::DIR_DEFAULT_DOWNLOADS:
209 #if defined(OS_ANDROID)
210 if (!base::android::GetDownloadsDirectory(&cur))
211 return false;
212 #else
213 if (!GetUserDownloadsDirectory(&cur))
214 return false;
215 // Do not create the download directory here, we have done it twice now
216 // and annoyed a lot of users.
217 #endif
218 break;
219 case chrome::DIR_CRASH_DUMPS:
220 #if defined(OS_CHROMEOS)
221 // ChromeOS uses a separate directory. See http://crosbug.com/25089
222 cur = base::FilePath("/var/log/chrome");
223 #elif defined(OS_ANDROID)
224 if (!base::android::GetCacheDirectory(&cur))
225 return false;
226 #else
227 // The crash reports are always stored relative to the default user data
228 // directory. This avoids the problem of having to re-initialize the
229 // exception handler after parsing command line options, which may
230 // override the location of the app's profile directory.
231 if (!GetDefaultUserDataDirectory(&cur))
232 return false;
233 #endif
234 #if defined(OS_MACOSX)
235 cur = cur.Append(FILE_PATH_LITERAL("Crashpad"));
236 #else
237 cur = cur.Append(FILE_PATH_LITERAL("Crash Reports"));
238 #endif
239 create_dir = true;
240 break;
241 #if defined(OS_WIN)
242 case chrome::DIR_WATCHER_DATA:
243 // The watcher data is always stored relative to the default user data
244 // directory. This allows the watcher to be initialized before
245 // command-line options have been parsed.
246 if (!GetDefaultUserDataDirectory(&cur))
247 return false;
248 cur = cur.Append(FILE_PATH_LITERAL("Diagnostics"));
249 break;
250 #endif
251 case chrome::DIR_RESOURCES:
252 #if defined(OS_MACOSX)
253 cur = base::mac::FrameworkBundlePath();
254 cur = cur.Append(FILE_PATH_LITERAL("Resources"));
255 #else
256 if (!PathService::Get(chrome::DIR_APP, &cur))
257 return false;
258 cur = cur.Append(FILE_PATH_LITERAL("resources"));
259 #endif
260 break;
261 case chrome::DIR_INSPECTOR:
262 if (!PathService::Get(chrome::DIR_RESOURCES, &cur))
263 return false;
264 cur = cur.Append(FILE_PATH_LITERAL("inspector"));
265 break;
266 case chrome::DIR_APP_DICTIONARIES:
267 #if defined(OS_POSIX)
268 // We can't write into the EXE dir on Linux, so keep dictionaries
269 // alongside the safe browsing database in the user data dir.
270 // And we don't want to write into the bundle on the Mac, so push
271 // it to the user data dir there also.
272 if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
273 return false;
274 #else
275 if (!PathService::Get(base::DIR_EXE, &cur))
276 return false;
277 #endif
278 cur = cur.Append(FILE_PATH_LITERAL("Dictionaries"));
279 create_dir = true;
280 break;
281 case chrome::DIR_INTERNAL_PLUGINS:
282 if (!GetInternalPluginsDirectory(&cur))
283 return false;
284 break;
285 case chrome::DIR_PEPPER_FLASH_PLUGIN:
286 if (!GetInternalPluginsDirectory(&cur))
287 return false;
288 cur = cur.Append(kPepperFlashBaseDirectory);
289 break;
290 case chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN:
291 if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
292 return false;
293 cur = cur.Append(kPepperFlashBaseDirectory);
294 break;
295 case chrome::DIR_PEPPER_FLASH_SYSTEM_PLUGIN:
296 #if defined(OS_WIN)
297 if (!GetSystemFlashDirectory(&cur))
298 return false;
299 #elif defined(OS_MACOSX) && !defined(OS_IOS)
300 if (!GetLocalLibraryDirectory(&cur))
301 return false;
302 cur = cur.Append(kPepperFlashSystemBaseDirectory);
303 #else
304 // Chrome on iOS does not supports PPAPI binaries, return false.
305 // TODO(wfh): If Adobe release PPAPI binaries for Linux, add support here.
306 return false;
307 #endif
308 break;
309 case chrome::FILE_LOCAL_STATE:
310 if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
311 return false;
312 cur = cur.Append(chrome::kLocalStateFilename);
313 break;
314 case chrome::FILE_RECORDED_SCRIPT:
315 if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
316 return false;
317 cur = cur.Append(FILE_PATH_LITERAL("script.log"));
318 break;
319 case chrome::FILE_FLASH_PLUGIN:
320 if (!GetInternalPluginsDirectory(&cur))
321 return false;
322 cur = cur.Append(kInternalFlashPluginFileName);
323 break;
324 case chrome::FILE_PEPPER_FLASH_PLUGIN:
325 if (!PathService::Get(chrome::DIR_PEPPER_FLASH_PLUGIN, &cur))
326 return false;
327 cur = cur.Append(chrome::kPepperFlashPluginFilename);
328 break;
329 case chrome::FILE_EFFECTS_PLUGIN:
330 if (!GetInternalPluginsDirectory(&cur))
331 return false;
332 cur = cur.Append(kEffectsPluginFileName);
333 break;
334 // TODO(teravest): Remove this case once the internal NaCl plugin is gone.
335 // We currently need a path here to look up whether the plugin is disabled
336 // and what its permissions are.
337 case chrome::FILE_NACL_PLUGIN:
338 if (!GetInternalPluginsDirectory(&cur))
339 return false;
340 cur = cur.Append(kInternalNaClPluginFileName);
341 break;
342 // PNaCl is currenly installable via the component updater or by being
343 // simply built-in. DIR_PNACL_BASE is used as the base directory for
344 // installation via component updater. DIR_PNACL_COMPONENT will be
345 // the final location of pnacl, which is a subdir of DIR_PNACL_BASE.
346 case chrome::DIR_PNACL_BASE:
347 if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
348 return false;
349 cur = cur.Append(FILE_PATH_LITERAL("pnacl"));
350 break;
351 // Where PNaCl files are ultimately located. The default finds the files
352 // inside the InternalPluginsDirectory / build directory, as if it
353 // was shipped along with chrome. The value can be overridden
354 // if it is installed via component updater.
355 case chrome::DIR_PNACL_COMPONENT:
356 #if defined(OS_MACOSX)
357 // PNaCl really belongs in the InternalPluginsDirectory but actually
358 // copying it there would result in the files also being shipped, which
359 // we don't want yet. So for now, just find them in the directory where
360 // they get built.
361 if (!PathService::Get(base::DIR_EXE, &cur))
362 return false;
363 if (base::mac::AmIBundled()) {
364 // If we're called from chrome, it's beside the app (outside the
365 // app bundle), if we're called from a unittest, we'll already be
366 // outside the bundle so use the exe dir.
367 // exe_dir gave us .../Chromium.app/Contents/MacOS/Chromium.
368 cur = cur.DirName();
369 cur = cur.DirName();
370 cur = cur.DirName();
372 #else
373 if (!GetInternalPluginsDirectory(&cur))
374 return false;
375 #endif
376 cur = cur.Append(FILE_PATH_LITERAL("pnacl"));
377 break;
378 #if defined(OS_POSIX) && !defined(OS_MACOSX)
379 case chrome::FILE_O1D_PLUGIN:
380 if (!PathService::Get(base::DIR_MODULE, &cur))
381 return false;
382 cur = cur.Append(kO1DPluginFileName);
383 break;
384 case chrome::FILE_GTALK_PLUGIN:
385 if (!PathService::Get(base::DIR_MODULE, &cur))
386 return false;
387 cur = cur.Append(kGTalkPluginFileName);
388 break;
389 #endif
390 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS)
391 #if defined(WIDEVINE_CDM_IS_COMPONENT)
392 case chrome::DIR_COMPONENT_WIDEVINE_CDM:
393 if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
394 return false;
395 cur = cur.Append(kWidevineCdmBaseDirectory);
396 break;
397 #endif // defined(WIDEVINE_CDM_IS_COMPONENT)
398 // TODO(xhwang): FILE_WIDEVINE_CDM_ADAPTER has different meanings.
399 // In the component case, this is the source adapter. Otherwise, it is the
400 // actual Pepper module that gets loaded.
401 case chrome::FILE_WIDEVINE_CDM_ADAPTER:
402 if (!GetInternalPluginsDirectory(&cur))
403 return false;
404 cur = cur.AppendASCII(kWidevineCdmAdapterFileName);
405 break;
406 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS)
407 case chrome::FILE_RESOURCES_PACK:
408 #if defined(OS_MACOSX) && !defined(OS_IOS)
409 if (base::mac::AmIBundled()) {
410 cur = base::mac::FrameworkBundlePath();
411 cur = cur.Append(FILE_PATH_LITERAL("Resources"))
412 .Append(FILE_PATH_LITERAL("resources.pak"));
413 break;
415 #elif defined(OS_ANDROID)
416 if (!PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &cur))
417 return false;
418 #else
419 // If we're not bundled on mac or Android, resources.pak should be next
420 // to the binary (e.g., for unit tests).
421 if (!PathService::Get(base::DIR_MODULE, &cur))
422 return false;
423 #endif
424 cur = cur.Append(FILE_PATH_LITERAL("resources.pak"));
425 break;
426 case chrome::DIR_RESOURCES_EXTENSION:
427 if (!PathService::Get(base::DIR_MODULE, &cur))
428 return false;
429 cur = cur.Append(FILE_PATH_LITERAL("resources"))
430 .Append(FILE_PATH_LITERAL("extension"));
431 break;
432 #if defined(OS_CHROMEOS)
433 case chrome::DIR_CHROMEOS_WALLPAPERS:
434 if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
435 return false;
436 cur = cur.Append(FILE_PATH_LITERAL("wallpapers"));
437 break;
438 case chrome::DIR_CHROMEOS_WALLPAPER_THUMBNAILS:
439 if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
440 return false;
441 cur = cur.Append(FILE_PATH_LITERAL("wallpaper_thumbnails"));
442 break;
443 case chrome::DIR_CHROMEOS_CUSTOM_WALLPAPERS:
444 if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
445 return false;
446 cur = cur.Append(FILE_PATH_LITERAL("custom_wallpapers"));
447 break;
448 #endif
449 #if defined(OS_LINUX) && defined(ENABLE_SUPERVISED_USERS)
450 case chrome::DIR_SUPERVISED_USERS_DEFAULT_APPS:
451 if (!PathService::Get(chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS, &cur))
452 return false;
453 cur = cur.Append(FILE_PATH_LITERAL("managed_users"));
454 break;
455 #endif
456 // The following are only valid in the development environment, and
457 // will fail if executed from an installed executable (because the
458 // generated path won't exist).
459 case chrome::DIR_GEN_TEST_DATA:
460 #if defined(OS_ANDROID)
461 // On Android, our tests don't have permission to write to DIR_MODULE.
462 // gtest/test_runner.py pushes data to external storage.
463 if (!PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, &cur))
464 return false;
465 #else
466 if (!PathService::Get(base::DIR_MODULE, &cur))
467 return false;
468 #endif
469 cur = cur.Append(FILE_PATH_LITERAL("test_data"));
470 if (!base::PathExists(cur)) // We don't want to create this.
471 return false;
472 break;
473 case chrome::DIR_TEST_DATA:
474 if (!PathService::Get(base::DIR_SOURCE_ROOT, &cur))
475 return false;
476 cur = cur.Append(FILE_PATH_LITERAL("chrome"));
477 cur = cur.Append(FILE_PATH_LITERAL("test"));
478 cur = cur.Append(FILE_PATH_LITERAL("data"));
479 if (!base::PathExists(cur)) // We don't want to create this.
480 return false;
481 break;
482 case chrome::DIR_TEST_TOOLS:
483 if (!PathService::Get(base::DIR_SOURCE_ROOT, &cur))
484 return false;
485 cur = cur.Append(FILE_PATH_LITERAL("chrome"));
486 cur = cur.Append(FILE_PATH_LITERAL("tools"));
487 cur = cur.Append(FILE_PATH_LITERAL("test"));
488 if (!base::PathExists(cur)) // We don't want to create this
489 return false;
490 break;
491 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD)
492 case chrome::DIR_POLICY_FILES: {
493 #if defined(GOOGLE_CHROME_BUILD)
494 cur = base::FilePath(FILE_PATH_LITERAL("/etc/opt/chrome/policies"));
495 #else
496 cur = base::FilePath(FILE_PATH_LITERAL("/etc/chromium/policies"));
497 #endif
498 break;
500 #endif
501 #if defined(OS_MACOSX) && !defined(OS_IOS)
502 case chrome::DIR_USER_LIBRARY: {
503 if (!GetUserLibraryDirectory(&cur))
504 return false;
505 if (!base::PathExists(cur)) // We don't want to create this.
506 return false;
507 break;
509 case chrome::DIR_USER_APPLICATIONS: {
510 if (!GetUserApplicationsDirectory(&cur))
511 return false;
512 if (!base::PathExists(cur)) // We don't want to create this.
513 return false;
514 break;
516 #endif
517 #if defined(OS_CHROMEOS) || (defined(OS_MACOSX) && !defined(OS_IOS))
518 case chrome::DIR_USER_EXTERNAL_EXTENSIONS: {
519 if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
520 return false;
521 cur = cur.Append(FILE_PATH_LITERAL("External Extensions"));
522 break;
524 #endif
525 #if defined(OS_LINUX)
526 case chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS: {
527 cur = base::FilePath(kFilepathSinglePrefExtensions);
528 break;
530 #endif
531 case chrome::DIR_EXTERNAL_EXTENSIONS:
532 #if defined(OS_MACOSX) && !defined(OS_IOS)
533 if (!chrome::GetGlobalApplicationSupportDirectory(&cur))
534 return false;
536 cur = cur.Append(FILE_PATH_LITERAL("Google"))
537 .Append(FILE_PATH_LITERAL("Chrome"))
538 .Append(FILE_PATH_LITERAL("External Extensions"));
539 create_dir = false;
540 #else
541 if (!PathService::Get(base::DIR_MODULE, &cur))
542 return false;
544 cur = cur.Append(FILE_PATH_LITERAL("extensions"));
545 create_dir = true;
546 #endif
547 break;
549 case chrome::DIR_DEFAULT_APPS:
550 #if defined(OS_MACOSX)
551 cur = base::mac::FrameworkBundlePath();
552 cur = cur.Append(FILE_PATH_LITERAL("Default Apps"));
553 #else
554 if (!PathService::Get(chrome::DIR_APP, &cur))
555 return false;
556 cur = cur.Append(FILE_PATH_LITERAL("default_apps"));
557 #endif
558 break;
560 #if defined(OS_LINUX) || (defined(OS_MACOSX) && !defined(OS_IOS))
561 case chrome::DIR_NATIVE_MESSAGING:
562 #if defined(OS_MACOSX)
563 #if defined(GOOGLE_CHROME_BUILD)
564 cur = base::FilePath(FILE_PATH_LITERAL(
565 "/Library/Google/Chrome/NativeMessagingHosts"));
566 #else
567 cur = base::FilePath(FILE_PATH_LITERAL(
568 "/Library/Application Support/Chromium/NativeMessagingHosts"));
569 #endif
570 #else // defined(OS_MACOSX)
571 #if defined(GOOGLE_CHROME_BUILD)
572 cur = base::FilePath(FILE_PATH_LITERAL(
573 "/etc/opt/chrome/native-messaging-hosts"));
574 #else
575 cur = base::FilePath(FILE_PATH_LITERAL(
576 "/etc/chromium/native-messaging-hosts"));
577 #endif
578 #endif // !defined(OS_MACOSX)
579 break;
581 case chrome::DIR_USER_NATIVE_MESSAGING:
582 if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
583 return false;
584 cur = cur.Append(FILE_PATH_LITERAL("NativeMessagingHosts"));
585 break;
586 #endif // defined(OS_LINUX) || (defined(OS_MACOSX) && !defined(OS_IOS))
587 #if !defined(OS_ANDROID)
588 case chrome::DIR_GLOBAL_GCM_STORE:
589 if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
590 return false;
591 cur = cur.Append(kGCMStoreDirname);
592 break;
593 #endif // !defined(OS_ANDROID)
595 default:
596 return false;
599 // TODO(bauerb): http://crbug.com/259796
600 base::ThreadRestrictions::ScopedAllowIO allow_io;
601 if (create_dir && !base::PathExists(cur) &&
602 !base::CreateDirectory(cur))
603 return false;
605 *result = cur;
606 return true;
609 // This cannot be done as a static initializer sadly since Visual Studio will
610 // eliminate this object file if there is no direct entry point into it.
611 void RegisterPathProvider() {
612 PathService::RegisterProvider(PathProvider, PATH_START, PATH_END);
615 void SetInvalidSpecifiedUserDataDir(const base::FilePath& user_data_dir) {
616 g_invalid_specified_user_data_dir.Get() = user_data_dir;
619 const base::FilePath& GetInvalidSpecifiedUserDataDir() {
620 return g_invalid_specified_user_data_dir.Get();
623 } // namespace chrome