| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 |
| OLD | NEW |