Store all persistent data in the CefSettings.cache_path directory (issue #510).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@709 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2012-06-25 18:22:50 +00:00
parent f7c91a7d6b
commit 6f2897cb50
6 changed files with 10 additions and 47 deletions

View File

@ -7,38 +7,24 @@
#include <map>
#include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/context.h"
#include "libcef/browser/download_manager_delegate.h"
#include "libcef/browser/resource_context.h"
#include "libcef/browser/thread_util.h"
#include "libcef/browser/url_request_context_getter.h"
#include "base/bind.h"
#include "base/environment.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/threading/thread.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/geolocation_permission_context.h"
#include "content/public/browser/speech_recognition_preferences.h"
#if defined(OS_WIN)
#include "base/base_paths_win.h"
#elif defined(OS_LINUX)
#include "base/nix/xdg_util.h"
#endif
using content::BrowserThread;
namespace {
#if defined(OS_LINUX)
const char kDotConfigDir[] = ".config";
const char kXdgConfigHomeEnvVar[] = "XDG_CONFIG_HOME";
#endif
class CefGeolocationPermissionContext
: public content::GeolocationPermissionContext {
public:
@ -187,8 +173,6 @@ class CefSpeechRecognitionPreferences
} // namespace
CefBrowserContext::CefBrowserContext() {
InitWhileIOAllowed();
// Initialize the request context getter.
url_request_getter_ = new CefURLRequestContextGetter(
GetPath(),
@ -206,30 +190,8 @@ CefBrowserContext::~CefBrowserContext() {
}
}
void CefBrowserContext::InitWhileIOAllowed() {
#if defined(OS_WIN)
CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path_));
path_ = path_.Append(std::wstring(L"cef_data"));
#elif defined(OS_LINUX)
scoped_ptr<base::Environment> env(base::Environment::Create());
FilePath config_dir(
base::nix::GetXDGDirectory(env.get(),
base::nix::kXdgConfigHomeEnvVar,
base::nix::kDotConfigDir));
path_ = config_dir.Append("cef_data");
#elif defined(OS_MACOSX)
CHECK(PathService::Get(base::DIR_APP_DATA, &path_));
path_ = path_.Append("cef_data");
#else
NOTIMPLEMENTED();
#endif
if (!file_util::PathExists(path_))
file_util::CreateDirectory(path_);
}
FilePath CefBrowserContext::GetPath() {
return path_;
return _Context->cache_path();
}
bool CefBrowserContext::IsOffTheRecord() const {

View File

@ -25,8 +25,6 @@ class CefBrowserContext : public content::BrowserContext {
CefBrowserContext();
virtual ~CefBrowserContext();
void InitWhileIOAllowed();
// BrowserContext methods.
virtual FilePath GetPath() OVERRIDE;
virtual bool IsOffTheRecord() const OVERRIDE;
@ -45,7 +43,6 @@ class CefBrowserContext : public content::BrowserContext {
private:
FilePath path_;
scoped_ptr<content::ResourceContext> resource_context_;
scoped_refptr<CefDownloadManagerDelegate> download_manager_delegate_;
scoped_refptr<content::DownloadManager> download_manager_;

View File

@ -182,7 +182,9 @@ bool CefContext::Initialize(const CefMainArgs& args,
settings_ = settings;
cache_path_ = FilePath(CefString(&settings.cache_path));
if (!cache_path_.empty() && !file_util::CreateDirectory(cache_path_)) {
if (!cache_path_.empty() &&
!file_util::DirectoryExists(cache_path_) &&
!file_util::CreateDirectory(cache_path_)) {
NOTREACHED() << "The cache_path directory could not be created";
cache_path_ = FilePath();
}

View File

@ -330,7 +330,8 @@ bool CefCookieManagerImpl::SetStoragePath(const CefString& path) {
// TODO(cef): Move directory creation to the blocking pool instead of
// allowing file IO on this thread.
base::ThreadRestrictions::ScopedAllowIO allow_io;
if (file_util::CreateDirectory(new_path)) {
if (file_util::DirectoryExists(new_path) ||
file_util::CreateDirectory(new_path)) {
const FilePath& cookie_path = new_path.AppendASCII("Cookies");
persistent_store =
new SQLitePersistentCookieStore(cookie_path, false, NULL);

View File

@ -95,7 +95,7 @@ void CefDownloadManagerDelegate::GenerateFilename(
const FilePath& generated_name) {
FilePath suggested_path = download_manager_->GetBrowserContext()->GetPath().
Append(FILE_PATH_LITERAL("Downloads"));
if (!file_util::PathExists(suggested_path))
if (!file_util::DirectoryExists(suggested_path))
file_util::CreateDirectory(suggested_path);
suggested_path = suggested_path.Append(generated_name);

View File

@ -304,7 +304,8 @@ void CefURLRequestContextGetter::SetCookieStoragePath(const FilePath& path) {
// TODO(cef): Move directory creation to the blocking pool instead of
// allowing file IO on this thread.
base::ThreadRestrictions::ScopedAllowIO allow_io;
if (file_util::CreateDirectory(path)) {
if (file_util::DirectoryExists(path) ||
file_util::CreateDirectory(path)) {
const FilePath& cookie_path = path.AppendASCII("Cookies");
persistent_store =
new SQLitePersistentCookieStore(cookie_path, false, NULL);