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

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: Cleaned-up with using Timer. (No clean-up for the unit-test.) 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..d84711b6d9b2c630ed8ae367aa104ab3224d752b
--- /dev/null
+++ b/webkit/quota/quota_temporary_storage_evictor.cc
@@ -0,0 +1,101 @@
+// 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::kUsageRatioToBeEvicted = 0.7;
+
+QuotaTemporaryStorageEvictor::QuotaTemporaryStorageEvictor(
+ QuotaEvictionHandler* quota_eviction_handler,
+ int64 target_available_space,
+ int64 delay_ms,
+ scoped_refptr<base::MessageLoopProxy> io_thread)
+ : physical_available_space_to_be_evicted(1000 * 1000 * 500),
kinuko 2011/05/19 09:27:18 nit: to be evicted -> to start eviction ? (from th
Dai Mikurube (NOT FULLTIME) 2011/05/20 02:42:24 Renamed them to: static const double kUsageRatio
+ quota_eviction_handler_(quota_eviction_handler),
+ target_available_space_(target_available_space),
kinuko 2011/05/19 09:27:18 not used now?
Dai Mikurube (NOT FULLTIME) 2011/05/20 02:42:24 Done.
+ delay_ms_(delay_ms),
kinuko 2011/05/19 09:27:18 interval_ms_? (since this is used for repeated evi
Dai Mikurube (NOT FULLTIME) 2011/05/20 02:42:24 My thought was that it might be changed at run-tim
kinuko 2011/05/20 06:41:13 Ok if we change the value it makes sense.
+ repeated_eviction_(false),
+ io_thread_(io_thread),
+ callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
kinuko 2011/05/19 09:27:18 I guess now we can DCHECK(quota_eviction_handler)
Dai Mikurube (NOT FULLTIME) 2011/05/20 02:42:24 Done.
+}
+
+QuotaTemporaryStorageEvictor::~QuotaTemporaryStorageEvictor() {
+}
+
+void QuotaTemporaryStorageEvictor::OnQuotaManagerDestroyedOnIOThread() {
kinuko 2011/05/19 09:27:18 Now we can happily get rid of this.
Dai Mikurube (NOT FULLTIME) 2011/05/20 02:42:24 Done.
+ DCHECK(io_thread_->BelongsToCurrentThread());
+ quota_eviction_handler_ = NULL;
+}
+
+void QuotaTemporaryStorageEvictor::OnEvictionCompleted(
+ QuotaStatusCode status) {
+ DCHECK(io_thread_->BelongsToCurrentThread());
+
+ // Check if more eviction is immediately required?
+ if (quota_eviction_handler_ != NULL) {
+ 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_)
+ repeated_eviction_ = false;
kinuko 2011/05/19 09:27:18 why do we flip the flag here? GetLRUOrigin may re
Dai Mikurube (NOT FULLTIME) 2011/05/20 02:42:24 Oh, I wrongly edited this line. MayStartEviction(
+ return;
+ }
+
+ if (quota_eviction_handler_ != NULL) {
+ 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 * kUsageRatioToBeEvicted ||
+ physical_available_space_to_be_evicted > physical_available_space)) {
+ if (quota_eviction_handler_ != NULL) {
+ quota_eviction_handler_->GetLRUOrigin(kStorageTypeTemporary,
+ callback_factory_.NewCallback(
+ &QuotaTemporaryStorageEvictor::DoEvict));
+ }
+ } else if (repeated_eviction_) {
kinuko 2011/05/19 09:27:18 Maybe if we get status != kQuotaStatusOk more than
Dai Mikurube (NOT FULLTIME) 2011/05/20 02:42:24 We should discuss error handling for the entire ev
kinuko 2011/05/20 06:41:13 sgtm. For the latter case we may also want to remo
+ MayStartEviction(delay_ms_);
+ }
+}
+
+void QuotaTemporaryStorageEvictor::GetUsageAndQuotaThenEvict() {
+ if (quota_eviction_handler_ != NULL) {
+ quota_eviction_handler_->GetUsageAndQuotaForEviction(callback_factory_.
+ NewCallback(&QuotaTemporaryStorageEvictor::EvictIfRequired));
+ }
+}
+
+void QuotaTemporaryStorageEvictor::MayStartEviction(int delay_ms) {
+ if (timer_.IsRunning())
+ return;
+ timer_.Start(base::TimeDelta::FromMilliseconds(delay_ms), this,
+ &QuotaTemporaryStorageEvictor::GetUsageAndQuotaThenEvict);
+}
+
+void QuotaTemporaryStorageEvictor::Start() {
kinuko 2011/05/19 09:27:18 Do we need this func? (I guess we could either cal
Dai Mikurube (NOT FULLTIME) 2011/05/20 02:42:24 Hmm, MayStartEviction and GetUsageAndQuotaThenEvic
kinuko 2011/05/20 06:43:49 First I thought GetUsageAndQuotaThenEvict could be
Dai Mikurube (NOT FULLTIME) 2011/05/20 07:36:54 Finally, you say which should be MayStartEviction(
+ DCHECK(io_thread_->BelongsToCurrentThread());
+ MayStartEviction(0);
+}
+
+} // namespace quota
« no previous file with comments | « webkit/quota/quota_temporary_storage_evictor.h ('k') | webkit/quota/quota_temporary_storage_evictor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698