Chromium Code Reviews| Index: webkit/tools/test_shell/simple_dom_storage_system.cc |
| =================================================================== |
| --- webkit/tools/test_shell/simple_dom_storage_system.cc (revision 0) |
| +++ webkit/tools/test_shell/simple_dom_storage_system.cc (revision 0) |
| @@ -0,0 +1,184 @@ |
| +// 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 "webkit/tools/test_shell/simple_dom_storage_system.h" |
| + |
| +#include "googleurl/src/gurl.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageArea.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h" |
| +#include "webkit/dom_storage/dom_storage_context.h" |
| +#include "webkit/dom_storage/dom_storage_host.h" |
| +#include "webkit/dom_storage/dom_storage_session.h" |
| + |
| +using dom_storage::DomStorageContext; |
| +using dom_storage::DomStorageHost; |
| +using dom_storage::DomStorageSession; |
| +using WebKit::WebStorageNamespace; |
| +using WebKit::WebStorageArea; |
| +using WebKit::WebString; |
| +using WebKit::WebURL; |
| + |
| +class SimpleDomStorageSystem::NamespaceImpl : public WebStorageNamespace { |
| + public: |
| + NamespaceImpl(const base::WeakPtr<SimpleDomStorageSystem>& parent); |
| + NamespaceImpl(const base::WeakPtr<SimpleDomStorageSystem>& parent, |
| + int session_namespace_id); |
| + virtual ~NamespaceImpl(); |
| + virtual WebStorageArea* createStorageArea(const WebString& origin) OVERRIDE; |
| + virtual WebStorageNamespace* copy() OVERRIDE; |
| + virtual void close() OVERRIDE; |
| + |
| + private: |
| + DomStorageContext* Context() { |
| + if (parent_.get()) |
|
benm (inactive)
2012/02/23 19:17:15
!parent.get()
michaeln
2012/02/28 01:14:54
Done.
|
| + return NULL; |
| + return parent_.get()->context_.get(); |
| + } |
| + |
| + base::WeakPtr<SimpleDomStorageSystem> parent_; |
| + int namespace_id_; |
| +}; |
| + |
| +class SimpleDomStorageSystem::AreaImpl : public WebStorageArea { |
| + public: |
| + AreaImpl(const base::WeakPtr<SimpleDomStorageSystem>& parent, |
| + int namespace_id, const GURL& origin); |
| + virtual ~AreaImpl(); |
| + virtual unsigned length() OVERRIDE; |
| + virtual WebString key(unsigned index) OVERRIDE; |
| + virtual WebString getItem(const WebString& key) OVERRIDE; |
| + virtual void setItem(const WebString& key, const WebString& newValue, |
| + const WebURL&, Result&, WebString& oldValue) OVERRIDE; |
| + virtual void removeItem(const WebString& key, const WebURL& url, |
| + WebString& oldValue) OVERRIDE; |
| + virtual void clear(const WebURL& url, bool& somethingCleared) OVERRIDE; |
| + |
| + private: |
| + DomStorageHost* Host() { |
| + if (parent_.get()) |
|
benm (inactive)
2012/02/23 19:17:15
!parent.get()
michaeln
2012/02/28 01:14:54
Done.
|
| + return NULL; |
| + return parent_.get()->host_.get(); |
| + } |
| + |
| + base::WeakPtr<SimpleDomStorageSystem> parent_; |
| + int connection_id_; |
| +}; |
| + |
| +// NamespaceImpl ----------------------------- |
| + |
| +SimpleDomStorageSystem::NamespaceImpl::NamespaceImpl( |
| + const base::WeakPtr<SimpleDomStorageSystem>& parent) |
| + : parent_(parent), |
| + namespace_id_(dom_storage::kLocalStorageNamespaceId) { |
| +} |
| + |
| +SimpleDomStorageSystem::NamespaceImpl::NamespaceImpl( |
| + const base::WeakPtr<SimpleDomStorageSystem>& parent, |
| + int session_namespace_id) |
| + : parent_(parent), |
| + namespace_id_(session_namespace_id) { |
| +} |
| + |
| +SimpleDomStorageSystem::NamespaceImpl::~NamespaceImpl() { |
| + if (namespace_id_ == dom_storage::kLocalStorageNamespaceId || !Context()) |
| + return; |
| + Context()->DeleteSessionNamespace(namespace_id_); |
| +} |
| + |
| +WebStorageArea* SimpleDomStorageSystem::NamespaceImpl::createStorageArea( |
| + const WebString& origin) { |
| + return new AreaImpl(parent_, namespace_id_, GURL()); |
|
benm (inactive)
2012/02/23 19:17:15
Should this be a GURL created from the origin para
michaeln
2012/02/28 01:14:54
Done.
|
| +} |
| + |
| +WebStorageNamespace* SimpleDomStorageSystem::NamespaceImpl::copy() { |
| + DCHECK_NE(dom_storage::kLocalStorageNamespaceId, namespace_id_); |
| + int new_id = -1; |
|
benm (inactive)
2012/02/23 19:17:15
how about making a kInvalidNamespaceId in dom_stor
michaeln
2012/02/28 01:14:54
Done in a constant in this file
|
| + if (Context()) { |
| + new_id = Context()->AllocateSessionId(); |
| + Context()->CloneSessionNamespace(namespace_id_, new_id); |
| + } |
| + return new NamespaceImpl(parent_, new_id); |
|
benm (inactive)
2012/02/23 19:17:15
Is it ok for -1 to end up as the id here?
michaeln
2012/02/28 01:14:54
Yes, should be harmless.
|
| +} |
| + |
| +void SimpleDomStorageSystem::NamespaceImpl::close() { |
| +} |
| + |
| +// AreaImpl ----------------------------- |
| + |
| +SimpleDomStorageSystem::AreaImpl::AreaImpl( |
| + const base::WeakPtr<SimpleDomStorageSystem>& parent, |
| + int namespace_id, const GURL& origin) |
| + : parent_(parent), |
| + connection_id_(0) { |
| + if (Host()) |
| + connection_id_ = Host()->OpenStorageArea(namespace_id, origin); |
| +} |
| + |
| +SimpleDomStorageSystem::AreaImpl::~AreaImpl() { |
| + if (Host()) |
| + Host()->CloseStorageArea(connection_id_); |
| +} |
| + |
| +unsigned SimpleDomStorageSystem::AreaImpl::length() { |
| + if (Host()) |
| + return Host()->GetAreaLength(connection_id_); |
| + return 0; |
| +} |
| + |
| +WebString SimpleDomStorageSystem::AreaImpl::key(unsigned index) { |
| + if (Host()) |
| + return Host()->GetAreaKey(connection_id_, index); |
| + return WebString(); |
| +} |
| + |
| +WebString SimpleDomStorageSystem::AreaImpl::getItem(const WebString& key) { |
| + if (Host()) |
| + return Host()->GetAreaItem(connection_id_, key); |
| + return WebString(); |
| +} |
| + |
| +void SimpleDomStorageSystem::AreaImpl::setItem( |
| + const WebString& key, const WebString& newValue, |
| + const WebURL&, Result& result, WebString& oldValue) { |
| + // host_->SetAreaItem(connection_id_, key, ...); |
| + result = ResultBlockedByQuota; |
| +} |
| + |
| +void SimpleDomStorageSystem::AreaImpl::removeItem( |
| + const WebString& key, const WebURL& url, WebString& oldValue) { |
| + // host_->RemoveAreaItem(connection_id_, key, ...); |
| +} |
| + |
| +void SimpleDomStorageSystem::AreaImpl::clear( |
| + const WebURL& page_url, bool& somethingCleared) { |
| + // somethingCleared = host_->SetAreaItem(connection_id_, page_url); |
| + somethingCleared = false; |
| +} |
| + |
| +// SimpleDomStorageSystem ----------------------------- |
| + |
| +SimpleDomStorageSystem* SimpleDomStorageSystem::g_instance_; |
| + |
| +SimpleDomStorageSystem::SimpleDomStorageSystem() |
| + : weak_factory_(this), |
| + context_(new DomStorageContext(FilePath(), NULL, NULL)), |
|
benm (inactive)
2012/02/23 19:17:15
I guess the params here still need filling out.
michaeln
2012/02/25 19:20:32
I think they may not need any more filling out tha
|
| + host_(new DomStorageHost(context_)) { |
| + DCHECK(!g_instance_); |
| + g_instance_ = this; |
| +} |
| + |
| +SimpleDomStorageSystem::~SimpleDomStorageSystem() { |
| + g_instance_ = NULL; |
| + host_.reset(); |
| +} |
| + |
| +WebStorageNamespace* SimpleDomStorageSystem::CreateLocalStorageNamespace() { |
| + return new NamespaceImpl(weak_factory_.GetWeakPtr()); |
| +} |
| + |
| +WebStorageNamespace* SimpleDomStorageSystem::CreateSessionStorageNamespace() { |
| + int id = context_->AllocateSessionId(); |
| + context_->CreateSessionNamespace(id); |
| + return new NamespaceImpl(weak_factory_.GetWeakPtr(), id); |
| +} |
| Property changes on: webkit\tools\test_shell\simple_dom_storage_system.cc |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |