From a6aded4716fa9dfffe42a4e66996c177436e25e2 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Fri, 22 Jun 2012 14:56:07 +0000 Subject: [PATCH] Implement persistent localStorage with the new DOM storage backend (issue #603). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@704 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- cef1/libcef/browser_dom_storage_system.cc | 29 +++++++++++++++++++++-- cef1/libcef/cef_context.h | 9 +++++++ cef1/libcef/cef_process_ui_thread.cc | 9 +++++++ cef1/libcef/cef_process_ui_thread.h | 3 +++ 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/cef1/libcef/browser_dom_storage_system.cc b/cef1/libcef/browser_dom_storage_system.cc index 541c3f82c..06bd62e1c 100644 --- a/cef1/libcef/browser_dom_storage_system.cc +++ b/cef1/libcef/browser_dom_storage_system.cc @@ -3,8 +3,11 @@ // found in the LICENSE file. #include "libcef/browser_dom_storage_system.h" +#include "libcef/cef_context.h" +#include "libcef/cef_thread.h" #include "base/auto_reset.h" +#include "base/path_service.h" #include "googleurl/src/gurl.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageArea.h" @@ -13,10 +16,12 @@ #include "webkit/database/database_util.h" #include "webkit/dom_storage/dom_storage_area.h" #include "webkit/dom_storage/dom_storage_host.h" +#include "webkit/dom_storage/dom_storage_task_runner.h" using dom_storage::DomStorageContext; using dom_storage::DomStorageHost; using dom_storage::DomStorageSession; +using dom_storage::DomStorageWorkerPoolTaskRunner; using webkit_database::DatabaseUtil; using WebKit::WebStorageArea; using WebKit::WebStorageNamespace; @@ -194,10 +199,30 @@ BrowserDomStorageSystem* BrowserDomStorageSystem::g_instance_; BrowserDomStorageSystem::BrowserDomStorageSystem() : weak_factory_(this), - context_(new DomStorageContext(FilePath(), FilePath(), NULL, NULL)), - host_(new DomStorageHost(context_)), area_being_processed_(NULL), next_connection_id_(1) { + FilePath local_storage_path; + FilePath cache_path(_Context->cache_path()); + if (!cache_path.empty()) { + local_storage_path = cache_path.Append(FILE_PATH_LITERAL("Local Storage")); + if (!file_util::PathExists(local_storage_path) && + !file_util::CreateDirectory(local_storage_path)) { + LOG(WARNING) << "Failed to create Local Storage directory"; + local_storage_path.clear(); + } + } + + base::SequencedWorkerPool* worker_pool = _Context->blocking_pool(); + + context_ = new DomStorageContext(local_storage_path, FilePath(), NULL, + new DomStorageWorkerPoolTaskRunner( + worker_pool, + worker_pool->GetNamedSequenceToken("dom_storage_primary"), + worker_pool->GetNamedSequenceToken("dom_storage_commit"), + CefThread::GetMessageLoopProxyForThread(CefThread::FILE))); + + host_.reset(new DomStorageHost(context_)); + DCHECK(!g_instance_); g_instance_ = this; context_->AddEventObserver(this); diff --git a/cef1/libcef/cef_context.h b/cef1/libcef/cef_context.h index 9c7179155..f6d867bc9 100644 --- a/cef1/libcef/cef_context.h +++ b/cef1/libcef/cef_context.h @@ -19,6 +19,7 @@ #include "base/at_exit.h" #include "base/file_path.h" #include "base/memory/ref_counted.h" +#include "base/threading/sequenced_worker_pool.h" class CefBrowserImpl; class CefResourceBundleDelegate; @@ -88,6 +89,12 @@ class CefContext : public CefBase { current_webviewhost_ = host; } + // The SequencedWorkerPool object is managed by CefProcessUIThread. + void set_blocking_pool(base::SequencedWorkerPool* blocking_pool) { + blocking_pool_ = blocking_pool; + } + base::SequencedWorkerPool* blocking_pool() { return blocking_pool_.get(); } + static bool ImplementsThreadSafeReferenceCounting() { return true; } private: @@ -122,6 +129,8 @@ class CefContext : public CefBase { WebViewHost* current_webviewhost_; + scoped_refptr blocking_pool_; + IMPLEMENT_REFCOUNTING(CefContext); IMPLEMENT_LOCKING(CefContext); }; diff --git a/cef1/libcef/cef_process_ui_thread.cc b/cef1/libcef/cef_process_ui_thread.cc index ea23d1d01..9da589556 100644 --- a/cef1/libcef/cef_process_ui_thread.cc +++ b/cef1/libcef/cef_process_ui_thread.cc @@ -100,6 +100,10 @@ void CefProcessUIThread::Init() { PlatformInit(); + // Initialize the blocking pool. + blocking_pool_ = new base::SequencedWorkerPool(3, "BrowserBlocking"); + _Context->set_blocking_pool(blocking_pool_.get()); + // Initialize WebKit. webkit_init_ = new BrowserWebKitInit(); @@ -194,6 +198,11 @@ void CefProcessUIThread::CleanUp() { net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); network_change_notifier_.reset(); + // Shut down the blocking pool. + _Context->set_blocking_pool(NULL); + blocking_pool_->Shutdown(); + blocking_pool_ = NULL; + PlatformCleanUp(); _Context->CleanupResourceBundle(); diff --git a/cef1/libcef/cef_process_ui_thread.h b/cef1/libcef/cef_process_ui_thread.h index a2d19621f..4b6bdef76 100644 --- a/cef1/libcef/cef_process_ui_thread.h +++ b/cef1/libcef/cef_process_ui_thread.h @@ -11,6 +11,7 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" +#include "base/threading/sequenced_worker_pool.h" #include "net/base/network_change_notifier.h" class BrowserWebKitInit; @@ -53,6 +54,8 @@ class CefProcessUIThread scoped_ptr network_change_notifier_; + scoped_refptr blocking_pool_; + DISALLOW_COPY_AND_ASSIGN(CefProcessUIThread); };