Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(824)

Unified Diff: webkit/dom_storage/dom_storage_context.cc

Issue 9963107: Persist sessionStorage on disk. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webkit/dom_storage/dom_storage_context.cc
diff --git a/webkit/dom_storage/dom_storage_context.cc b/webkit/dom_storage/dom_storage_context.cc
index e31019067cea7b9922f5e894dd30e741c1d0b5c9..175316d4758ed5cdf3514a72274103376bbea44c 100644
--- a/webkit/dom_storage/dom_storage_context.cc
+++ b/webkit/dom_storage/dom_storage_context.cc
@@ -10,9 +10,11 @@
#include "base/location.h"
#include "base/time.h"
#include "webkit/dom_storage/dom_storage_area.h"
+#include "webkit/dom_storage/dom_storage_database.h"
#include "webkit/dom_storage/dom_storage_namespace.h"
#include "webkit/dom_storage/dom_storage_task_runner.h"
#include "webkit/dom_storage/dom_storage_types.h"
+#include "webkit/dom_storage/session_storage_database.h"
#include "webkit/quota/special_storage_policy.h"
using file_util::FileEnumerator;
@@ -38,6 +40,10 @@ DomStorageContext::DomStorageContext(
// namespace ids at one since zero is reserved for the
// kLocalStorageNamespaceId.
session_id_sequence_.GetNext();
+ if (!sessionstorage_directory_.empty()) {
+ session_storage_database_ =
+ new SessionStorageDatabase(sessionstorage_directory_);
+ }
}
DomStorageContext::~DomStorageContext() {
@@ -87,6 +93,7 @@ void DomStorageContext::GetUsageInfo(std::vector<UsageInfo>* infos,
infos->push_back(info);
}
}
+ // FIXME(marja): Get usage infos for sessionStorage (crbug.com/123599).
}
void DomStorageContext::DeleteOrigin(const GURL& origin) {
@@ -146,6 +153,16 @@ void DomStorageContext::Shutdown() {
base::Bind(&DomStorageContext::ClearLocalStateInCommitSequence, this));
DCHECK(success);
}
+
+ // If the last exit was unclean, the session storage backing might contain
+ // leftover data. Delete it now.
+ // TODO(marja): When doing a session restore, protect parts of the data from
+ // deletion.
+ bool success = task_runner_->PostShutdownBlockingTask(
+ FROM_HERE,
+ DomStorageTaskRunner::COMMIT_SEQUENCE,
+ base::Bind(&DomStorageContext::DeleteLeftoverDataInCommitSequence, this));
michaeln 2012/04/22 21:43:35 it might be premature to have this here, feels lik
marja 2012/05/11 12:18:32 Should I make it so that this CL just deletes all
michaeln 2012/05/16 08:10:55 Maybe don't try to answer this question just yet,
+ DCHECK(success);
}
void DomStorageContext::AddEventObserver(EventObserver* observer) {
@@ -191,14 +208,31 @@ void DomStorageContext::CreateSessionNamespace(
return;
DCHECK(namespace_id != kLocalStorageNamespaceId);
DCHECK(namespaces_.find(namespace_id) == namespaces_.end());
- namespaces_[namespace_id] = new DomStorageNamespace(
- namespace_id, task_runner_);
+ if (session_storage_database_.get()) {
+ // Session storage with backing.
+ namespaces_[namespace_id] = new DomStorageNamespace(
+ namespace_id, session_storage_database_.get(), task_runner_);
+ } else {
+ // Session storage without backing.
+ namespaces_[namespace_id] = new DomStorageNamespace(
+ namespace_id, task_runner_);
+ }
}
void DomStorageContext::DeleteSessionNamespace(
int64 namespace_id) {
DCHECK_NE(kLocalStorageNamespaceId, namespace_id);
namespaces_.erase(namespace_id);
+ // TODO(marja): When doing a session restore, protect parts of the data from
+ // deletion.
michaeln 2012/04/22 21:43:35 maybe the way the session handling logic in chrome
marja 2012/05/11 12:18:32 Hmm, not sure yet how this would work. Could the
+ if (session_storage_database_.get()) {
+ bool success = task_runner_->PostShutdownBlockingTask(
+ FROM_HERE,
+ DomStorageTaskRunner::COMMIT_SEQUENCE,
+ base::Bind(&DomStorageContext::DeleteSessionNamespaceInCommitSequence,
+ this, namespace_id));
+ DCHECK(success);
+ }
}
void DomStorageContext::CloneSessionNamespace(
@@ -237,4 +271,13 @@ void DomStorageContext::ClearLocalStateInCommitSequence() {
}
}
+void DomStorageContext::DeleteSessionNamespaceInCommitSequence(
+ int64 namespace_id) {
+ session_storage_database_->DeleteNamespace(namespace_id);
+}
+
+void DomStorageContext::DeleteLeftoverDataInCommitSequence() {
+ session_storage_database_->DeleteLeftoverData();
+}
+
} // namespace dom_storage

Powered by Google App Engine
This is Rietveld 408576698