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

Side by Side Diff: content/browser/dom_storage/dom_storage_namespace.cc

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 #include "content/browser/dom_storage/dom_storage_namespace.h" 5 #include "content/browser/dom_storage/dom_storage_namespace.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 DOMStorageArea* area = OpenStorageArea(origin); 116 DOMStorageArea* area = OpenStorageArea(origin);
117 area->FastClear(); 117 area->FastClear();
118 CloseStorageArea(area); 118 CloseStorageArea(area);
119 } 119 }
120 120
121 void DOMStorageNamespace::PurgeMemory(PurgeOption option) { 121 void DOMStorageNamespace::PurgeMemory(PurgeOption option) {
122 if (directory_.empty()) 122 if (directory_.empty())
123 return; // We can't purge w/o backing on disk. 123 return; // We can't purge w/o backing on disk.
124 AreaMap::iterator it = areas_.begin(); 124 AreaMap::iterator it = areas_.begin();
125 while (it != areas_.end()) { 125 while (it != areas_.end()) {
126 // Leave it alone if changes are pending 126 const AreaHolder& holder = it->second;
127 if (it->second.area_->HasUncommittedChanges()) { 127
128 // We can't purge if there are changes pending.
129 if (holder.area_->HasUncommittedChanges()) {
130 if (holder.open_count_ == 0) {
131 // Schedule an immediate commit so the next time we're asked to purge,
132 // we can drop it from memory.
133 holder.area_->ScheduleImmediateCommit();
134 }
128 ++it; 135 ++it;
129 continue; 136 continue;
130 } 137 }
131 138
132 // If not in use, we can shut it down and remove 139 // If not in use, we can shut it down and remove
133 // it from our collection entirely. 140 // it from our collection entirely.
134 if (it->second.open_count_ == 0) { 141 if (holder.open_count_ == 0) {
135 it->second.area_->Shutdown(); 142 holder.area_->Shutdown();
136 areas_.erase(it++); 143 areas_.erase(it++);
137 continue; 144 continue;
138 } 145 }
139 146
140 if (option == PURGE_AGGRESSIVE) { 147 if (option == PURGE_AGGRESSIVE) {
141 // If aggressive is true, we clear caches and such 148 // If aggressive is true, we clear caches and such
142 // for opened areas. 149 // for opened areas.
143 it->second.area_->PurgeMemory(); 150 holder.area_->PurgeMemory();
144 } 151 }
145 152
146 ++it; 153 ++it;
147 } 154 }
148 } 155 }
149 156
150 void DOMStorageNamespace::Shutdown() { 157 void DOMStorageNamespace::Shutdown() {
151 AreaMap::const_iterator it = areas_.begin(); 158 AreaMap::const_iterator it = areas_.begin();
152 for (; it != areas_.end(); ++it) 159 for (; it != areas_.end(); ++it)
153 it->second.area_->Shutdown(); 160 it->second.area_->Shutdown();
(...skipping 24 matching lines...) Expand all
178 185
179 DOMStorageNamespace::AreaHolder::AreaHolder( 186 DOMStorageNamespace::AreaHolder::AreaHolder(
180 DOMStorageArea* area, int count) 187 DOMStorageArea* area, int count)
181 : area_(area), open_count_(count) { 188 : area_(area), open_count_(count) {
182 } 189 }
183 190
184 DOMStorageNamespace::AreaHolder::~AreaHolder() { 191 DOMStorageNamespace::AreaHolder::~AreaHolder() {
185 } 192 }
186 193
187 } // namespace content 194 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698