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

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

Issue 896643002: [DOMStorage] Rate limiting writes to disk. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/gtest_prod_util.h" 9 #include "base/gtest_prod_util.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, DOMStorageAreaBasics); 88 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, DOMStorageAreaBasics);
89 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, BackingDatabaseOpened); 89 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, BackingDatabaseOpened);
90 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, TestDatabaseFilePath); 90 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, TestDatabaseFilePath);
91 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, CommitTasks); 91 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, CommitTasks);
92 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, CommitChangesAtShutdown); 92 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, CommitChangesAtShutdown);
93 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, DeleteOrigin); 93 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, DeleteOrigin);
94 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, PurgeMemory); 94 FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, PurgeMemory);
95 FRIEND_TEST_ALL_PREFIXES(DOMStorageContextImplTest, PersistentIds); 95 FRIEND_TEST_ALL_PREFIXES(DOMStorageContextImplTest, PersistentIds);
96 friend class base::RefCountedThreadSafe<DOMStorageArea>; 96 friend class base::RefCountedThreadSafe<DOMStorageArea>;
97 97
98 class RateLimiter {
cmumford 2015/02/03 00:45:24 Why not put the implementation of RateLimiter in t
michaeln 2015/02/03 19:59:15 because i wasn't done yet :)
99 public:
100 RateLimiter(size_t desired_rate, base::TimeDelta time_quantum)
101 : rate_(desired_rate),
102 samples_(0),
103 time_quantum_(time_quantum) {
104 DCHECK(desired_rate > 0);
cmumford 2015/02/03 00:45:24 Consider using DCHECK_GT instead of DCHECK(a > b)
michaeln 2015/02/03 19:59:15 Done.
105 }
cmumford 2015/02/03 00:45:24 Indenting looks wrong - Reitveld issue?
106
107 void AddSamples(size_t samples) { samples_ += samples; }
108
109 // Computes the total time needed to process the total samples seen
110 // at the desired rate.
111 base::TimeDelta ComputeTimeNeeded() {
cmumford 2015/02/03 00:45:24 Should this be const?
michaeln 2015/02/03 19:59:14 Done.
112 return base::TimeDelta::FromInternalValue
113 ((samples_ / rate_) * time_quantum_.ToInternalValue());
114 }
115
116 // Given the elapsed time since the start of the rate limiting session,
117 // computes the delay needed to mimic having processed the total samples
118 // seen at the desired rate.
119 base::TimeDelta ComputeDelayNeeded(const base::TimeDelta elapsed_time) {
cmumford 2015/02/03 00:45:24 Should be a static method?
michaeln 2015/02/03 19:59:15 can't be, this uses the instance method ComputeTim
cmumford 2015/02/04 18:43:54 Then it can be const right?
120 base::TimeDelta time_needed = ComputeTimeNeeded();
121 if (time_needed > elapsed_time)
122 return time_needed - elapsed_time;
123 return base::TimeDelta();
124 }
125
126 private:
127 double rate_;
128 double samples_;
129 base::TimeDelta time_quantum_;
130 };
131
98 struct CommitBatch { 132 struct CommitBatch {
99 bool clear_all_first; 133 bool clear_all_first;
100 DOMStorageValuesMap changed_values; 134 DOMStorageValuesMap changed_values;
135
101 CommitBatch(); 136 CommitBatch();
102 ~CommitBatch(); 137 ~CommitBatch();
138 size_t GetDataSize();
cmumford 2015/02/03 00:45:24 const method.
michaeln 2015/02/03 19:59:14 Done.
103 }; 139 };
104 140
105 ~DOMStorageArea(); 141 ~DOMStorageArea();
106 142
107 // If we haven't done so already and this is a local storage area, 143 // If we haven't done so already and this is a local storage area,
108 // will attempt to read any values for this origin currently 144 // will attempt to read any values for this origin currently
109 // stored on disk. 145 // stored on disk.
110 void InitialImportIfNeeded(); 146 void InitialImportIfNeeded();
111 147
112 // Post tasks to defer writing a batch of changed values to 148 // Post tasks to defer writing a batch of changed values to
113 // disk on the commit sequence, and to call back on the primary 149 // disk on the commit sequence, and to call back on the primary
114 // task sequence when complete. 150 // task sequence when complete.
115 CommitBatch* CreateCommitBatchIfNeeded(); 151 CommitBatch* CreateCommitBatchIfNeeded();
116 void OnCommitTimer(); 152 void OnCommitTimer();
117 void CommitChanges(const CommitBatch* commit_batch); 153 void CommitChanges(const CommitBatch* commit_batch);
118 void OnCommitComplete(); 154 void OnCommitComplete();
155 base::TimeDelta ComputeCommitDelay();
cmumford 2015/02/03 00:45:24 const
michaeln 2015/02/03 19:59:14 Done.
119 156
120 void ShutdownInCommitSequence(); 157 void ShutdownInCommitSequence();
121 158
122 int64 namespace_id_; 159 int64 namespace_id_;
123 std::string persistent_namespace_id_; 160 std::string persistent_namespace_id_;
124 GURL origin_; 161 GURL origin_;
125 base::FilePath directory_; 162 base::FilePath directory_;
126 scoped_refptr<DOMStorageTaskRunner> task_runner_; 163 scoped_refptr<DOMStorageTaskRunner> task_runner_;
127 scoped_refptr<DOMStorageMap> map_; 164 scoped_refptr<DOMStorageMap> map_;
128 scoped_ptr<DOMStorageDatabaseAdapter> backing_; 165 scoped_ptr<DOMStorageDatabaseAdapter> backing_;
129 scoped_refptr<SessionStorageDatabase> session_storage_backing_; 166 scoped_refptr<SessionStorageDatabase> session_storage_backing_;
130 bool is_initial_import_done_; 167 bool is_initial_import_done_;
131 bool is_shutdown_; 168 bool is_shutdown_;
132 scoped_ptr<CommitBatch> commit_batch_; 169 scoped_ptr<CommitBatch> commit_batch_;
133 int commit_batches_in_flight_; 170 int commit_batches_in_flight_;
171 base::Time start_time_;
172 RateLimiter data_rate_limiter_;
173 RateLimiter commit_rate_limiter_;
134 }; 174 };
135 175
136 } // namespace content 176 } // namespace content
137 177
138 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_AREA_H_ 178 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_AREA_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/dom_storage/dom_storage_area.cc » ('j') | content/browser/dom_storage/dom_storage_area.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698