OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_AREA_H_ | 5 #ifndef CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_AREA_H_ |
6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_AREA_H_ | 6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_AREA_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <memory> | 11 #include <memory> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/strings/nullable_string16.h" | 18 #include "base/strings/nullable_string16.h" |
19 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
20 #include "content/common/content_export.h" | 20 #include "content/common/content_export.h" |
| 21 #include "content/common/dom_storage/dom_storage_map.h" |
21 #include "content/common/dom_storage/dom_storage_types.h" | 22 #include "content/common/dom_storage/dom_storage_types.h" |
22 #include "url/gurl.h" | 23 #include "url/gurl.h" |
23 | 24 |
24 namespace base { | 25 namespace base { |
25 namespace trace_event { | 26 namespace trace_event { |
26 class ProcessMemoryDump; | 27 class ProcessMemoryDump; |
27 } | 28 } |
28 } | 29 } |
29 | 30 |
30 namespace content { | 31 namespace content { |
31 | 32 |
32 class DOMStorageDatabaseAdapter; | 33 class DOMStorageDatabaseAdapter; |
33 class DOMStorageMap; | |
34 class DOMStorageTaskRunner; | 34 class DOMStorageTaskRunner; |
35 class SessionStorageDatabase; | 35 class SessionStorageDatabase; |
36 | 36 |
37 // Container for a per-origin Map of key/value pairs potentially | 37 // Container for a per-origin Map of key/value pairs potentially |
38 // backed by storage on disk and lazily commits changes to disk. | 38 // backed by storage on disk and lazily commits changes to disk. |
39 // See class comments for DOMStorageContextImpl for a larger overview. | 39 // See class comments for DOMStorageContextImpl for a larger overview. |
40 class CONTENT_EXPORT DOMStorageArea | 40 class CONTENT_EXPORT DOMStorageArea |
41 : public base::RefCountedThreadSafe<DOMStorageArea> { | 41 : public base::RefCountedThreadSafe<DOMStorageArea> { |
42 | 42 |
43 public: | 43 public: |
(...skipping 14 matching lines...) Expand all Loading... |
58 | 58 |
59 // Session storage. Backed on disk if |session_storage_backing| is not NULL. | 59 // Session storage. Backed on disk if |session_storage_backing| is not NULL. |
60 DOMStorageArea(int64_t namespace_id, | 60 DOMStorageArea(int64_t namespace_id, |
61 const std::string& persistent_namespace_id, | 61 const std::string& persistent_namespace_id, |
62 const GURL& origin, | 62 const GURL& origin, |
63 SessionStorageDatabase* session_storage_backing, | 63 SessionStorageDatabase* session_storage_backing, |
64 DOMStorageTaskRunner* task_runner); | 64 DOMStorageTaskRunner* task_runner); |
65 | 65 |
66 const GURL& origin() const { return origin_; } | 66 const GURL& origin() const { return origin_; } |
67 int64_t namespace_id() const { return namespace_id_; } | 67 int64_t namespace_id() const { return namespace_id_; } |
| 68 size_t map_usage_in_bytes() const { return map_ ? map_->bytes_used() : 0; } |
68 | 69 |
69 // Writes a copy of the current set of values in the area to the |map|. | 70 // Writes a copy of the current set of values in the area to the |map|. |
70 void ExtractValues(DOMStorageValuesMap* map); | 71 void ExtractValues(DOMStorageValuesMap* map); |
71 | 72 |
72 unsigned Length(); | 73 unsigned Length(); |
73 base::NullableString16 Key(unsigned index); | 74 base::NullableString16 Key(unsigned index); |
74 base::NullableString16 GetItem(const base::string16& key); | 75 base::NullableString16 GetItem(const base::string16& key); |
75 bool SetItem(const base::string16& key, const base::string16& value, | 76 bool SetItem(const base::string16& key, const base::string16& value, |
76 base::NullableString16* old_value); | 77 base::NullableString16* old_value); |
77 bool RemoveItem(const base::string16& key, base::string16* old_value); | 78 bool RemoveItem(const base::string16& key, base::string16* old_value); |
78 bool Clear(); | 79 bool Clear(); |
79 void FastClear(); | 80 void FastClear(); |
80 | 81 |
81 DOMStorageArea* ShallowCopy( | 82 DOMStorageArea* ShallowCopy( |
82 int64_t destination_namespace_id, | 83 int64_t destination_namespace_id, |
83 const std::string& destination_persistent_namespace_id); | 84 const std::string& destination_persistent_namespace_id); |
84 | 85 |
85 bool HasUncommittedChanges() const; | 86 bool HasUncommittedChanges() const; |
86 void ScheduleImmediateCommit(); | 87 void ScheduleImmediateCommit(); |
87 | 88 |
88 // Similar to Clear() but more optimized for just deleting | 89 // Similar to Clear() but more optimized for just deleting |
89 // without raising events. | 90 // without raising events. |
90 void DeleteOrigin(); | 91 void DeleteOrigin(); |
91 | 92 |
| 93 void TrimDatabase(); |
| 94 |
92 // Frees up memory when possible. Typically, this method returns | 95 // Frees up memory when possible. Typically, this method returns |
93 // the object to its just constructed state, however if uncommitted | 96 // the object to its just constructed state, however if uncommitted |
94 // changes are pending, it does nothing. | 97 // changes are pending, it does nothing. |
95 void PurgeMemory(); | 98 void PurgeMemory(); |
96 | 99 |
97 // Schedules the commit of any unsaved changes and enters a | 100 // Schedules the commit of any unsaved changes and enters a |
98 // shutdown state such that the value getters and setters will | 101 // shutdown state such that the value getters and setters will |
99 // no longer do anything. | 102 // no longer do anything. |
100 void Shutdown(); | 103 void Shutdown(); |
101 | 104 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 base::TimeTicks start_time_; | 192 base::TimeTicks start_time_; |
190 RateLimiter data_rate_limiter_; | 193 RateLimiter data_rate_limiter_; |
191 RateLimiter commit_rate_limiter_; | 194 RateLimiter commit_rate_limiter_; |
192 | 195 |
193 DISALLOW_COPY_AND_ASSIGN(DOMStorageArea); | 196 DISALLOW_COPY_AND_ASSIGN(DOMStorageArea); |
194 }; | 197 }; |
195 | 198 |
196 } // namespace content | 199 } // namespace content |
197 | 200 |
198 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_AREA_H_ | 201 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_AREA_H_ |
OLD | NEW |