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

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: Reflected the comments. 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..1ea9bfb690367f264653235555297efd933b0ed3
--- /dev/null
+++ b/webkit/quota/quota_temporary_storage_evictor.cc
@@ -0,0 +1,89 @@
+// 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;
+const int64 QuotaTemporaryStorageEvictor::
+ kDefaultMinAvailableDiskSpaceToStartEviction = 1000 * 1000 * 500;
+
+QuotaTemporaryStorageEvictor::QuotaTemporaryStorageEvictor(
+ QuotaEvictionHandler* quota_eviction_handler,
+ int64 interval_ms,
+ scoped_refptr<base::MessageLoopProxy> io_thread)
+ : min_available_disk_space_to_start_eviction_(
+ kDefaultMinAvailableDiskSpaceToStartEviction),
+ 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(
michaeln 2011/05/23 19:53:47 Please define the methods in the .cc file in the s
Dai Mikurube (NOT FULLTIME) 2011/05/24 05:59:04 Exactly. Reordered them.
+ 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 available_disk_space) {
+ DCHECK(io_thread_->BelongsToCurrentThread());
+
+ if (status == kQuotaStatusOk &&
+ (usage > quota * kUsageRatioToStartEviction ||
+ min_available_disk_space_to_start_eviction_ > available_disk_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