From 6f2897cb509ae736df7a58014babf758b042b9af Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Mon, 25 Jun 2012 18:22:50 +0000 Subject: [PATCH] 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 --- libcef/browser/browser_context.cc | 42 +------------------- libcef/browser/browser_context.h | 3 -- libcef/browser/context.cc | 4 +- libcef/browser/cookie_manager_impl.cc | 3 +- libcef/browser/download_manager_delegate.cc | 2 +- libcef/browser/url_request_context_getter.cc | 3 +- 6 files changed, 10 insertions(+), 47 deletions(-) diff --git a/libcef/browser/browser_context.cc b/libcef/browser/browser_context.cc index fb0755fe2..dcfb56951 100644 --- a/libcef/browser/browser_context.cc +++ b/libcef/browser/browser_context.cc @@ -7,38 +7,24 @@ #include #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 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 { diff --git a/libcef/browser/browser_context.h b/libcef/browser/browser_context.h index 2d6063b9f..3367e680c 100644 --- a/libcef/browser/browser_context.h +++ b/libcef/browser/browser_context.h @@ -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 resource_context_; scoped_refptr download_manager_delegate_; scoped_refptr download_manager_; diff --git a/libcef/browser/context.cc b/libcef/browser/context.cc index bd99684e6..f1fa361a8 100644 --- a/libcef/browser/context.cc +++ b/libcef/browser/context.cc @@ -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(); } diff --git a/libcef/browser/cookie_manager_impl.cc b/libcef/browser/cookie_manager_impl.cc index 780f69fc6..15d9e5002 100644 --- a/libcef/browser/cookie_manager_impl.cc +++ b/libcef/browser/cookie_manager_impl.cc @@ -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); diff --git a/libcef/browser/download_manager_delegate.cc b/libcef/browser/download_manager_delegate.cc index 09d035096..7b8dfc7ab 100644 --- a/libcef/browser/download_manager_delegate.cc +++ b/libcef/browser/download_manager_delegate.cc @@ -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); diff --git a/libcef/browser/url_request_context_getter.cc b/libcef/browser/url_request_context_getter.cc index 7544d2c48..f7740dd5c 100644 --- a/libcef/browser/url_request_context_getter.cc +++ b/libcef/browser/url_request_context_getter.cc @@ -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);