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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/dom_storage/dom_storage_area.h
diff --git a/content/browser/dom_storage/dom_storage_area.h b/content/browser/dom_storage/dom_storage_area.h
index ca28be1aa144da7a55a984a3fdf2f1cdc96d50ed..53a7217893eac1a01c5ef86136da2d9cacea7e34 100644
--- a/content/browser/dom_storage/dom_storage_area.h
+++ b/content/browser/dom_storage/dom_storage_area.h
@@ -95,11 +95,47 @@ class CONTENT_EXPORT DOMStorageArea
FRIEND_TEST_ALL_PREFIXES(DOMStorageContextImplTest, PersistentIds);
friend class base::RefCountedThreadSafe<DOMStorageArea>;
+ 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 :)
+ public:
+ RateLimiter(size_t desired_rate, base::TimeDelta time_quantum)
+ : rate_(desired_rate),
+ samples_(0),
+ time_quantum_(time_quantum) {
+ 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.
+ }
cmumford 2015/02/03 00:45:24 Indenting looks wrong - Reitveld issue?
+
+ void AddSamples(size_t samples) { samples_ += samples; }
+
+ // Computes the total time needed to process the total samples seen
+ // at the desired rate.
+ base::TimeDelta ComputeTimeNeeded() {
cmumford 2015/02/03 00:45:24 Should this be const?
michaeln 2015/02/03 19:59:14 Done.
+ return base::TimeDelta::FromInternalValue
+ ((samples_ / rate_) * time_quantum_.ToInternalValue());
+ }
+
+ // Given the elapsed time since the start of the rate limiting session,
+ // computes the delay needed to mimic having processed the total samples
+ // seen at the desired rate.
+ 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?
+ base::TimeDelta time_needed = ComputeTimeNeeded();
+ if (time_needed > elapsed_time)
+ return time_needed - elapsed_time;
+ return base::TimeDelta();
+ }
+
+ private:
+ double rate_;
+ double samples_;
+ base::TimeDelta time_quantum_;
+ };
+
struct CommitBatch {
bool clear_all_first;
DOMStorageValuesMap changed_values;
+
CommitBatch();
~CommitBatch();
+ size_t GetDataSize();
cmumford 2015/02/03 00:45:24 const method.
michaeln 2015/02/03 19:59:14 Done.
};
~DOMStorageArea();
@@ -116,6 +152,7 @@ class CONTENT_EXPORT DOMStorageArea
void OnCommitTimer();
void CommitChanges(const CommitBatch* commit_batch);
void OnCommitComplete();
+ base::TimeDelta ComputeCommitDelay();
cmumford 2015/02/03 00:45:24 const
michaeln 2015/02/03 19:59:14 Done.
void ShutdownInCommitSequence();
@@ -131,6 +168,9 @@ class CONTENT_EXPORT DOMStorageArea
bool is_shutdown_;
scoped_ptr<CommitBatch> commit_batch_;
int commit_batches_in_flight_;
+ base::Time start_time_;
+ RateLimiter data_rate_limiter_;
+ RateLimiter commit_rate_limiter_;
};
} // namespace content
« 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