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

Unified Diff: content/browser/dom_storage/dom_storage_area.cc

Issue 2309523002: DOM Storage: Populate commit batch values lazily to avoid memory bloat (Closed)
Patch Set: Actually save the memory Created 4 years, 3 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
« no previous file with comments | « content/browser/dom_storage/dom_storage_area.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/dom_storage/dom_storage_area.cc
diff --git a/content/browser/dom_storage/dom_storage_area.cc b/content/browser/dom_storage/dom_storage_area.cc
index f623fdcee0efcc1c91f0d6112b49a8b98babad79..c305ccb69b618dd550d043a36d446ebcd601b121 100644
--- a/content/browser/dom_storage/dom_storage_area.cc
+++ b/content/browser/dom_storage/dom_storage_area.cc
@@ -195,7 +195,8 @@ bool DOMStorageArea::SetItem(const base::string16& key,
if (success && backing_ &&
(old_value->is_null() || old_value->string() != value)) {
CommitBatch* commit_batch = CreateCommitBatchIfNeeded();
- commit_batch->changed_values[key] = base::NullableString16(value, false);
+ // Values are populated later to avoid holding duplicate memory.
+ commit_batch->changed_values[key] = base::NullableString16();
}
return success;
}
@@ -327,6 +328,12 @@ void DOMStorageArea::PurgeMemory() {
void DOMStorageArea::Shutdown() {
DCHECK(!is_shutdown_);
is_shutdown_ = true;
+
+ if (commit_batch_) {
+ DCHECK(backing_);
+ PopulateCommitBatchValues();
+ }
+
map_ = NULL;
if (!backing_)
return;
@@ -427,6 +434,12 @@ DOMStorageArea::CommitBatch* DOMStorageArea::CreateCommitBatchIfNeeded() {
return commit_batch_.get();
}
+void DOMStorageArea::PopulateCommitBatchValues() {
+ DCHECK(task_runner_->IsRunningOnPrimarySequence());
+ for (auto& key_value : commit_batch_->changed_values)
+ key_value.second = map_->GetItem(key_value.first);
+}
+
void DOMStorageArea::StartCommitTimer() {
if (is_shutdown_ || !commit_batch_)
return;
@@ -473,6 +486,7 @@ void DOMStorageArea::PostCommitTask() {
DCHECK(backing_.get());
+ PopulateCommitBatchValues();
commit_rate_limiter_.add_samples(1);
data_rate_limiter_.add_samples(commit_batch_->GetDataSize());
« no previous file with comments | « content/browser/dom_storage/dom_storage_area.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698