Index: content/browser/dom_storage/dom_storage_context_impl_new.h |
=================================================================== |
--- content/browser/dom_storage/dom_storage_context_impl_new.h (revision 127025) |
+++ content/browser/dom_storage/dom_storage_context_impl_new.h (working copy) |
@@ -1,170 +1,75 @@ |
-// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// 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_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_IMPL_H_ |
-#define CONTENT_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_IMPL_H_ |
+#ifndef CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_IMPL_H_ |
+#define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_IMPL_H_ |
#pragma once |
-#include <map> |
-#include <set> |
- |
-#include "base/compiler_specific.h" |
#include "base/file_path.h" |
-#include "base/gtest_prod_util.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" |
-class DOMStorageArea; |
-class DOMStorageMessageFilter; |
-class DOMStorageNamespace; |
+#ifdef ENABLE_NEW_DOM_STORAGE_BACKEND |
-namespace base { |
-class MessageLoopProxy; |
-class SequencedTaskRunner; |
+namespace dom_storage { |
+class DomStorageContext; |
} |
namespace quota { |
class SpecialStoragePolicy; |
} |
-// This is owned by BrowserContext and is all the dom storage information that's |
-// shared by all the DOMStorageMessageFilters that share the same browser |
-// context. The specifics of responsibilities are fairly well documented here |
-// and in StorageNamespace and StorageArea. Everything is only to be accessed |
-// on the WebKit thread unless noted otherwise. |
+// 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) { |
+ 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); |
- virtual ~DOMStorageContextImpl(); |
- // DOMStorageContext implementation: |
- virtual base::SequencedTaskRunner* task_runner() const OVERRIDE; |
- virtual std::vector<FilePath> GetAllStorageFiles() OVERRIDE; |
+ // 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; |
- // Invalid storage id. No storage session will ever report this value. |
- // Used in DOMStorageMessageFilter::OnStorageAreaId when coping with |
- // interactions with non-existent storage sessions. |
- static const int64 kInvalidStorageId = -1; |
- |
- // Allocate a new storage area id. Only call on the WebKit thread. |
- int64 AllocateStorageAreaId(); |
- |
- // Allocate a new session storage id. Only call on the UI or IO thread. |
- int64 AllocateSessionStorageNamespaceId(); |
- |
- // Clones a session storage namespace and returns the cloned namespaces' id. |
- // Only call on the IO thread. |
- int64 CloneSessionStorage(int64 original_id); |
- |
- // Various storage area methods. The storage area is owned by one of the |
- // namespaces that's owned by this class. |
- void RegisterStorageArea(DOMStorageArea* storage_area); |
- void UnregisterStorageArea(DOMStorageArea* storage_area); |
- DOMStorageArea* GetStorageArea(int64 id); |
- |
- // Called on WebKit thread when a session storage namespace can be deleted. |
- void DeleteSessionStorageNamespace(int64 namespace_id); |
- |
- // Get a namespace from an id. What's returned is owned by this class. If |
- // allocation_allowed is true, then this function will create the storage |
- // namespace if it hasn't been already. |
- DOMStorageNamespace* GetStorageNamespace(int64 id, bool allocation_allowed); |
- |
- // Sometimes an event from one DOM storage message filter requires |
- // communication to all of them. |
- typedef std::set<DOMStorageMessageFilter*> MessageFilterSet; |
- void RegisterMessageFilter(DOMStorageMessageFilter* message_filter); |
- void UnregisterMessageFilter(DOMStorageMessageFilter* MessageFilter); |
- const MessageFilterSet* GetMessageFilterSet() const; |
- |
- // Tells storage namespaces to purge any memory they do not need. |
+ // Called to free up memory that's not strictly needed. |
void PurgeMemory(); |
- // Deletes all local storage files. |
- void DeleteAllLocalStorageFiles(); |
+ // 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(); |
- // The local storage directory. |
- static const FilePath::CharType kLocalStorageDirectory[]; |
+ // Called when the BrowserContext/Profile is going away. |
+ void Shutdown(); |
- // The local storage file extension. |
- static const FilePath::CharType kLocalStorageExtension[]; |
+ // See render_message_filter.cc for details. |
+ // TODO(michaeln): Remove this method when that bug is fixed. |
+ int64 LeakyCloneSessionStorage(int64 existing_namespace_id); |
- void set_clear_local_state_on_exit(bool clear_local_state) { |
- clear_local_state_on_exit_ = clear_local_state; |
- } |
- |
- // Disables the exit-time deletion for all data (also session-only data). |
- void SaveSessionState() { |
- save_session_state_ = true; |
- } |
- |
- void set_data_path_for_testing(const FilePath& data_path) { |
- data_path_ = data_path; |
- } |
- |
private: |
- FRIEND_TEST_ALL_PREFIXES(DOMStorageTest, SessionOnly); |
- FRIEND_TEST_ALL_PREFIXES(DOMStorageTest, SaveSessionState); |
+ friend class DOMStorageMessageFilter; // for access to context() |
+ friend class SessionStorageNamespaceImpl; // ditto |
+ friend class base::RefCountedThreadSafe<DOMStorageContextImpl>; |
- // Get the local storage instance. The object is owned by this class. |
- DOMStorageNamespace* CreateLocalStorage(); |
+ virtual ~DOMStorageContextImpl(); |
+ dom_storage::DomStorageContext* context() const { return context_.get(); } |
- // Get a new session storage namespace. The object is owned by this class. |
- DOMStorageNamespace* CreateSessionStorage(int64 namespace_id); |
+ scoped_refptr<dom_storage::DomStorageContext> context_; |
- // Used internally to register storage namespaces we create. |
- void RegisterStorageNamespace(DOMStorageNamespace* storage_namespace); |
- |
- // The WebKit thread half of CloneSessionStorage above. |
- void CompleteCloningSessionStorage(int64 existing_id, int64 clone_id); |
- |
- // The last used storage_area_id and storage_namespace_id's. For the storage |
- // namespaces, IDs allocated on the UI thread are positive and count up while |
- // IDs allocated on the IO thread are negative and count down. This allows us |
- // to allocate unique IDs on both without any locking. All storage area ids |
- // are allocated on the WebKit thread. |
- int64 last_storage_area_id_; |
- int64 last_session_storage_namespace_id_on_ui_thread_; |
- int64 last_session_storage_namespace_id_on_io_thread_; |
- |
- // True if the destructor should delete its files. |
- bool clear_local_state_on_exit_; |
- |
- // If true, nothing (not even session-only data) should be deleted on exit. |
- bool save_session_state_; |
- |
- // Path where the browser context data is stored. |
- // TODO(pastarmovj): Keep in mind that unlike indexed db data_path_ variable |
- // this one still has to point to the upper level dir because of the |
- // MigrateLocalStorageDirectory function. Once this function disappears we can |
- // make it point directly to the dom storage path. |
- FilePath data_path_; |
- |
- // All the DOMStorageMessageFilters that are attached to us. ONLY USE ON THE |
- // IO THREAD! |
- MessageFilterSet message_filter_set_; |
- |
- // Maps ids to StorageAreas. We do NOT own these objects. StorageNamespace |
- // (which does own them) will notify us when we should remove the entries. |
- typedef std::map<int64, DOMStorageArea*> StorageAreaMap; |
- StorageAreaMap storage_area_map_; |
- |
- // Maps ids to StorageNamespaces. We own these objects. |
- typedef std::map<int64, DOMStorageNamespace*> StorageNamespaceMap; |
- StorageNamespaceMap storage_namespace_map_; |
- |
- scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; |
- scoped_refptr<base::MessageLoopProxy> webkit_message_loop_; |
- |
DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageContextImpl); |
}; |
-#endif // CONTENT_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_IMPL_H_ |
+#endif // ENABLE_NEW_DOM_STORAGE_BACKEND |
+#endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_IMPL_H_ |