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

Side by Side Diff: webkit/dom_storage/dom_storage_context.cc

Issue 12398008: Purge in-memory localStorage areas if the # of areas exceeds the limit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "webkit/dom_storage/dom_storage_context.h" 5 #include "webkit/dom_storage/dom_storage_context.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/guid.h" 10 #include "base/guid.h"
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 } 345 }
346 346
347 void DomStorageContext::StartScavengingUnusedSessionStorage() { 347 void DomStorageContext::StartScavengingUnusedSessionStorage() {
348 if (session_storage_database_.get()) { 348 if (session_storage_database_.get()) {
349 task_runner_->PostDelayedTask( 349 task_runner_->PostDelayedTask(
350 FROM_HERE, base::Bind(&DomStorageContext::FindUnusedNamespaces, this), 350 FROM_HERE, base::Bind(&DomStorageContext::FindUnusedNamespaces, this),
351 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); 351 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds));
352 } 352 }
353 } 353 }
354 354
355 int64 DomStorageContext::GetInMemoryStorageSize() const {
356 // TODO(kinuko): Cache this!!
357 int64 total_size = 0;
358 // Naively add-up the area size for each connection.
359 std::set<DomStorageArea*> visited_areas;
360 for (StorageNamespaceMap::const_iterator itr = namespaces_.begin();
361 itr != namespaces_.end(); ++itr) {
362 const DomStorageNamespace::AreaMap& map = itr->second->GetAreaMap();
363 for (DomStorageNamespace::AreaMap::const_iterator map_itr = map.begin();
364 map_itr != map.end(); ++map_itr) {
365 // We don't care open_count_ here, since we want to limit the
366 // memory usage.
367 DomStorageArea* area = map_itr->second.area_;
368 DCHECK(area);
369 if (visited_areas.insert(area).second) {
370 total_size += area->GetMapSize();
371 }
372 }
373 }
374 return total_size;
375 }
376
355 void DomStorageContext::FindUnusedNamespaces() { 377 void DomStorageContext::FindUnusedNamespaces() {
356 DCHECK(session_storage_database_.get()); 378 DCHECK(session_storage_database_.get());
357 if (scavenging_started_) 379 if (scavenging_started_)
358 return; 380 return;
359 scavenging_started_ = true; 381 scavenging_started_ = true;
360 std::set<std::string> namespace_ids_in_use; 382 std::set<std::string> namespace_ids_in_use;
361 for (StorageNamespaceMap::const_iterator it = namespaces_.begin(); 383 for (StorageNamespaceMap::const_iterator it = namespaces_.begin();
362 it != namespaces_.end(); ++it) 384 it != namespaces_.end(); ++it)
363 namespace_ids_in_use.insert(it->second->persistent_namespace_id()); 385 namespace_ids_in_use.insert(it->second->persistent_namespace_id());
364 std::set<std::string> protected_persistent_session_ids; 386 std::set<std::string> protected_persistent_session_ids;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 if (!deletable_persistent_namespace_ids_.empty()) { 437 if (!deletable_persistent_namespace_ids_.empty()) {
416 task_runner_->PostDelayedTask( 438 task_runner_->PostDelayedTask(
417 FROM_HERE, base::Bind( 439 FROM_HERE, base::Bind(
418 &DomStorageContext::DeleteNextUnusedNamespace, 440 &DomStorageContext::DeleteNextUnusedNamespace,
419 this), 441 this),
420 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); 442 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds));
421 } 443 }
422 } 444 }
423 445
424 } // namespace dom_storage 446 } // namespace dom_storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698