From 1ed3ac28b47233bebb02cc31e64f33f73e9d27f1 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Wed, 20 Jun 2012 19:44:00 +0000 Subject: [PATCH] - Add persistent HTML5 application cache support (issue #543). - Standardize the approach for creating new directories. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@698 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- cef1/libcef/browser_request_context.cc | 27 +++++++++++--------------- cef1/libcef/browser_webkit_init.cc | 19 +++++++++--------- cef1/libcef/browser_webkit_init.h | 1 - cef1/libcef/cef_context.cc | 6 ++++++ cef1/libcef/cookie_manager_impl.cc | 11 ++++++----- 5 files changed, 33 insertions(+), 31 deletions(-) diff --git a/cef1/libcef/browser_request_context.cc b/cef1/libcef/browser_request_context.cc index eee742045..d7dc551bc 100644 --- a/cef1/libcef/browser_request_context.cc +++ b/cef1/libcef/browser_request_context.cc @@ -146,15 +146,6 @@ void BrowserRequestContext::Init( const FilePath& cache_path, net::HttpCache::Mode cache_mode, bool no_proxy) { - // Create the |cache_path| directory if necessary. - bool cache_path_valid = false; - if (!cache_path.empty()) { - if (file_util::CreateDirectory(cache_path)) - cache_path_valid = true; - else - NOTREACHED() << "The cache_path directory could not be created"; - } - SetCookieStoragePath(cache_path); storage_.set_server_bound_cert_service(new net::ServerBoundCertService( @@ -238,7 +229,7 @@ void BrowserRequestContext::Init( storage_.set_http_server_properties(new net::HttpServerPropertiesImpl); net::HttpCache::DefaultBackend* backend = new net::HttpCache::DefaultBackend( - cache_path_valid ? net::DISK_CACHE : net::MEMORY_CACHE, + cache_path.empty() ? net::MEMORY_CACHE : net::DISK_CACHE, cache_path, 0, BrowserResourceLoaderBridge::GetCacheThread()); net::HttpCache* cache = @@ -299,13 +290,17 @@ void BrowserRequestContext::SetCookieStoragePath(const FilePath& path) { return; } + FilePath new_path = path; + scoped_refptr persistent_store; - if (!path.empty()) { - if (file_util::CreateDirectory(path)) { - const FilePath& cookie_path = path.AppendASCII("Cookies"); - persistent_store = new SQLitePersistentCookieStore(cookie_path, false); + if (!new_path.empty()) { + if (!file_util::PathExists(new_path) && + !file_util::CreateDirectory(new_path)) { + NOTREACHED() << "Failed to create cookie storage directory"; + new_path.clear(); } else { - NOTREACHED() << "The cookie storage directory could not be created"; + FilePath cookie_path = new_path.Append(FILE_PATH_LITERAL("Cookies")); + persistent_store = new SQLitePersistentCookieStore(cookie_path, false); } } @@ -314,7 +309,7 @@ void BrowserRequestContext::SetCookieStoragePath(const FilePath& path) { // longer referenced. storage_.set_cookie_store( new net::CookieMonster(persistent_store.get(), NULL)); - cookie_store_path_ = path; + cookie_store_path_ = new_path; } const std::string& BrowserRequestContext::GetUserAgent( diff --git a/cef1/libcef/browser_webkit_init.cc b/cef1/libcef/browser_webkit_init.cc index a38e2e053..e6d0afc60 100644 --- a/cef1/libcef/browser_webkit_init.cc +++ b/cef1/libcef/browser_webkit_init.cc @@ -66,16 +66,17 @@ BrowserWebKitInit::BrowserWebKitInit() PathService::Get(base::DIR_MODULE, &module_path) && media::InitializeMediaLibrary(module_path)); - // Construct and initialize an appcache system for this scope. - // A new empty temp directory is created to house any cached - // content during the run. Upon exit that directory is deleted. - // If we can't create a tempdir, we'll use in-memory storage. - if (!appcache_dir_.CreateUniqueTempDir()) { - LOG(WARNING) << "Failed to create a temp dir for the appcache, " - "using in-memory storage."; - DCHECK(appcache_dir_.path().empty()); + FilePath appcache_path; + FilePath cache_path = _Context->cache_path(); + if (!cache_path.empty()) { + appcache_path = cache_path.Append(FILE_PATH_LITERAL("AppCache")); + if (!file_util::PathExists(appcache_path) && + !file_util::CreateDirectory(appcache_path)) { + LOG(WARNING) << "Failed to create appcache storage directory"; + appcache_path.clear(); + } } - BrowserAppCacheSystem::InitializeOnUIThread(appcache_dir_.path()); + BrowserAppCacheSystem::InitializeOnUIThread(appcache_path); WebKit::WebDatabase::setObserver(&database_system_); diff --git a/cef1/libcef/browser_webkit_init.h b/cef1/libcef/browser_webkit_init.h index 0a5d63d3a..5d8cad3ac 100644 --- a/cef1/libcef/browser_webkit_init.h +++ b/cef1/libcef/browser_webkit_init.h @@ -104,7 +104,6 @@ class BrowserWebKitInit : public webkit_glue::WebKitPlatformSupportImpl { webkit_glue::WebClipboardImpl clipboard_; SimpleClipboardClient clipboard_client_; webkit_glue::WebFileUtilitiesImpl file_utilities_; - ScopedTempDir appcache_dir_; BrowserAppCacheSystem appcache_system_; BrowserDatabaseSystem database_system_; BrowserDomStorageSystem dom_storage_system_; diff --git a/cef1/libcef/cef_context.cc b/cef1/libcef/cef_context.cc index fc4f9a44e..4ac1a8daa 100644 --- a/cef1/libcef/cef_context.cc +++ b/cef1/libcef/cef_context.cc @@ -263,6 +263,12 @@ bool CefContext::Initialize(const CefSettings& settings, application_ = application; cache_path_ = FilePath(CefString(&settings.cache_path)); + if (!cache_path_.empty() && + !file_util::PathExists(cache_path_) && + !file_util::CreateDirectory(cache_path_)) { + NOTREACHED() << "Failed to create cache_path directory"; + cache_path_.clear(); + } #if defined(OS_MACOSX) || defined(OS_WIN) // We want to be sure to init NSPR on the main thread. diff --git a/cef1/libcef/cookie_manager_impl.cc b/cef1/libcef/cookie_manager_impl.cc index 3044c83a0..4ab7b82e8 100644 --- a/cef1/libcef/cookie_manager_impl.cc +++ b/cef1/libcef/cookie_manager_impl.cc @@ -227,12 +227,13 @@ bool CefCookieManagerImpl::SetStoragePath(const CefString& path) { scoped_refptr persistent_store; if (!new_path.empty()) { - if (file_util::CreateDirectory(new_path)) { - const FilePath& cookie_path = new_path.AppendASCII("Cookies"); - persistent_store = new SQLitePersistentCookieStore(cookie_path, false); + if (!file_util::PathExists(new_path) && + !file_util::CreateDirectory(new_path)) { + NOTREACHED() << "Failed to create cookie storage directory"; + new_path.clear(); } else { - NOTREACHED() << "The cookie storage directory could not be created"; - storage_path_.clear(); + FilePath cookie_path = new_path.Append(FILE_PATH_LITERAL("Cookies")); + persistent_store = new SQLitePersistentCookieStore(cookie_path, false); } }