From 964e1d6bb6f53dc535e05ef67eeef4bf2eafc3a9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 18 Jan 2015 16:42:32 -0800 Subject: [PATCH] Override DIR_APP_DATA on Linux --- brightray/browser/browser_context.cc | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 05f127755c1..7a9b56c0525 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -27,6 +27,23 @@ using content::BrowserThread; namespace brightray { +namespace { + +#if defined(OS_LINUX) +void OverrideLinuxAppDataPath() { + base::FilePath path; + if (PathService::Get(base::DIR_APP_DATA, &path)) + return; + scoped_ptr env(base::Environment::Create()); + path = base::nix::GetXDGDirectory(env.get(), + base::nix::kXdgConfigHomeEnvVar, + base::nix::kDotConfigDir); + PathService::Override(base::DIR_APP_DATA, path); +} +#endif + +} // namespace + class BrowserContext::ResourceContext : public content::ResourceContext { public: ResourceContext() : getter_(nullptr) {} @@ -51,16 +68,12 @@ BrowserContext::BrowserContext() : resource_context_(new ResourceContext) { } void BrowserContext::Initialize() { - base::FilePath path; #if defined(OS_LINUX) - scoped_ptr env(base::Environment::Create()); - path = base::nix::GetXDGDirectory(env.get(), - base::nix::kXdgConfigHomeEnvVar, - base::nix::kDotConfigDir); -#else - CHECK(PathService::Get(base::DIR_APP_DATA, &path)); + OverrideLinuxAppDataPath(); #endif + base::FilePath path; + PathService::Get(base::DIR_APP_DATA, &path); path_ = path.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); auto prefs_path = GetPath().Append(FILE_PATH_LITERAL("Preferences"));