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

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

Issue 1953703004: Purge browser cache for dom storage in a smarter way (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dom_storage
Patch Set: Fix limit and description for UMA. Created 4 years, 6 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/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "content/browser/dom_storage/dom_storage_area.h" 10 #include "content/browser/dom_storage/dom_storage_area.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 area->DeleteOrigin(); 110 area->DeleteOrigin();
111 } 111 }
112 } 112 }
113 113
114 void DOMStorageNamespace::DeleteSessionStorageOrigin(const GURL& origin) { 114 void DOMStorageNamespace::DeleteSessionStorageOrigin(const GURL& origin) {
115 DOMStorageArea* area = OpenStorageArea(origin); 115 DOMStorageArea* area = OpenStorageArea(origin);
116 area->FastClear(); 116 area->FastClear();
117 CloseStorageArea(area); 117 CloseStorageArea(area);
118 } 118 }
119 119
120 void DOMStorageNamespace::PurgeMemory(PurgeOption option) { 120 void DOMStorageNamespace::PurgeMemory(bool aggressively) {
121 if (directory_.empty()) 121 if (directory_.empty())
122 return; // We can't purge w/o backing on disk. 122 return; // We can't purge w/o backing on disk.
123
123 AreaMap::iterator it = areas_.begin(); 124 AreaMap::iterator it = areas_.begin();
124 while (it != areas_.end()) { 125 while (it != areas_.end()) {
125 const AreaHolder& holder = it->second; 126 const AreaHolder& holder = it->second;
126 127
127 // We can't purge if there are changes pending. 128 // We can't purge if there are changes pending.
128 if (holder.area_->HasUncommittedChanges()) { 129 if (holder.area_->HasUncommittedChanges()) {
129 if (holder.open_count_ == 0) { 130 if (holder.open_count_ == 0) {
130 // Schedule an immediate commit so the next time we're asked to purge, 131 // Schedule an immediate commit so the next time we're asked to purge,
131 // we can drop it from memory. 132 // we can drop it from memory.
132 holder.area_->ScheduleImmediateCommit(); 133 holder.area_->ScheduleImmediateCommit();
133 } 134 }
134 ++it; 135 ++it;
135 continue; 136 continue;
136 } 137 }
137 138
138 // If not in use, we can shut it down and remove 139 // If not in use, we can shut it down and remove
139 // it from our collection entirely. 140 // it from our collection entirely.
140 if (holder.open_count_ == 0) { 141 if (holder.open_count_ == 0) {
141 holder.area_->Shutdown(); 142 holder.area_->Shutdown();
142 areas_.erase(it++); 143 areas_.erase(it++);
143 continue; 144 continue;
144 } 145 }
145 146
146 if (option == PURGE_AGGRESSIVE) { 147 if (aggressively) {
147 // If aggressive is true, we clear caches and such 148 // If aggressive is true, we clear caches and such
148 // for opened areas. 149 // for opened areas.
149 holder.area_->PurgeMemory(); 150 holder.area_->PurgeMemory();
150 } 151 }
151 152
152 ++it; 153 ++it;
153 } 154 }
154 } 155 }
155 156
156 void DOMStorageNamespace::Shutdown() { 157 void DOMStorageNamespace::Shutdown() {
157 AreaMap::const_iterator it = areas_.begin(); 158 AreaMap::const_iterator it = areas_.begin();
158 for (; it != areas_.end(); ++it) 159 for (; it != areas_.end(); ++it)
159 it->second.area_->Shutdown(); 160 it->second.area_->Shutdown();
160 } 161 }
161 162
162 void DOMStorageNamespace::Flush() { 163 void DOMStorageNamespace::Flush() {
163 for (auto& entry : areas_) { 164 for (auto& entry : areas_) {
164 if (!entry.second.area_->HasUncommittedChanges()) 165 if (!entry.second.area_->HasUncommittedChanges())
165 continue; 166 continue;
166 entry.second.area_->ScheduleImmediateCommit(); 167 entry.second.area_->ScheduleImmediateCommit();
167 } 168 }
168 } 169 }
169 170
170 unsigned int DOMStorageNamespace::CountInMemoryAreas() const { 171 DOMStorageNamespace::UsageStatistics DOMStorageNamespace::GetUsageStatistics()
171 unsigned int area_count = 0; 172 const {
173 UsageStatistics stats = {0};
172 for (AreaMap::const_iterator it = areas_.begin(); it != areas_.end(); ++it) { 174 for (AreaMap::const_iterator it = areas_.begin(); it != areas_.end(); ++it) {
173 if (it->second.area_->IsLoadedInMemory()) 175 if (it->second.area_->IsLoadedInMemory()) {
174 ++area_count; 176 stats.total_cache_size += it->second.area_->map_usage_in_bytes();
177 ++stats.total_area_count;
178 if (it->second.open_count_ == 0)
179 ++stats.inactive_area_count;
180 }
175 } 181 }
176 return area_count; 182 return stats;
177 } 183 }
178 184
179 void DOMStorageNamespace::OnMemoryDump( 185 void DOMStorageNamespace::OnMemoryDump(
180 base::trace_event::ProcessMemoryDump* pmd) { 186 base::trace_event::ProcessMemoryDump* pmd) {
181 DCHECK(task_runner_->IsRunningOnPrimarySequence()); 187 DCHECK(task_runner_->IsRunningOnPrimarySequence());
182 for (const auto& it : areas_) 188 for (const auto& it : areas_)
183 it.second.area_->OnMemoryDump(pmd); 189 it.second.area_->OnMemoryDump(pmd);
184 } 190 }
185 191
186 void DOMStorageNamespace::GetOriginsWithAreas( 192 void DOMStorageNamespace::GetOriginsWithAreas(
(...skipping 21 matching lines...) Expand all
208 DOMStorageArea* area, int count) 214 DOMStorageArea* area, int count)
209 : area_(area), open_count_(count) { 215 : area_(area), open_count_(count) {
210 } 216 }
211 217
212 DOMStorageNamespace::AreaHolder::AreaHolder(const AreaHolder& other) = default; 218 DOMStorageNamespace::AreaHolder::AreaHolder(const AreaHolder& other) = default;
213 219
214 DOMStorageNamespace::AreaHolder::~AreaHolder() { 220 DOMStorageNamespace::AreaHolder::~AreaHolder() {
215 } 221 }
216 222
217 } // namespace content 223 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/dom_storage/dom_storage_namespace.h ('k') | content/common/dom_storage/dom_storage_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698