This source file includes following definitions.
- GetInternalPluginsDirectory
- PathProvider
- RegisterPathProvider
- SetInvalidSpecifiedUserDataDir
- GetInvalidSpecifiedUserDataDir
#include "chrome/common/chrome_paths.h"
#include "base/file_util.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/mac/bundle_locations.h"
#include "base/path_service.h"
#include "base/strings/string_util.h"
#include "base/sys_info.h"
#include "base/threading/thread_restrictions.h"
#include "base/version.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths_internal.h"
#include "chrome/common/widevine_cdm_constants.h"
#include "ui/base/ui_base_paths.h"
#if defined(OS_ANDROID)
#include "base/android/path_utils.h"
#endif
#if defined(OS_MACOSX)
#include "base/mac/foundation_util.h"
#endif
#include "widevine_cdm_version.h"
namespace {
const base::FilePath::CharType kInternalFlashPluginFileName[] =
#if defined(OS_MACOSX)
FILE_PATH_LITERAL("Flash Player Plugin for Chrome.plugin");
#elif defined(OS_WIN)
FILE_PATH_LITERAL("gcswf32.dll");
#else
FILE_PATH_LITERAL("libgcflashplayer.so");
#endif
const base::FilePath::CharType kPepperFlashBaseDirectory[] =
FILE_PATH_LITERAL("PepperFlash");
const base::FilePath::CharType kInternalPDFPluginFileName[] =
#if defined(OS_WIN)
FILE_PATH_LITERAL("pdf.dll");
#elif defined(OS_MACOSX)
FILE_PATH_LITERAL("PDF.plugin");
#else
FILE_PATH_LITERAL("libpdf.so");
#endif
const base::FilePath::CharType kInternalNaClPluginFileName[] =
#if defined(OS_WIN)
FILE_PATH_LITERAL("ppGoogleNaClPluginChrome.dll");
#elif defined(OS_MACOSX)
FILE_PATH_LITERAL("ppGoogleNaClPluginChrome.plugin");
#else
FILE_PATH_LITERAL("libppGoogleNaClPluginChrome.so");
#endif
const base::FilePath::CharType kEffectsPluginFileName[] =
#if defined(OS_WIN)
FILE_PATH_LITERAL("pepper/libppeffects.dll");
#elif defined(OS_MACOSX)
FILE_PATH_LITERAL("pepper/libppeffects.plugin");
#else
FILE_PATH_LITERAL("pepper/libppeffects.so");
#endif
#if defined(OS_POSIX) && !defined(OS_MACOSX)
const base::FilePath::CharType kO1DPluginFileName[] =
FILE_PATH_LITERAL("pepper/libppo1d.so");
const base::FilePath::CharType kGTalkPluginFileName[] =
FILE_PATH_LITERAL("pepper/libppgoogletalk.so");
#endif
#if defined(OS_LINUX)
const base::FilePath::CharType kFilepathSinglePrefExtensions[] =
#if defined(GOOGLE_CHROME_BUILD)
FILE_PATH_LITERAL("/usr/share/google-chrome/extensions");
#else
FILE_PATH_LITERAL("/usr/share/chromium/extensions");
#endif
#endif
static base::LazyInstance<base::FilePath>
g_invalid_specified_user_data_dir = LAZY_INSTANCE_INITIALIZER;
bool GetInternalPluginsDirectory(base::FilePath* result) {
#if defined(OS_MACOSX) && !defined(OS_IOS)
if (base::mac::AmIBundled()) {
*result = chrome::GetFrameworkBundlePath();
DCHECK(!result->empty());
*result = result->Append("Internet Plug-Ins");
return true;
}
#endif
return PathService::Get(base::DIR_MODULE, result);
}
}
namespace chrome {
bool PathProvider(int key, base::FilePath* result) {
switch (key) {
case chrome::DIR_APP:
return PathService::Get(base::DIR_MODULE, result);
case chrome::DIR_LOGS:
#ifdef NDEBUG
return PathService::Get(chrome::DIR_USER_DATA, result);
#else
#if defined(OS_MACOSX)
if (!PathService::Get(base::DIR_EXE, result))
return false;
if (base::mac::AmIBundled()) {
*result = result->DirName();
*result = result->DirName();
*result = result->DirName();
}
return true;
#else
return PathService::Get(base::DIR_EXE, result);
#endif
#endif
case chrome::FILE_RESOURCE_MODULE:
return PathService::Get(base::FILE_MODULE, result);
}
bool create_dir = false;
base::FilePath cur;
switch (key) {
case chrome::DIR_USER_DATA:
if (!GetDefaultUserDataDirectory(&cur)) {
NOTREACHED();
return false;
}
create_dir = true;
break;
case chrome::DIR_USER_DOCUMENTS:
if (!GetUserDocumentsDirectory(&cur))
return false;
create_dir = true;
break;
case chrome::DIR_USER_MUSIC:
if (!GetUserMusicDirectory(&cur))
return false;
break;
case chrome::DIR_USER_PICTURES:
if (!GetUserPicturesDirectory(&cur))
return false;
break;
case chrome::DIR_USER_VIDEOS:
if (!GetUserVideosDirectory(&cur))
return false;
break;
case chrome::DIR_DEFAULT_DOWNLOADS_SAFE:
#if defined(OS_WIN) || defined(OS_LINUX)
if (!GetUserDownloadsDirectorySafe(&cur))
return false;
break;
#else
#endif
case chrome::DIR_DEFAULT_DOWNLOADS:
#if defined(OS_ANDROID)
if (!base::android::GetDownloadsDirectory(&cur))
return false;
#else
if (!GetUserDownloadsDirectory(&cur))
return false;
#endif
break;
case chrome::DIR_CRASH_DUMPS:
#if defined(OS_CHROMEOS)
cur = base::FilePath("/var/log/chrome");
#elif defined(OS_ANDROID)
if (!base::android::GetCacheDirectory(&cur))
return false;
#else
if (!GetDefaultUserDataDirectory(&cur))
return false;
#endif
cur = cur.Append(FILE_PATH_LITERAL("Crash Reports"));
create_dir = true;
break;
case chrome::DIR_RESOURCES:
#if defined(OS_MACOSX)
cur = base::mac::FrameworkBundlePath();
cur = cur.Append(FILE_PATH_LITERAL("Resources"));
#else
if (!PathService::Get(chrome::DIR_APP, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("resources"));
#endif
break;
case chrome::DIR_INSPECTOR:
if (!PathService::Get(chrome::DIR_RESOURCES, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("inspector"));
break;
case chrome::DIR_APP_DICTIONARIES:
#if defined(OS_POSIX)
if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
return false;
#else
if (!PathService::Get(base::DIR_EXE, &cur))
return false;
#endif
cur = cur.Append(FILE_PATH_LITERAL("Dictionaries"));
create_dir = true;
break;
case chrome::DIR_INTERNAL_PLUGINS:
if (!GetInternalPluginsDirectory(&cur))
return false;
break;
case chrome::DIR_PEPPER_FLASH_PLUGIN:
if (!GetInternalPluginsDirectory(&cur))
return false;
cur = cur.Append(kPepperFlashBaseDirectory);
break;
case chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN:
if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
return false;
cur = cur.Append(kPepperFlashBaseDirectory);
break;
case chrome::FILE_LOCAL_STATE:
if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
return false;
cur = cur.Append(chrome::kLocalStateFilename);
break;
case chrome::FILE_RECORDED_SCRIPT:
if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("script.log"));
break;
case chrome::FILE_FLASH_PLUGIN:
if (!GetInternalPluginsDirectory(&cur))
return false;
cur = cur.Append(kInternalFlashPluginFileName);
break;
case chrome::FILE_PEPPER_FLASH_PLUGIN:
if (!PathService::Get(chrome::DIR_PEPPER_FLASH_PLUGIN, &cur))
return false;
cur = cur.Append(chrome::kPepperFlashPluginFilename);
break;
case chrome::FILE_PDF_PLUGIN:
if (!GetInternalPluginsDirectory(&cur))
return false;
cur = cur.Append(kInternalPDFPluginFileName);
break;
case chrome::FILE_EFFECTS_PLUGIN:
if (!GetInternalPluginsDirectory(&cur))
return false;
cur = cur.Append(kEffectsPluginFileName);
break;
case chrome::FILE_NACL_PLUGIN:
if (!GetInternalPluginsDirectory(&cur))
return false;
cur = cur.Append(kInternalNaClPluginFileName);
break;
case chrome::DIR_PNACL_BASE:
if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("pnacl"));
break;
case chrome::DIR_PNACL_COMPONENT:
#if defined(OS_MACOSX)
if (!PathService::Get(base::DIR_EXE, &cur))
return false;
if (base::mac::AmIBundled()) {
cur = cur.DirName();
cur = cur.DirName();
cur = cur.DirName();
}
#else
if (!GetInternalPluginsDirectory(&cur))
return false;
#endif
cur = cur.Append(FILE_PATH_LITERAL("pnacl"));
break;
#if defined(OS_POSIX) && !defined(OS_MACOSX)
case chrome::FILE_O1D_PLUGIN:
if (!PathService::Get(base::DIR_MODULE, &cur))
return false;
cur = cur.Append(kO1DPluginFileName);
break;
case chrome::FILE_GTALK_PLUGIN:
if (!PathService::Get(base::DIR_MODULE, &cur))
return false;
cur = cur.Append(kGTalkPluginFileName);
break;
#endif
#if defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS)
#if defined(WIDEVINE_CDM_IS_COMPONENT)
case chrome::DIR_COMPONENT_WIDEVINE_CDM:
if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
return false;
cur = cur.Append(kWidevineCdmBaseDirectory);
break;
#endif
case chrome::FILE_WIDEVINE_CDM_ADAPTER:
if (!GetInternalPluginsDirectory(&cur))
return false;
cur = cur.AppendASCII(kWidevineCdmAdapterFileName);
break;
#endif
case chrome::FILE_RESOURCES_PACK:
#if defined(OS_MACOSX) && !defined(OS_IOS)
if (base::mac::AmIBundled()) {
cur = base::mac::FrameworkBundlePath();
cur = cur.Append(FILE_PATH_LITERAL("Resources"))
.Append(FILE_PATH_LITERAL("resources.pak"));
break;
}
#elif defined(OS_ANDROID)
if (!PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &cur))
return false;
#else
if (!PathService::Get(base::DIR_MODULE, &cur))
return false;
#endif
cur = cur.Append(FILE_PATH_LITERAL("resources.pak"));
break;
case chrome::DIR_RESOURCES_EXTENSION:
if (!PathService::Get(base::DIR_MODULE, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("resources"))
.Append(FILE_PATH_LITERAL("extension"));
break;
#if defined(OS_CHROMEOS)
case chrome::DIR_CHROMEOS_WALLPAPERS:
if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("wallpapers"));
break;
case chrome::DIR_CHROMEOS_WALLPAPER_THUMBNAILS:
if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("wallpaper_thumbnails"));
break;
case chrome::DIR_CHROMEOS_CUSTOM_WALLPAPERS:
if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("custom_wallpapers"));
break;
#endif
#if defined(OS_LINUX) && defined(ENABLE_MANAGED_USERS)
case chrome::DIR_MANAGED_USERS_DEFAULT_APPS:
if (!PathService::Get(chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("managed_users"));
break;
#endif
case chrome::DIR_GEN_TEST_DATA:
if (!PathService::Get(base::DIR_MODULE, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("test_data"));
if (!base::PathExists(cur))
return false;
break;
case chrome::DIR_TEST_DATA:
if (!PathService::Get(base::DIR_SOURCE_ROOT, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("chrome"));
cur = cur.Append(FILE_PATH_LITERAL("test"));
cur = cur.Append(FILE_PATH_LITERAL("data"));
if (!base::PathExists(cur))
return false;
break;
case chrome::DIR_TEST_TOOLS:
if (!PathService::Get(base::DIR_SOURCE_ROOT, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("chrome"));
cur = cur.Append(FILE_PATH_LITERAL("tools"));
cur = cur.Append(FILE_PATH_LITERAL("test"));
if (!base::PathExists(cur))
return false;
break;
#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD)
case chrome::DIR_POLICY_FILES: {
#if defined(GOOGLE_CHROME_BUILD)
cur = base::FilePath(FILE_PATH_LITERAL("/etc/opt/chrome/policies"));
#else
cur = base::FilePath(FILE_PATH_LITERAL("/etc/chromium/policies"));
#endif
break;
}
#endif
#if defined(OS_MACOSX) && !defined(OS_IOS)
case chrome::DIR_MANAGED_PREFS: {
if (!GetLocalLibraryDirectory(&cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("Managed Preferences"));
char* login = getlogin();
if (!login)
return false;
cur = cur.AppendASCII(login);
if (!base::PathExists(cur))
return false;
break;
}
case chrome::DIR_USER_LIBRARY: {
if (!GetUserLibraryDirectory(&cur))
return false;
if (!base::PathExists(cur))
return false;
break;
}
case chrome::DIR_USER_APPLICATIONS: {
if (!GetUserApplicationsDirectory(&cur))
return false;
if (!base::PathExists(cur))
return false;
break;
}
#endif
#if defined(OS_CHROMEOS) || (defined(OS_MACOSX) && !defined(OS_IOS))
case chrome::DIR_USER_EXTERNAL_EXTENSIONS: {
if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("External Extensions"));
break;
}
#endif
#if defined(OS_LINUX)
case chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS: {
cur = base::FilePath(kFilepathSinglePrefExtensions);
break;
}
#endif
case chrome::DIR_EXTERNAL_EXTENSIONS:
#if defined(OS_MACOSX) && !defined(OS_IOS)
if (!chrome::GetGlobalApplicationSupportDirectory(&cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("Google"))
.Append(FILE_PATH_LITERAL("Chrome"))
.Append(FILE_PATH_LITERAL("External Extensions"));
create_dir = false;
#else
if (!PathService::Get(base::DIR_MODULE, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("extensions"));
create_dir = true;
#endif
break;
case chrome::DIR_DEFAULT_APPS:
#if defined(OS_MACOSX)
cur = base::mac::FrameworkBundlePath();
cur = cur.Append(FILE_PATH_LITERAL("Default Apps"));
#else
if (!PathService::Get(chrome::DIR_APP, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("default_apps"));
#endif
break;
#if defined(OS_LINUX) || (defined(OS_MACOSX) && !defined(OS_IOS))
case chrome::DIR_NATIVE_MESSAGING:
#if defined(OS_MACOSX)
#if defined(GOOGLE_CHROME_BUILD)
cur = base::FilePath(FILE_PATH_LITERAL(
"/Library/Google/Chrome/NativeMessagingHosts"));
#else
cur = base::FilePath(FILE_PATH_LITERAL(
"/Library/Application Support/Chromium/NativeMessagingHosts"));
#endif
#else
#if defined(GOOGLE_CHROME_BUILD)
cur = base::FilePath(FILE_PATH_LITERAL(
"/etc/opt/chrome/native-messaging-hosts"));
#else
cur = base::FilePath(FILE_PATH_LITERAL(
"/etc/chromium/native-messaging-hosts"));
#endif
#endif
break;
case chrome::DIR_USER_NATIVE_MESSAGING:
if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("NativeMessagingHosts"));
break;
#endif
default:
return false;
}
base::ThreadRestrictions::ScopedAllowIO allow_io;
if (create_dir && !base::PathExists(cur) &&
!base::CreateDirectory(cur))
return false;
*result = cur;
return true;
}
void RegisterPathProvider() {
PathService::RegisterProvider(PathProvider, PATH_START, PATH_END);
}
void SetInvalidSpecifiedUserDataDir(const base::FilePath& user_data_dir) {
g_invalid_specified_user_data_dir.Get() = user_data_dir;
}
const base::FilePath& GetInvalidSpecifiedUserDataDir() {
return g_invalid_specified_user_data_dir.Get();
}
}