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..9056c1ae8d9fcd9c819c834e2021f38cf2b21040 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) { |
@@ -124,13 +131,25 @@ void DomStorageContext::Shutdown() { |
for (; it != namespaces_.end(); ++it) |
it->second->Shutdown(); |
+ // Delete data from sessionStorage. If the previous exit was unclean, the |
+ // session storage backing might contain leftover data. Delete it now. |
+ if (session_storage_database_.get()) { |
+ bool success = task_runner_->PostShutdownBlockingTask( |
+ FROM_HERE, |
+ DomStorageTaskRunner::COMMIT_SEQUENCE, |
+ base::Bind(&DomStorageContext::DeleteLeftoverDataInCommitSequence, |
+ this)); |
+ DCHECK(success); |
+ } |
+ |
+ // Delete data from localStorage. |
if (localstorage_directory_.empty()) |
return; |
// Respect the content policy settings about what to |
// keep and what to discard. |
- if (save_session_state_) |
- return; // Keep everything. |
+ if (save_session_state_) // Keep everything. |
+ return; |
bool has_session_only_origins = |
special_storage_policy_.get() && |
@@ -192,13 +211,23 @@ void DomStorageContext::CreateSessionNamespace( |
DCHECK(namespace_id != kLocalStorageNamespaceId); |
DCHECK(namespaces_.find(namespace_id) == namespaces_.end()); |
namespaces_[namespace_id] = new DomStorageNamespace( |
- namespace_id, task_runner_); |
+ namespace_id, session_storage_database_.get(), 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. |
+ 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 +266,22 @@ void DomStorageContext::ClearLocalStateInCommitSequence() { |
} |
} |
+void DomStorageContext::DeleteSessionNamespaceInCommitSequence( |
+ int64 namespace_id) { |
+ session_storage_database_->DeleteNamespace(namespace_id); |
+} |
+ |
+void DomStorageContext::DeleteLeftoverDataInCommitSequence() { |
+ DCHECK(session_storage_database_.get()); |
+ // Delete all namespaces which don't have an associated DomStorageNamespace |
+ // alive. |
+ std::vector<int64> namespace_ids; |
+ session_storage_database_->ReadNamespaceIds(&namespace_ids); |
+ for (std::vector<int64>::const_iterator it = namespace_ids.begin(); |
+ it != namespace_ids.end(); ++it) { |
+ if (namespaces_.find(*it) == namespaces_.end()) |
+ session_storage_database_->DeleteNamespace(*it); |
+ } |
+} |
+ |
} // namespace dom_storage |