Chromium Code Reviews| Index: webkit/dom_storage/dom_storage_namespace.cc |
| =================================================================== |
| --- webkit/dom_storage/dom_storage_namespace.cc (revision 0) |
| +++ webkit/dom_storage/dom_storage_namespace.cc (working copy) |
| @@ -1,109 +1,65 @@ |
| -// Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. Use of this |
| // source code is governed by a BSD-style license that can be found in the |
| // LICENSE file. |
| -#include "content/browser/in_process_webkit/dom_storage_namespace.h" |
| +#include "webkit/dom_storage/dom_storage_namespace.h" |
| -#include "base/file_path.h" |
| -#include "content/browser/in_process_webkit/dom_storage_area.h" |
| -#include "content/browser/in_process_webkit/dom_storage_context.h" |
| -#include "content/browser/in_process_webkit/dom_storage_message_filter.h" |
| -#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageArea.h" |
| -#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h" |
| -#include "webkit/glue/webkit_glue.h" |
| +#include "base/basictypes.h" |
| +#include "base/logging.h" |
| +#include "webkit/dom_storage/dom_storage_area.h" |
| -using WebKit::WebStorageArea; |
| -using WebKit::WebStorageNamespace; |
| -using WebKit::WebString; |
| +namespace dom_storage { |
| -/* static */ |
| -DOMStorageNamespace* DOMStorageNamespace::CreateLocalStorageNamespace( |
| - DOMStorageContext* dom_storage_context, const FilePath& data_dir_path) { |
| - int64 id = kLocalStorageNamespaceId; |
| - DCHECK(!dom_storage_context->GetStorageNamespace(id, false)); |
| - return new DOMStorageNamespace(dom_storage_context, id, |
| - webkit_glue::FilePathToWebString(data_dir_path), DOM_STORAGE_LOCAL); |
| +DomStorageNamespace::DomStorageNamespace( |
| + int64 namespace_id, |
| + const FilePath& directory, // may be empty |
| + DomStorageTaskRunner* task_runner) |
| + : namespace_id_(namespace_id), |
| + directory_(directory), |
| + task_runner_(task_runner) { |
| } |
| -/* static */ |
| -DOMStorageNamespace* DOMStorageNamespace::CreateSessionStorageNamespace( |
| - DOMStorageContext* dom_storage_context, int64 id) { |
| - DCHECK(!dom_storage_context->GetStorageNamespace(id, false)); |
| - return new DOMStorageNamespace(dom_storage_context, id, WebString(), |
| - DOM_STORAGE_SESSION); |
| +DomStorageArea* DomStorageNamespace::OpenStorageArea(const GURL& origin) { |
| + if (AreaHolder* holder = GetAreaHolder(origin)) { |
| + ++(holder->open_count_); |
| + return holder->area_; |
| + } |
| + // TODO(michaeln): Compute the right filepath. |
|
benm (inactive)
2012/02/02 16:23:19
Do you mean whether there should be a backing file
michaeln
2012/02/03 00:33:42
Done. I see in your CL you've got the 'area' compu
|
| + DomStorageArea* area = new DomStorageArea(namespace_id_, origin, |
| + FilePath(), task_runner_); |
| + areas_[origin] = AreaHolder(area, 1); |
| + return area; |
| } |
| -DOMStorageNamespace::DOMStorageNamespace(DOMStorageContext* dom_storage_context, |
| - int64 id, |
| - const WebString& data_dir_path, |
| - DOMStorageType dom_storage_type) |
| - : dom_storage_context_(dom_storage_context), |
| - id_(id), |
| - data_dir_path_(data_dir_path), |
| - dom_storage_type_(dom_storage_type) { |
| - DCHECK(dom_storage_context_); |
| +void DomStorageNamespace::CloseStorageArea(DomStorageArea* area) { |
| + AreaHolder* holder = GetAreaHolder(area->origin()); |
| + DCHECK(holder); |
| + DCHECK_EQ(holder->area_.get(), area); |
| + --(holder->open_count_); |
| + // TODO(michaeln): Clean up areas that aren't needed in memory anymore. |
| + // The in-process-webkit based impl didn't do this, but would be nice. |
| } |
| -DOMStorageNamespace::~DOMStorageNamespace() { |
| - // TODO(jorlow): If the DOMStorageContext is being destructed, there's no need |
| - // to do these calls. Maybe we should add a fast path? |
| - for (OriginToStorageAreaMap::iterator iter(origin_to_storage_area_.begin()); |
| - iter != origin_to_storage_area_.end(); ++iter) { |
| - dom_storage_context_->UnregisterStorageArea(iter->second); |
| - delete iter->second; |
| +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, FilePath(), task_runner_); |
| + AreaMap::const_iterator it = areas_.begin(); |
| + for (; it != areas_.end(); ++it) { |
| + DomStorageArea* area = it->second.area_->ShallowCopy(clone_namespace_id); |
| + clone->areas_[it->first] = AreaHolder(area, 0); |
| } |
| + return clone; |
| } |
| -DOMStorageArea* DOMStorageNamespace::GetStorageArea(const string16& origin) { |
| - // We may have already created it for another dispatcher host. |
| - OriginToStorageAreaMap::iterator iter = origin_to_storage_area_.find(origin); |
| - if (iter != origin_to_storage_area_.end()) |
| - return iter->second; |
| - |
| - // We need to create a new one. |
| - int64 id = dom_storage_context_->AllocateStorageAreaId(); |
| - DCHECK(!dom_storage_context_->GetStorageArea(id)); |
| - DOMStorageArea* storage_area = new DOMStorageArea(origin, id, this); |
| - origin_to_storage_area_[origin] = storage_area; |
| - dom_storage_context_->RegisterStorageArea(storage_area); |
| - return storage_area; |
| +DomStorageNamespace::AreaHolder* |
| +DomStorageNamespace::GetAreaHolder(const GURL& origin) { |
| + AreaMap::iterator found = areas_.find(origin); |
| + if (found == areas_.end()) |
| + return NULL; |
| + return &(found->second); |
| } |
| -DOMStorageNamespace* DOMStorageNamespace::Copy(int64 id) { |
| - DCHECK(dom_storage_type_ == DOM_STORAGE_SESSION); |
| - DCHECK(!dom_storage_context_->GetStorageNamespace(id, false)); |
| - DOMStorageNamespace* new_storage_namespace = new DOMStorageNamespace( |
| - dom_storage_context_, id, data_dir_path_, dom_storage_type_); |
| - // If we haven't used the namespace yet, there's nothing to copy. |
| - if (storage_namespace_.get()) |
| - new_storage_namespace->storage_namespace_.reset(storage_namespace_->copy()); |
| - return new_storage_namespace; |
| -} |
| -void DOMStorageNamespace::PurgeMemory() { |
| - DCHECK(dom_storage_type_ == DOM_STORAGE_LOCAL); |
| - for (OriginToStorageAreaMap::iterator iter(origin_to_storage_area_.begin()); |
| - iter != origin_to_storage_area_.end(); ++iter) |
| - iter->second->PurgeMemory(); |
| - storage_namespace_.reset(); |
| -} |
| - |
| -WebStorageArea* DOMStorageNamespace::CreateWebStorageArea( |
| - const string16& origin) { |
| - CreateWebStorageNamespaceIfNecessary(); |
| - return storage_namespace_->createStorageArea(origin); |
| -} |
| - |
| -void DOMStorageNamespace::CreateWebStorageNamespaceIfNecessary() { |
| - if (storage_namespace_.get()) |
| - return; |
| - |
| - if (dom_storage_type_ == DOM_STORAGE_LOCAL) { |
| - storage_namespace_.reset( |
| - WebStorageNamespace::createLocalStorageNamespace(data_dir_path_, |
| - WebStorageNamespace::m_localStorageQuota)); |
| - } else { |
| - storage_namespace_.reset(WebStorageNamespace::createSessionStorageNamespace( |
| - WebStorageNamespace::m_sessionStorageQuota)); |
| - } |
| -} |
| +} // namespace dom_storage |