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_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_ | 5 #ifndef WEBKIT_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_ |
6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_ | 6 #define WEBKIT_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/storage/webkit_storage_export.h" | 13 #include "webkit/storage/webkit_storage_export.h" |
14 | 14 |
15 class GURL; | 15 class GURL; |
16 | 16 |
17 namespace dom_storage { | 17 namespace dom_storage { |
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 DomStorageContext for a larger overview. |
25 class WEBKIT_STORAGE_EXPORT DomStorageNamespace | 25 class WEBKIT_STORAGE_EXPORT DomStorageNamespace |
26 : public base::RefCountedThreadSafe<DomStorageNamespace> { | 26 : public base::RefCountedThreadSafe<DomStorageNamespace> { |
27 public: | 27 public: |
| 28 // Option for PurgeMemory. |
| 29 enum PurgeOption { |
| 30 // Purge unopened areas only. |
| 31 PURGE_UNOPENED, |
| 32 |
| 33 // Purge aggressively, i.e. discard cache even for areas that have |
| 34 // non-zero open count. |
| 35 PURGE_AGGRESSIVE, |
| 36 }; |
| 37 |
28 // Constructor for a LocalStorage namespace with id of 0 | 38 // Constructor for a LocalStorage namespace with id of 0 |
29 // and an optional backing directory on disk. | 39 // and an optional backing directory on disk. |
30 DomStorageNamespace(const base::FilePath& directory, // may be empty | 40 DomStorageNamespace(const base::FilePath& directory, // may be empty |
31 DomStorageTaskRunner* task_runner); | 41 DomStorageTaskRunner* task_runner); |
32 | 42 |
33 // 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 |
34 // optional backing on disk via |session_storage_database| (may be NULL). | 44 // optional backing on disk via |session_storage_database| (may be NULL). |
35 DomStorageNamespace(int64 namespace_id, | 45 DomStorageNamespace(int64 namespace_id, |
36 const std::string& persistent_namespace_id, | 46 const std::string& persistent_namespace_id, |
37 SessionStorageDatabase* session_storage_database, | 47 SessionStorageDatabase* session_storage_database, |
(...skipping 14 matching lines...) Expand all Loading... |
52 DomStorageArea* GetOpenStorageArea(const GURL& origin); | 62 DomStorageArea* GetOpenStorageArea(const GURL& origin); |
53 | 63 |
54 // Creates a clone of |this| namespace including | 64 // Creates a clone of |this| namespace including |
55 // shallow copies of all contained areas. | 65 // shallow copies of all contained areas. |
56 // Should only be called for session storage namespaces. | 66 // Should only be called for session storage namespaces. |
57 DomStorageNamespace* Clone(int64 clone_namespace_id, | 67 DomStorageNamespace* Clone(int64 clone_namespace_id, |
58 const std::string& clone_persistent_namespace_id); | 68 const std::string& clone_persistent_namespace_id); |
59 | 69 |
60 void DeleteLocalStorageOrigin(const GURL& origin); | 70 void DeleteLocalStorageOrigin(const GURL& origin); |
61 void DeleteSessionStorageOrigin(const GURL& origin); | 71 void DeleteSessionStorageOrigin(const GURL& origin); |
62 void PurgeMemory(); | 72 void PurgeMemory(PurgeOption purge); |
63 void Shutdown(); | 73 void Shutdown(); |
64 | 74 |
| 75 unsigned int CountInMemoryAreas() const; |
| 76 |
65 private: | 77 private: |
66 friend class base::RefCountedThreadSafe<DomStorageNamespace>; | 78 friend class base::RefCountedThreadSafe<DomStorageNamespace>; |
67 | 79 |
68 // Struct to hold references to our contained areas and | 80 // Struct to hold references to our contained areas and |
69 // 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. |
70 struct AreaHolder { | 82 struct AreaHolder { |
71 scoped_refptr<DomStorageArea> area_; | 83 scoped_refptr<DomStorageArea> area_; |
72 int open_count_; | 84 int open_count_; |
73 AreaHolder(); | 85 AreaHolder(); |
74 AreaHolder(DomStorageArea* area, int count); | 86 AreaHolder(DomStorageArea* area, int count); |
(...skipping 11 matching lines...) Expand all Loading... |
86 base::FilePath directory_; | 98 base::FilePath directory_; |
87 AreaMap areas_; | 99 AreaMap areas_; |
88 scoped_refptr<DomStorageTaskRunner> task_runner_; | 100 scoped_refptr<DomStorageTaskRunner> task_runner_; |
89 scoped_refptr<SessionStorageDatabase> session_storage_database_; | 101 scoped_refptr<SessionStorageDatabase> session_storage_database_; |
90 }; | 102 }; |
91 | 103 |
92 } // namespace dom_storage | 104 } // namespace dom_storage |
93 | 105 |
94 | 106 |
95 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_ | 107 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_ |
OLD | NEW |