Index: webkit/dom_storage/dom_storage_namespace.h |
=================================================================== |
--- webkit/dom_storage/dom_storage_namespace.h (revision 0) |
+++ webkit/dom_storage/dom_storage_namespace.h (working copy) |
@@ -1,83 +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_NAMESPACE_H_ |
-#define CONTENT_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_NAMESPACE_H_ |
+#ifndef WEBKIT_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_ |
+#define WEBKIT_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_ |
#pragma once |
-#include "base/hash_tables.h" |
-#include "base/memory/scoped_ptr.h" |
-#include "base/string16.h" |
-#include "content/common/dom_storage_common.h" |
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
+#include <map> |
-class DOMStorageArea; |
-class DOMStorageContext; |
-class FilePath; |
+#include "base/basictypes.h" |
+#include "base/file_path.h" |
+#include "base/memory/ref_counted.h" |
+#include "webkit/dom_storage/dom_storage_area.h" |
-namespace WebKit { |
-class WebStorageArea; |
-class WebStorageNamespace; |
-} |
+class GURL; |
-// Only to be used on the WebKit thread. |
-class DOMStorageNamespace { |
- public: |
- static DOMStorageNamespace* CreateLocalStorageNamespace( |
- DOMStorageContext* dom_storage_context, const FilePath& data_dir_path); |
- static DOMStorageNamespace* CreateSessionStorageNamespace( |
- DOMStorageContext* dom_storage_context, int64 namespace_id); |
+namespace dom_storage { |
- ~DOMStorageNamespace(); |
+class DomStorageArea; |
+class DomStorageTaskRunner; |
- DOMStorageArea* GetStorageArea(const string16& origin); |
- DOMStorageNamespace* Copy(int64 clone_namespace_id); |
+// Container for the set of per-origin Areas. |
+// See class comments for DomStorageContext for a larger overview. |
+class DomStorageNamespace |
+ : public base::RefCountedThreadSafe<DomStorageNamespace> { |
+ public: |
+ // Constructor for a LocalStorage namespace with id of 0 |
+ // and an optional backing directory on disk. |
benm (inactive)
2012/02/03 16:04:00
The only case I can think of where there would be
|
+ DomStorageNamespace(const FilePath& directory, // may be empty |
+ DomStorageTaskRunner* task_runner); |
- void PurgeMemory(); |
+ // Constructor for a SessionStorage namespace with a non-zero id |
+ // and no backing directory on disk. |
+ DomStorageNamespace(int64 namespace_id, |
+ DomStorageTaskRunner* task_runner); |
- const DOMStorageContext* dom_storage_context() const { |
- return dom_storage_context_; |
- } |
- int64 id() const { return id_; } |
- const WebKit::WebString& data_dir_path() const { return data_dir_path_; } |
- DOMStorageType dom_storage_type() const { return dom_storage_type_; } |
+ int64 namespace_id() const { return namespace_id_; } |
- // Creates a WebStorageArea for the given origin. This should only be called |
- // by an owned DOMStorageArea. |
- WebKit::WebStorageArea* CreateWebStorageArea(const string16& origin); |
+ // Returns the storage area for the given origin, |
+ // creating instance if needed. Each call to open |
+ // must be balanced with a call to CloseStorageArea. |
+ DomStorageArea* OpenStorageArea(const GURL& origin); |
+ void CloseStorageArea(DomStorageArea* area); |
+ // Creates a clone of |this| namespace including |
+ // shallow copies of all contained areas. |
+ // Should only be called for session storage namespaces. |
+ DomStorageNamespace* Clone(int64 clone_namespace_id); |
+ |
private: |
- // Called by the static factory methods above. |
- DOMStorageNamespace(DOMStorageContext* dom_storage_context, |
- int64 id, |
- const WebKit::WebString& data_dir_path, |
- DOMStorageType storage_type); |
+ // Struct to hold a references to our contained areas and |
benm (inactive)
2012/02/03 16:04:00
nit: no 'a'
michaeln
2012/02/03 20:15:57
Done.
|
+ // to keep track of how many tabs have a given area open. |
+ struct AreaHolder { |
+ scoped_refptr<DomStorageArea> area_; |
+ int open_count_; |
+ AreaHolder(); |
+ AreaHolder(DomStorageArea* area, int count); |
+ ~AreaHolder(); |
+ }; |
+ typedef std::map<GURL, AreaHolder> AreaMap; |
- // Creates the underlying WebStorageNamespace on demand. |
- void CreateWebStorageNamespaceIfNecessary(); |
+ // Returns a pointer to the area holder in our map or NULL. |
+ AreaHolder* GetAreaHolder(const GURL& origin); |
- // All the storage areas we own. |
- typedef base::hash_map<string16, DOMStorageArea*> OriginToStorageAreaMap; |
- OriginToStorageAreaMap origin_to_storage_area_; |
+ int64 namespace_id_; |
+ FilePath directory_; |
+ AreaMap areas_; |
+ scoped_refptr<DomStorageTaskRunner> task_runner_; |
+}; |
- // The DOMStorageContext that owns us. |
- DOMStorageContext* dom_storage_context_; |
+} // namespace dom_storage |
- // The WebKit storage namespace we manage. |
- scoped_ptr<WebKit::WebStorageNamespace> storage_namespace_; |
- // Our id. Unique to our parent WebKitContext class. |
- int64 id_; |
- |
- // The path used to create us, so we can recreate our WebStorageNamespace on |
- // demand. |
- WebKit::WebString data_dir_path_; |
- |
- // SessionStorage vs. LocalStorage. |
- const DOMStorageType dom_storage_type_; |
- |
- DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageNamespace); |
-}; |
- |
-#endif // CONTENT_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_NAMESPACE_H_ |
+#endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_ |