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

Unified Diff: webkit/quota/quota_temporary_storage_evictor.cc

Issue 7002024: Implement QuotaTemporaryStorageEvictor. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixed and cleaned-up. Created 9 years, 7 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
Index: webkit/quota/quota_temporary_storage_evictor.cc
diff --git a/webkit/quota/quota_temporary_storage_evictor.cc b/webkit/quota/quota_temporary_storage_evictor.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9596c7aebdc8f025086e11f33e16832cd63b9d48
--- /dev/null
+++ b/webkit/quota/quota_temporary_storage_evictor.cc
@@ -0,0 +1,86 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/quota/quota_temporary_storage_evictor.h"
+
+#include "googleurl/src/gurl.h"
+
+namespace quota {
+
+const double QuotaTemporaryStorageEvictor::kUsageRatioToStartEviction = 0.7;
+
+QuotaTemporaryStorageEvictor::QuotaTemporaryStorageEvictor(
+ QuotaEvictionHandler* quota_eviction_handler,
+ int64 interval_ms,
+ scoped_refptr<base::MessageLoopProxy> io_thread)
+ : kAvailableDiskSpaceToStartEviction(1000 * 1000 * 500),
+ quota_eviction_handler_(quota_eviction_handler),
+ interval_ms_(interval_ms),
+ repeated_eviction_(false),
+ io_thread_(io_thread),
+ callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ DCHECK(quota_eviction_handler);
+}
+
+QuotaTemporaryStorageEvictor::~QuotaTemporaryStorageEvictor() {
+}
+
+void QuotaTemporaryStorageEvictor::OnEvictionCompleted(
+ QuotaStatusCode status) {
+ DCHECK(io_thread_->BelongsToCurrentThread());
+
+ // Check if more eviction is immediately required?
+ quota_eviction_handler_->GetUsageAndQuotaForEviction(callback_factory_.
+ NewCallback(&QuotaTemporaryStorageEvictor::EvictIfRequired));
+}
+
+void QuotaTemporaryStorageEvictor::DoEvict(const GURL& origin) {
+ DCHECK(io_thread_->BelongsToCurrentThread());
+
+ if (origin.is_empty()) {
+ if (repeated_eviction_)
+ MayStartEviction(interval_ms_);
+ return;
+ }
+
+ quota_eviction_handler_->EvictOriginData(origin, kStorageTypeTemporary,
+ callback_factory_.NewCallback(
+ &QuotaTemporaryStorageEvictor::OnEvictionCompleted));
+}
+
+void QuotaTemporaryStorageEvictor::EvictIfRequired(
+ QuotaStatusCode status,
+ int64 usage,
+ int64 quota,
+ int64 physical_available_space) {
+ DCHECK(io_thread_->BelongsToCurrentThread());
+
+ if (status == kQuotaStatusOk &&
+ (usage > quota * kUsageRatioToStartEviction ||
+ kAvailableDiskSpaceToStartEviction > physical_available_space)) {
+ quota_eviction_handler_->GetLRUOrigin(kStorageTypeTemporary,
+ callback_factory_.NewCallback(&QuotaTemporaryStorageEvictor::DoEvict));
+ } else if (repeated_eviction_) {
+ MayStartEviction(interval_ms_);
+ }
+}
+
+void QuotaTemporaryStorageEvictor::GetUsageAndQuotaThenEvict() {
+ quota_eviction_handler_->GetUsageAndQuotaForEviction(callback_factory_.
+ NewCallback(&QuotaTemporaryStorageEvictor::EvictIfRequired));
+}
+
+void QuotaTemporaryStorageEvictor::MayStartEviction(int interval_ms) {
+ if (timer_.IsRunning())
+ return;
+ timer_.Start(base::TimeDelta::FromMilliseconds(interval_ms), this,
+ &QuotaTemporaryStorageEvictor::GetUsageAndQuotaThenEvict);
+}
+
+void QuotaTemporaryStorageEvictor::Start() {
+ DCHECK(io_thread_->BelongsToCurrentThread());
+ MayStartEviction(0);
+}
+
+} // namespace quota

Powered by Google App Engine
This is Rietveld 408576698