diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-19 23:40:04 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-19 23:40:04 +0000 |
commit | 24c915e7d8204d061c62516da805416f21f88269 (patch) | |
tree | 29cb9640ae147d1ea85f7b4dd848ee02e1de958e /content/browser/dom_storage | |
parent | 4a4512426f2c7224f3895d959e66ca1e8111a194 (diff) | |
download | chromium_src-24c915e7d8204d061c62516da805416f21f88269.zip chromium_src-24c915e7d8204d061c62516da805416f21f88269.tar.gz chromium_src-24c915e7d8204d061c62516da805416f21f88269.tar.bz2 |
DOMStorageContextImpl that's implemented in terms of the new dom_storage classes. Also compile out existing tests that no longer apply when ENABLE_NEW_DOM_STORAGE_BACKEND is defined.
BUG=106763
Review URL: https://chromiumcodereview.appspot.com/9695013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127573 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/dom_storage')
-rw-r--r-- | content/browser/dom_storage/dom_storage_context_impl_new.cc | 174 | ||||
-rw-r--r-- | content/browser/dom_storage/dom_storage_context_impl_new.h | 75 |
2 files changed, 249 insertions, 0 deletions
diff --git a/content/browser/dom_storage/dom_storage_context_impl_new.cc b/content/browser/dom_storage/dom_storage_context_impl_new.cc new file mode 100644 index 0000000..dec97e0 --- /dev/null +++ b/content/browser/dom_storage/dom_storage_context_impl_new.cc @@ -0,0 +1,174 @@ +// 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/dom_storage/dom_storage_context_impl_new.h" + +#ifdef ENABLE_NEW_DOM_STORAGE_BACKEND + +#include "base/bind.h" +#include "base/bind_helpers.h" +#include "base/message_loop_proxy.h" +#include "content/public/browser/browser_thread.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" +#include "webkit/database/database_util.h" +#include "webkit/dom_storage/dom_storage_area.h" +#include "webkit/dom_storage/dom_storage_context.h" +#include "webkit/dom_storage/dom_storage_task_runner.h" +#include "webkit/glue/webkit_glue.h" + +using content::BrowserThread; +using content::DOMStorageContext; +using dom_storage::DomStorageArea; +using dom_storage::DomStorageContext; +using dom_storage::DomStorageWorkerPoolTaskRunner; +using webkit_database::DatabaseUtil; + +namespace { + +const char kLocalStorageDirectory[] = "Local Storage"; + +// TODO(michaeln): Fix the content layer api, FilePaths and +// string16 origin_ids are just wrong. Then get rid of +// this conversion non-sense. Most of the includes are just +// to support that non-sense. + +GURL OriginIdToGURL(const string16& origin_id) { + return DatabaseUtil::GetOriginFromIdentifier(origin_id); +} + +FilePath OriginToFullFilePath(const FilePath& directory, + const GURL& origin) { + return directory.Append(DomStorageArea::DatabaseFileNameFromOrigin(origin)); +} + +GURL FilePathToOrigin(const FilePath& path) { + DCHECK(path.MatchesExtension(DomStorageArea::kDatabaseFileExtension)); + return OriginIdToGURL( + webkit_glue::FilePathToWebString(path.BaseName().RemoveExtension())); +} + +void InvokeAllStorageFilesCallbackHelper( + const DOMStorageContext::GetAllStorageFilesCallback& callback, + const std::vector<FilePath>& file_paths) { + callback.Run(file_paths); +} + +void GetAllStorageFilesHelper( + base::MessageLoopProxy* reply_loop, + DomStorageContext* context, + const DOMStorageContext::GetAllStorageFilesCallback& callback) { + std::vector<DomStorageContext::UsageInfo> infos; + context->GetUsageInfo(&infos); + + std::vector<FilePath> paths; + for (size_t i = 0; i < infos.size(); ++i) { + paths.push_back( + OriginToFullFilePath(context->directory(), infos[i].origin)); + } + + reply_loop->PostTask( + FROM_HERE, + base::Bind(&InvokeAllStorageFilesCallbackHelper, + callback, paths)); +} + +} + +DOMStorageContextImpl::DOMStorageContextImpl( + const FilePath& data_path, + quota::SpecialStoragePolicy* special_storage_policy) { + base::SequencedWorkerPool* worker_pool = BrowserThread::GetBlockingPool(); + context_ = new dom_storage::DomStorageContext( + data_path.empty() ? + data_path : data_path.AppendASCII(kLocalStorageDirectory), + special_storage_policy, + new DomStorageWorkerPoolTaskRunner( + worker_pool, + worker_pool->GetNamedSequenceToken("dom_storage"), + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); +} + +DOMStorageContextImpl::~DOMStorageContextImpl() { +} + +void DOMStorageContextImpl::GetAllStorageFiles( + const GetAllStorageFilesCallback& callback) { + DCHECK(context_); + context_->task_runner()->PostTask( + FROM_HERE, + base::Bind(&GetAllStorageFilesHelper, + base::MessageLoopProxy::current(), + context_, callback)); +} + +FilePath DOMStorageContextImpl::GetFilePath(const string16& origin_id) const { + DCHECK(context_); + return OriginToFullFilePath(context_->directory(), OriginIdToGURL(origin_id)); +} + +void DOMStorageContextImpl::DeleteForOrigin(const string16& origin_id) { + DCHECK(context_); + context_->task_runner()->PostTask( + FROM_HERE, + base::Bind(&DomStorageContext::DeleteOrigin, context_, + OriginIdToGURL(origin_id))); +} + +void DOMStorageContextImpl::DeleteLocalStorageFile(const FilePath& file_path) { + DCHECK(context_); + context_->task_runner()->PostTask( + FROM_HERE, + base::Bind(&DomStorageContext::DeleteOrigin, context_, + FilePathToOrigin(file_path))); +} + +void DOMStorageContextImpl::DeleteDataModifiedSince(const base::Time& cutoff) { + DCHECK(context_); + context_->task_runner()->PostTask( + FROM_HERE, + base::Bind(&DomStorageContext::DeleteDataModifiedSince, context_, + cutoff)); +} + +void DOMStorageContextImpl::PurgeMemory() { + DCHECK(context_); + context_->task_runner()->PostTask( + FROM_HERE, + base::Bind(&DomStorageContext::PurgeMemory, context_)); +} + +void DOMStorageContextImpl::SetClearLocalState(bool clear_local_state) { + DCHECK(context_); + context_->task_runner()->PostTask( + FROM_HERE, + base::Bind(&DomStorageContext::SetClearLocalState, context_, + clear_local_state)); +} + +void DOMStorageContextImpl::SaveSessionState() { + DCHECK(context_); + context_->task_runner()->PostTask( + FROM_HERE, + base::Bind(&DomStorageContext::SaveSessionState, context_)); +} + +void DOMStorageContextImpl::Shutdown() { + DCHECK(context_); + context_->task_runner()->PostTask( + FROM_HERE, + base::Bind(&DomStorageContext::Shutdown, context_)); +} + +int64 DOMStorageContextImpl::LeakyCloneSessionStorage( + int64 existing_namespace_id) { + DCHECK(context_); + int64 clone_id = context_->AllocateSessionId(); + context_->task_runner()->PostTask( + FROM_HERE, + base::Bind(&DomStorageContext::CloneSessionNamespace, context_, + existing_namespace_id, clone_id)); + return clone_id; +} + +#endif // ENABLE_NEW_DOM_STORAGE_BACKEND diff --git a/content/browser/dom_storage/dom_storage_context_impl_new.h b/content/browser/dom_storage/dom_storage_context_impl_new.h new file mode 100644 index 0000000..6f51f35 --- /dev/null +++ b/content/browser/dom_storage/dom_storage_context_impl_new.h @@ -0,0 +1,75 @@ +// 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. + +#ifndef CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_IMPL_H_ +#define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_IMPL_H_ +#pragma once + +#include "base/file_path.h" +#include "base/memory/ref_counted.h" +#include "base/string16.h" +#include "base/time.h" +#include "content/public/browser/dom_storage_context.h" +#include "webkit/dom_storage/dom_storage_types.h" + +#ifdef ENABLE_NEW_DOM_STORAGE_BACKEND + +namespace dom_storage { +class DomStorageContext; +} + +namespace quota { +class SpecialStoragePolicy; +} + +// This is owned by BrowserContext (aka Profile) and encapsulates all +// per-profile dom storage state. +class CONTENT_EXPORT DOMStorageContextImpl : + NON_EXPORTED_BASE(public content::DOMStorageContext), + public base::RefCountedThreadSafe<DOMStorageContextImpl> { + public: + // If |data_path| is empty, nothing will be saved to disk. + DOMStorageContextImpl(const FilePath& data_path, + quota::SpecialStoragePolicy* special_storage_policy); + + // DOMStorageContext implementation. + virtual void GetAllStorageFiles( + const GetAllStorageFilesCallback& callback) OVERRIDE; + virtual FilePath GetFilePath(const string16& origin_id) const OVERRIDE; + virtual void DeleteForOrigin(const string16& origin_id) OVERRIDE; + virtual void DeleteLocalStorageFile(const FilePath& file_path) OVERRIDE; + virtual void DeleteDataModifiedSince(const base::Time& cutoff) OVERRIDE; + + // Called to free up memory that's not strictly needed. + void PurgeMemory(); + + // Used by content settings to alter the behavior around + // what data to keep and what data to discard at shutdown. + // The policy is not so straight forward to describe, see + // the implementation for details. + void SetClearLocalState(bool clear_local_state); + void SaveSessionState(); + + // Called when the BrowserContext/Profile is going away. + void Shutdown(); + + // See render_message_filter.cc for details. + // TODO(michaeln): Remove this method when that bug is fixed. + int64 LeakyCloneSessionStorage(int64 existing_namespace_id); + + private: + friend class DOMStorageMessageFilter; // for access to context() + friend class SessionStorageNamespaceImpl; // ditto + friend class base::RefCountedThreadSafe<DOMStorageContextImpl>; + + virtual ~DOMStorageContextImpl(); + dom_storage::DomStorageContext* context() const { return context_.get(); } + + scoped_refptr<dom_storage::DomStorageContext> context_; + + DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageContextImpl); +}; + +#endif // ENABLE_NEW_DOM_STORAGE_BACKEND +#endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_IMPL_H_ |