Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: content/browser/dom_storage/dom_storage_area.h

Issue 1953703004: Purge browser cache for dom storage in a smarter way (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dom_storage
Patch Set: Add unittest. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 friend class DOMStorageAreaTest; 110 friend class DOMStorageAreaTest;
110 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, DOMStorageAreaBasics); 111 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, DOMStorageAreaBasics);
111 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, BackingDatabaseOpened); 112 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, BackingDatabaseOpened);
112 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, TestDatabaseFilePath); 113 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, TestDatabaseFilePath);
113 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, CommitTasks); 114 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, CommitTasks);
114 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, CommitChangesAtShutdown); 115 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, CommitChangesAtShutdown);
115 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, DeleteOrigin); 116 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, DeleteOrigin);
116 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, PurgeMemory); 117 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, PurgeMemory);
117 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, RateLimiter); 118 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, RateLimiter);
118 FRIEND_TEST_ALL_PREFIXES(DOMStorageContextImplTest, PersistentIds); 119 FRIEND_TEST_ALL_PREFIXES(DOMStorageContextImplTest, PersistentIds);
120 FRIEND_TEST_ALL_PREFIXES(DOMStorageContextImplTest, PurgeMemory);
119 friend class base::RefCountedThreadSafe<DOMStorageArea>; 121 friend class base::RefCountedThreadSafe<DOMStorageArea>;
120 122
121 // Used to rate limit commits. 123 // Used to rate limit commits.
122 class CONTENT_EXPORT RateLimiter { 124 class CONTENT_EXPORT RateLimiter {
123 public: 125 public:
124 RateLimiter(size_t desired_rate, base::TimeDelta time_quantum); 126 RateLimiter(size_t desired_rate, base::TimeDelta time_quantum);
125 127
126 void add_samples(size_t samples) { 128 void add_samples(size_t samples) {
127 samples_ += samples; 129 samples_ += samples;
128 } 130 }
129 131
130 // Computes the total time needed to process the total samples seen 132 // Computes the total time needed to process the total samples seen
131 // at the desired rate. 133 // at the desired rate.
132 base::TimeDelta ComputeTimeNeeded() const; 134 base::TimeDelta ComputeTimeNeeded() const;
133 135
134 // Given the elapsed time since the start of the rate limiting session, 136 // Given the elapsed time since the start of the rate limiting session,
135 // computes the delay needed to mimic having processed the total samples 137 // computes the delay needed to mimic having processed the total samples
136 // seen at the desired rate. 138 // seen at the desired rate.
137 base::TimeDelta ComputeDelayNeeded( 139 base::TimeDelta ComputeDelayNeeded(
138 const base::TimeDelta elapsed_time) const; 140 const base::TimeDelta elapsed_time) const;
139 141
140 private: 142 private:
141 float rate_; 143 float rate_;
142 float samples_; 144 float samples_;
143 base::TimeDelta time_quantum_; 145 base::TimeDelta time_quantum_;
144 }; 146 };
145 147
146 struct CommitBatch { 148 struct CommitBatch {
michaeln 2016/05/16 21:34:39 needs a CONTENT_EXPORT here now
ssid 2016/05/16 23:02:26 Done.
147 bool clear_all_first; 149 bool clear_all_first;
148 DOMStorageValuesMap changed_values; 150 DOMStorageValuesMap changed_values;
149 151
150 CommitBatch(); 152 CommitBatch();
151 ~CommitBatch(); 153 ~CommitBatch();
152 size_t GetDataSize() const; 154 size_t GetDataSize() const;
153 }; 155 };
154 156
155 ~DOMStorageArea(); 157 ~DOMStorageArea();
156 158
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 base::TimeTicks start_time_; 191 base::TimeTicks start_time_;
190 RateLimiter data_rate_limiter_; 192 RateLimiter data_rate_limiter_;
191 RateLimiter commit_rate_limiter_; 193 RateLimiter commit_rate_limiter_;
192 194
193 DISALLOW_COPY_AND_ASSIGN(DOMStorageArea); 195 DISALLOW_COPY_AND_ASSIGN(DOMStorageArea);
194 }; 196 };
195 197
196 } // namespace content 198 } // namespace content
197 199
198 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_AREA_H_ 200 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_AREA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698