OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef WEBKIT_BROWSER_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_ | 5 #ifndef CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_ |
6 #define WEBKIT_BROWSER_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_ | 6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "webkit/browser/webkit_storage_browser_export.h" | 13 #include "content/common/content_export.h" |
14 | 14 |
15 class GURL; | 15 class GURL; |
16 | 16 |
17 namespace dom_storage { | 17 namespace content { |
18 | 18 |
19 class DomStorageArea; | 19 class DOMStorageArea; |
20 class DomStorageTaskRunner; | 20 class DOMStorageTaskRunner; |
21 class SessionStorageDatabase; | 21 class SessionStorageDatabase; |
22 | 22 |
23 // Container for the set of per-origin Areas. | 23 // Container for the set of per-origin Areas. |
24 // See class comments for DomStorageContext for a larger overview. | 24 // See class comments for DOMStorageContextImpl for a larger overview. |
25 class WEBKIT_STORAGE_BROWSER_EXPORT DomStorageNamespace | 25 class CONTENT_EXPORT DOMStorageNamespace |
26 : public base::RefCountedThreadSafe<DomStorageNamespace> { | 26 : public base::RefCountedThreadSafe<DOMStorageNamespace> { |
27 public: | 27 public: |
28 // Option for PurgeMemory. | 28 // Option for PurgeMemory. |
29 enum PurgeOption { | 29 enum PurgeOption { |
30 // Purge unopened areas only. | 30 // Purge unopened areas only. |
31 PURGE_UNOPENED, | 31 PURGE_UNOPENED, |
32 | 32 |
33 // Purge aggressively, i.e. discard cache even for areas that have | 33 // Purge aggressively, i.e. discard cache even for areas that have |
34 // non-zero open count. | 34 // non-zero open count. |
35 PURGE_AGGRESSIVE, | 35 PURGE_AGGRESSIVE, |
36 }; | 36 }; |
37 | 37 |
38 // Constructor for a LocalStorage namespace with id of 0 | 38 // Constructor for a LocalStorage namespace with id of 0 |
39 // and an optional backing directory on disk. | 39 // and an optional backing directory on disk. |
40 DomStorageNamespace(const base::FilePath& directory, // may be empty | 40 DOMStorageNamespace(const base::FilePath& directory, // may be empty |
41 DomStorageTaskRunner* task_runner); | 41 DOMStorageTaskRunner* task_runner); |
42 | 42 |
43 // Constructor for a SessionStorage namespace with a non-zero id and an | 43 // Constructor for a SessionStorage namespace with a non-zero id and an |
44 // optional backing on disk via |session_storage_database| (may be NULL). | 44 // optional backing on disk via |session_storage_database| (may be NULL). |
45 DomStorageNamespace(int64 namespace_id, | 45 DOMStorageNamespace(int64 namespace_id, |
46 const std::string& persistent_namespace_id, | 46 const std::string& persistent_namespace_id, |
47 SessionStorageDatabase* session_storage_database, | 47 SessionStorageDatabase* session_storage_database, |
48 DomStorageTaskRunner* task_runner); | 48 DOMStorageTaskRunner* task_runner); |
49 | 49 |
50 int64 namespace_id() const { return namespace_id_; } | 50 int64 namespace_id() const { return namespace_id_; } |
51 const std::string& persistent_namespace_id() const { | 51 const std::string& persistent_namespace_id() const { |
52 return persistent_namespace_id_; | 52 return persistent_namespace_id_; |
53 } | 53 } |
54 | 54 |
55 // Returns the storage area for the given origin, | 55 // Returns the storage area for the given origin, |
56 // creating instance if needed. Each call to open | 56 // creating instance if needed. Each call to open |
57 // must be balanced with a call to CloseStorageArea. | 57 // must be balanced with a call to CloseStorageArea. |
58 DomStorageArea* OpenStorageArea(const GURL& origin); | 58 DOMStorageArea* OpenStorageArea(const GURL& origin); |
59 void CloseStorageArea(DomStorageArea* area); | 59 void CloseStorageArea(DOMStorageArea* area); |
60 | 60 |
61 // Returns the area for |origin| if it's open, otherwise NULL. | 61 // Returns the area for |origin| if it's open, otherwise NULL. |
62 DomStorageArea* GetOpenStorageArea(const GURL& origin); | 62 DOMStorageArea* GetOpenStorageArea(const GURL& origin); |
63 | 63 |
64 // Creates a clone of |this| namespace including | 64 // Creates a clone of |this| namespace including |
65 // shallow copies of all contained areas. | 65 // shallow copies of all contained areas. |
66 // Should only be called for session storage namespaces. | 66 // Should only be called for session storage namespaces. |
67 DomStorageNamespace* Clone(int64 clone_namespace_id, | 67 DOMStorageNamespace* Clone(int64 clone_namespace_id, |
68 const std::string& clone_persistent_namespace_id); | 68 const std::string& clone_persistent_namespace_id); |
69 | 69 |
70 void DeleteLocalStorageOrigin(const GURL& origin); | 70 void DeleteLocalStorageOrigin(const GURL& origin); |
71 void DeleteSessionStorageOrigin(const GURL& origin); | 71 void DeleteSessionStorageOrigin(const GURL& origin); |
72 void PurgeMemory(PurgeOption purge); | 72 void PurgeMemory(PurgeOption purge); |
73 void Shutdown(); | 73 void Shutdown(); |
74 | 74 |
75 unsigned int CountInMemoryAreas() const; | 75 unsigned int CountInMemoryAreas() const; |
76 | 76 |
77 private: | 77 private: |
78 friend class base::RefCountedThreadSafe<DomStorageNamespace>; | 78 friend class base::RefCountedThreadSafe<DOMStorageNamespace>; |
79 | 79 |
80 // Struct to hold references to our contained areas and | 80 // Struct to hold references to our contained areas and |
81 // to keep track of how many tabs have a given area open. | 81 // to keep track of how many tabs have a given area open. |
82 struct AreaHolder { | 82 struct AreaHolder { |
83 scoped_refptr<DomStorageArea> area_; | 83 scoped_refptr<DOMStorageArea> area_; |
84 int open_count_; | 84 int open_count_; |
85 AreaHolder(); | 85 AreaHolder(); |
86 AreaHolder(DomStorageArea* area, int count); | 86 AreaHolder(DOMStorageArea* area, int count); |
87 ~AreaHolder(); | 87 ~AreaHolder(); |
88 }; | 88 }; |
89 typedef std::map<GURL, AreaHolder> AreaMap; | 89 typedef std::map<GURL, AreaHolder> AreaMap; |
90 | 90 |
91 ~DomStorageNamespace(); | 91 ~DOMStorageNamespace(); |
92 | 92 |
93 // Returns a pointer to the area holder in our map or NULL. | 93 // Returns a pointer to the area holder in our map or NULL. |
94 AreaHolder* GetAreaHolder(const GURL& origin); | 94 AreaHolder* GetAreaHolder(const GURL& origin); |
95 | 95 |
96 int64 namespace_id_; | 96 int64 namespace_id_; |
97 std::string persistent_namespace_id_; | 97 std::string persistent_namespace_id_; |
98 base::FilePath directory_; | 98 base::FilePath directory_; |
99 AreaMap areas_; | 99 AreaMap areas_; |
100 scoped_refptr<DomStorageTaskRunner> task_runner_; | 100 scoped_refptr<DOMStorageTaskRunner> task_runner_; |
101 scoped_refptr<SessionStorageDatabase> session_storage_database_; | 101 scoped_refptr<SessionStorageDatabase> session_storage_database_; |
102 }; | 102 }; |
103 | 103 |
104 } // namespace dom_storage | 104 } // namespace content |
105 | 105 |
106 | 106 |
107 #endif // WEBKIT_BROWSER_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_ | 107 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_ |
OLD | NEW |