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..d0947896e9b05a5a8f25744c2032f3d62bc9c431 100644 |
--- a/content/browser/dom_storage/dom_storage_area.h |
+++ b/content/browser/dom_storage/dom_storage_area.h |
@@ -5,6 +5,8 @@ |
#ifndef CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_AREA_H_ |
#define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_AREA_H_ |
+#include <string> |
+ |
#include "base/files/file_path.h" |
#include "base/gtest_prod_util.h" |
#include "base/memory/ref_counted.h" |
@@ -65,6 +67,7 @@ class CONTENT_EXPORT DOMStorageArea |
const std::string& destination_persistent_namespace_id); |
bool HasUncommittedChanges() const; |
+ void ScheduleImmediateCommit(); |
// Similar to Clear() but more optimized for just deleting |
// without raising events. |
@@ -92,14 +95,42 @@ class CONTENT_EXPORT DOMStorageArea |
FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, CommitChangesAtShutdown); |
FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, DeleteOrigin); |
FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, PurgeMemory); |
+ FRIEND_TEST_ALL_PREFIXES(DOMStorageAreaTest, RateLimiter); |
FRIEND_TEST_ALL_PREFIXES(DOMStorageContextImplTest, PersistentIds); |
friend class base::RefCountedThreadSafe<DOMStorageArea>; |
+ // Used to rate limit commits. |
+ class CONTENT_EXPORT RateLimiter { |
+ public: |
+ RateLimiter(size_t desired_rate, base::TimeDelta time_quantum); |
+ |
+ void add_samples(size_t samples) { |
+ samples_ += samples; |
+ } |
+ |
+ // Computes the total time needed to process the total samples seen |
+ // at the desired rate. |
+ base::TimeDelta ComputeTimeNeeded() const; |
+ |
+ // 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) const; |
+ |
+ private: |
+ float rate_; |
+ float samples_; |
+ base::TimeDelta time_quantum_; |
+ }; |
+ |
struct CommitBatch { |
bool clear_all_first; |
DOMStorageValuesMap changed_values; |
+ |
CommitBatch(); |
~CommitBatch(); |
+ size_t GetDataSize() const; |
}; |
~DOMStorageArea(); |
@@ -114,8 +145,10 @@ class CONTENT_EXPORT DOMStorageArea |
// task sequence when complete. |
CommitBatch* CreateCommitBatchIfNeeded(); |
void OnCommitTimer(); |
+ void PostCommitTask(); |
void CommitChanges(const CommitBatch* commit_batch); |
void OnCommitComplete(); |
+ base::TimeDelta ComputeCommitDelay() const; |
void ShutdownInCommitSequence(); |
@@ -131,6 +164,11 @@ class CONTENT_EXPORT DOMStorageArea |
bool is_shutdown_; |
scoped_ptr<CommitBatch> commit_batch_; |
int commit_batches_in_flight_; |
+ base::TimeTicks start_time_; |
+ RateLimiter data_rate_limiter_; |
+ RateLimiter commit_rate_limiter_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(DOMStorageArea); |
}; |
} // namespace content |