Chromium Code Reviews| Index: webkit/dom_storage/dom_storage_namespace.cc |
| diff --git a/webkit/dom_storage/dom_storage_namespace.cc b/webkit/dom_storage/dom_storage_namespace.cc |
| index 656d244345258d5328f384241e07c3e2b7652ab5..6f972667d6cbf75a093c972ad97406973d00021b 100644 |
| --- a/webkit/dom_storage/dom_storage_namespace.cc |
| +++ b/webkit/dom_storage/dom_storage_namespace.cc |
| @@ -5,10 +5,13 @@ |
| #include "webkit/dom_storage/dom_storage_namespace.h" |
| #include "base/basictypes.h" |
| +#include "base/bind.h" |
| +#include "base/location.h" |
| #include "base/logging.h" |
| #include "webkit/dom_storage/dom_storage_area.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" |
| namespace dom_storage { |
| @@ -28,7 +31,19 @@ DomStorageNamespace::DomStorageNamespace( |
| DCHECK_NE(kLocalStorageNamespaceId, namespace_id); |
| } |
| +DomStorageNamespace::DomStorageNamespace( |
| + int64 namespace_id, |
| + SessionStorageDatabase* session_storage_database, |
| + DomStorageTaskRunner* task_runner) |
| + : namespace_id_(namespace_id), |
| + task_runner_(task_runner), |
| + session_storage_database_(session_storage_database) { |
| + DCHECK_NE(kLocalStorageNamespaceId, namespace_id); |
| +} |
| + |
| DomStorageNamespace::~DomStorageNamespace() { |
| + if (session_storage_database_.get()) |
| + session_storage_database_->DeleteNamespace(namespace_id_); |
|
michaeln
2012/04/22 21:43:35
should this be here given the logic in DomStorageC
marja
2012/05/11 12:18:32
Done.
|
| } |
| DomStorageArea* DomStorageNamespace::OpenStorageArea(const GURL& origin) { |
| @@ -36,8 +51,18 @@ DomStorageArea* DomStorageNamespace::OpenStorageArea(const GURL& origin) { |
| ++(holder->open_count_); |
| return holder->area_; |
| } |
| - DomStorageArea* area = new DomStorageArea(namespace_id_, origin, |
| - directory_, task_runner_); |
| + DomStorageArea* area; |
| + if (!directory_.empty()) { |
| + // Local storage backed on disk. |
| + area = new DomStorageArea(namespace_id_, origin, directory_, task_runner_); |
| + } else if (session_storage_database_.get()) { |
| + // Session storage backed on disk. |
| + area = new DomStorageArea(namespace_id_, origin, session_storage_database_, |
| + task_runner_); |
| + } else { |
| + // In-memory. |
| + area = new DomStorageArea(namespace_id_, origin, task_runner_); |
| + } |
| areas_[origin] = AreaHolder(area, 1); |
| return area; |
| } |
| @@ -54,13 +79,24 @@ void DomStorageNamespace::CloseStorageArea(DomStorageArea* area) { |
| DomStorageNamespace* DomStorageNamespace::Clone(int64 clone_namespace_id) { |
| DCHECK_NE(kLocalStorageNamespaceId, namespace_id_); |
| DCHECK_NE(kLocalStorageNamespaceId, clone_namespace_id); |
| - DomStorageNamespace* clone = |
| - new DomStorageNamespace(clone_namespace_id, task_runner_); |
| + DomStorageNamespace* clone = new DomStorageNamespace( |
| + clone_namespace_id, session_storage_database_, task_runner_); |
| AreaMap::const_iterator it = areas_.begin(); |
| + // We need to commit all data to the database before making a shallow copy, |
| + // otherwise the data which is written will cause a deep copy. ShallowCopy |
| + // will ensure that the next task in the commit sequence will be committing |
| + // the data. |
|
michaeln
2012/04/22 21:43:35
not sure this elaborate comment is needed here
//
marja
2012/05/11 12:18:32
Done. DomStorageArea::ShallowCopy will also put th
|
| for (; it != areas_.end(); ++it) { |
| DomStorageArea* area = it->second.area_->ShallowCopy(clone_namespace_id); |
| clone->areas_[it->first] = AreaHolder(area, 0); |
| } |
| + // CloneNamespaceInCommitSequence will be done after writing data. |
|
michaeln
2012/04/22 21:43:35
// And clone the on-disk structures too.
marja
2012/05/11 12:18:32
Done.
|
| + bool success = task_runner_->PostShutdownBlockingTask( |
|
michaeln
2012/04/22 21:43:35
in mem-only cases (chromiumDRT and some tests) its
marja
2012/05/11 12:18:32
Done.
|
| + FROM_HERE, |
| + DomStorageTaskRunner::COMMIT_SEQUENCE, |
| + base::Bind(&DomStorageNamespace::CloneNamespaceInCommitSequence, this, |
|
michaeln
2012/04/22 21:43:35
instead of binding to a helper method of this obje
marja
2012/05/11 12:18:32
Done. For that to work, I needed to change the ret
michaeln
2012/05/16 08:10:55
The base::IgnoreResult template could probably wor
|
| + clone_namespace_id)); |
| + DCHECK(success); |
| return clone; |
| } |
| @@ -74,6 +110,11 @@ void DomStorageNamespace::DeleteOrigin(const GURL& origin) { |
| scoped_refptr<DomStorageArea> area = |
| new DomStorageArea(namespace_id_, origin, directory_, task_runner_); |
| area->DeleteOrigin(); |
| + } else if (session_storage_database_.get()) { |
| + scoped_refptr<DomStorageArea> area = |
| + new DomStorageArea(namespace_id_, origin, |
| + session_storage_database_.get(), task_runner_); |
| + area->DeleteOrigin(); |
| } |
| } |
| @@ -117,6 +158,12 @@ DomStorageNamespace::GetAreaHolder(const GURL& origin) { |
| return &(found->second); |
| } |
| +void DomStorageNamespace::CloneNamespaceInCommitSequence( |
| + int64 clone_namespace_id) { |
| + session_storage_database_->ShallowCopyNamespace( |
| + namespace_id_, clone_namespace_id); |
| +} |
| + |
| // AreaHolder |
| DomStorageNamespace::AreaHolder::AreaHolder() |