| 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..1f1b2e70239385e9611a78bc4f309ca3ee196e7c 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,12 @@ 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_,
|
| + base::Bind(&DomStorageContext::NotifySessionStorageNamespaceAssociated,
|
| + this));
|
| + }
|
| }
|
|
|
| DomStorageContext::~DomStorageContext() {
|
| @@ -87,6 +95,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 +133,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() &&
|
| @@ -185,6 +206,25 @@ void DomStorageContext::NotifyAreaCleared(
|
| OnDomStorageAreaCleared(area, page_url));
|
| }
|
|
|
| +void DomStorageContext::AddSessionStorageObserver(
|
| + int64 namespace_id,
|
| + SessionStorageObserver* observer) {
|
| + session_storage_observers_[namespace_id] = observer;
|
| +}
|
| +
|
| +void DomStorageContext::RemoveSessionStorageObserver(int64 namespace_id) {
|
| + session_storage_observers_.erase(namespace_id);
|
| +}
|
| +
|
| +void DomStorageContext::NotifySessionStorageNamespaceAssociated(
|
| + int64 namespace_id,
|
| + int64 real_namespace_id) {
|
| + std::map<int64, SessionStorageObserver*>::const_iterator it =
|
| + session_storage_observers_.find(namespace_id);
|
| + if (it != session_storage_observers_.end())
|
| + it->second->OnSessionStorageNamespaceAssociated(real_namespace_id);
|
| +}
|
| +
|
| void DomStorageContext::CreateSessionNamespace(
|
| int64 namespace_id) {
|
| if (is_shutdown_)
|
| @@ -192,13 +232,22 @@ 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);
|
| + // FIXME: protect 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(
|
| @@ -214,6 +263,19 @@ void DomStorageContext::CloneSessionNamespace(
|
| CreateSessionNamespace(new_id);
|
| }
|
|
|
| +void DomStorageContext::AssociateSessionStorage(int64 namespace_id,
|
| + int64 real_id) {
|
| + if (!session_storage_database_.get())
|
| + return;
|
| + bool success = task_runner_->PostShutdownBlockingTask(
|
| + FROM_HERE,
|
| + DomStorageTaskRunner::COMMIT_SEQUENCE,
|
| + base::Bind(&SessionStorageDatabase::AssociateNamespaceId,
|
| + session_storage_database_.get(),
|
| + namespace_id, real_id));
|
| + DCHECK(success);
|
| +}
|
| +
|
| void DomStorageContext::ClearLocalStateInCommitSequence() {
|
| std::vector<UsageInfo> infos;
|
| const bool kDontIncludeFileInfo = false;
|
| @@ -237,4 +299,23 @@ 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.
|
| + // FIXME: protect from deletion.
|
| + 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
|
|
|