Merge pull request #89 from brightray/user-data-path

Use PathService to set and get DIR_USER_DATA
This commit is contained in:
Cheng Zhao 2015-01-18 18:03:56 -08:00
commit dc4ccfcbdc
4 changed files with 67 additions and 19 deletions

View file

@ -30,6 +30,7 @@
], ],
}, },
'sources': [ 'sources': [
'browser/brightray_paths.h',
'browser/browser_client.cc', 'browser/browser_client.cc',
'browser/browser_client.h', 'browser/browser_client.h',
'browser/browser_context.cc', 'browser/browser_context.cc',

View file

@ -0,0 +1,34 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BROWSER_BRIGHTRAY_PATHS_H_
#define BROWSER_BRIGHTRAY_PATHS_H_
#include "base/compiler_specific.h"
#if defined(OS_WIN)
#include "base/base_paths_win.h"
#elif defined(OS_MACOSX)
#include "base/base_paths_mac.h"
#endif
namespace brightray {
enum {
PATH_START = 1000,
DIR_USER_DATA = PATH_START, // Directory where user data can be written.
#if defined(OS_LINUX)
DIR_APP_DATA, // Application Data directory under the user profile.
#else
DIR_APP_DATA = base::DIR_APP_DATA,
#endif
PATH_END
};
} // namespace brightray
#endif // BROWSER_BRIGHTRAY_PATHS_H_

View file

@ -4,11 +4,11 @@
#include "browser/browser_context.h" #include "browser/browser_context.h"
#include "browser/brightray_paths.h"
#include "browser/inspectable_web_contents_impl.h" #include "browser/inspectable_web_contents_impl.h"
#include "browser/network_delegate.h" #include "browser/network_delegate.h"
#include "common/application_info.h" #include "common/application_info.h"
#include "base/environment.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/prefs/json_pref_store.h" #include "base/prefs/json_pref_store.h"
@ -19,10 +19,6 @@
#include "content/public/browser/resource_context.h" #include "content/public/browser/resource_context.h"
#include "content/public/browser/storage_partition.h" #include "content/public/browser/storage_partition.h"
#if defined(OS_LINUX)
#include "base/nix/xdg_util.h"
#endif
using content::BrowserThread; using content::BrowserThread;
namespace brightray { namespace brightray {
@ -51,17 +47,11 @@ BrowserContext::BrowserContext() : resource_context_(new ResourceContext) {
} }
void BrowserContext::Initialize() { void BrowserContext::Initialize() {
base::FilePath path; if (!PathService::Get(DIR_USER_DATA, &path_)) {
#if defined(OS_LINUX) PathService::Get(DIR_APP_DATA, &path_);
scoped_ptr<base::Environment> env(base::Environment::Create()); path_ = path_.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName()));
path = base::nix::GetXDGDirectory(env.get(), PathService::Override(DIR_USER_DATA, path_);
base::nix::kXdgConfigHomeEnvVar, }
base::nix::kDotConfigDir);
#else
CHECK(PathService::Get(base::DIR_APP_DATA, &path));
#endif
path_ = path.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName()));
auto prefs_path = GetPath().Append(FILE_PATH_LITERAL("Preferences")); auto prefs_path = GetPath().Append(FILE_PATH_LITERAL("Preferences"));
base::PrefServiceFactory prefs_factory; base::PrefServiceFactory prefs_factory;

View file

@ -26,6 +26,13 @@
#include "browser/views/views_delegate.h" #include "browser/views/views_delegate.h"
#endif #endif
#if defined(OS_LINUX)
#include "base/environment.h"
#include "base/path_service.h"
#include "base/nix/xdg_util.h"
#include "browser/brightray_paths.h"
#endif
#if defined(OS_WIN) #if defined(OS_WIN)
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/l10n_util_win.h" #include "ui/base/l10n/l10n_util_win.h"
@ -34,9 +41,9 @@
namespace brightray { namespace brightray {
#if defined(OS_WIN)
namespace { namespace {
#if defined(OS_WIN)
// gfx::Font callbacks // gfx::Font callbacks
void AdjustUIFont(LOGFONT* logfont) { void AdjustUIFont(LOGFONT* logfont) {
l10n_util::AdjustUIFont(logfont); l10n_util::AdjustUIFont(logfont);
@ -45,9 +52,22 @@ void AdjustUIFont(LOGFONT* logfont) {
int GetMinimumFontSize() { int GetMinimumFontSize() {
return 10; return 10;
} }
#endif
#if defined(OS_LINUX)
void OverrideLinuxAppDataPath() {
base::FilePath path;
if (PathService::Get(DIR_APP_DATA, &path))
return;
scoped_ptr<base::Environment> env(base::Environment::Create());
path = base::nix::GetXDGDirectory(env.get(),
base::nix::kXdgConfigHomeEnvVar,
base::nix::kDotConfigDir);
PathService::Override(DIR_APP_DATA, path);
}
#endif
} // namespace } // namespace
#endif
BrowserMainParts::BrowserMainParts() { BrowserMainParts::BrowserMainParts() {
} }
@ -64,10 +84,13 @@ void BrowserMainParts::PreEarlyInitialization() {
views::LinuxUI::SetInstance(BuildGtk2UI()); views::LinuxUI::SetInstance(BuildGtk2UI());
#endif #endif
#if defined(OS_LINUX)
OverrideLinuxAppDataPath();
#endif
InitProxyResolverV8(); InitProxyResolverV8();
} }
void BrowserMainParts::ToolkitInitialized() { void BrowserMainParts::ToolkitInitialized() {
#if defined(USE_AURA) && defined(USE_X11) #if defined(USE_AURA) && defined(USE_X11)
views::LinuxUI::instance()->Initialize(); views::LinuxUI::instance()->Initialize();