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..4911ae495060ad6a4045140d384fabe47476a76b |
--- /dev/null |
+++ b/webkit/quota/quota_temporary_storage_evictor.cc |
@@ -0,0 +1,139 @@ |
+// 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 <list> |
+#include <vector> |
+ |
+#include "base/message_loop.h" |
+#include "base/task.h" |
+#include "googleurl/src/gurl.h" |
+#include "webkit/quota/quota_client.h" |
+ |
+namespace quota { |
+ |
+const double QuotaTemporaryStorageEvictor::kUsageRatioToBeEvicted = 0.7; |
+ |
+QuotaTemporaryStorageEvictor::QuotaTemporaryStorageEvictor( |
+ int64 target_available_space, |
+ int64 delay_ms, |
+ scoped_refptr<base::MessageLoopProxy> io_message_loop) |
+ : physical_available_space_to_be_evicted(1000 * 1000 * 500), |
+ quota_manager_(NULL), |
+ target_available_space_(target_available_space), |
+ delay_ms_(delay_ms), |
+ repeated_eviction_(false), |
+ io_message_loop_(io_message_loop), |
+ callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
+} |
+ |
+QuotaTemporaryStorageEvictor::~QuotaTemporaryStorageEvictor() { |
+ LOG(ERROR) << "destruct"; |
+} |
+ |
+void QuotaTemporaryStorageEvictor::RegisterQuotaManagerOnIOThread( |
kinuko
2011/05/19 03:04:13
As we talked locally before I'd like to avoid this
Dai Mikurube (NOT FULLTIME)
2011/05/19 03:33:36
Yes, I'll get rid of it.
|
+ QuotaEvictionHandler* quota_manager) { |
+ LOG(ERROR) << "RegisterQuotaManagerOnIOThread"; |
+ DCHECK(io_message_loop_->BelongsToCurrentThread()); |
+ quota_manager_ = quota_manager; |
+} |
+ |
+void QuotaTemporaryStorageEvictor::OnQuotaManagerDestroyedOnIOThread() { |
+ LOG(ERROR) << "OnQuotaManagerDestroyedOnIOThread"; |
+ DCHECK(io_message_loop_->BelongsToCurrentThread()); |
+ LOG(ERROR) << "OnQuotaManagerDestroyedOnIOThread 2"; |
+ quota_manager_ = NULL; |
+} |
+ |
+void QuotaTemporaryStorageEvictor::OnGottenUsageAndQuotaOnIOThread( |
+ QuotaStatusCode status, |
+ int64 usage, |
+ int64 quota, |
+ int64 physical_available_space) { |
+ LOG(ERROR) << "OnGottenUsageAndQuotaOnIOThread"; |
+ DCHECK(io_message_loop_->BelongsToCurrentThread()); |
+ |
+ if (status == kQuotaStatusOk && |
+ (usage > quota * kUsageRatioToBeEvicted || |
+ physical_available_space_to_be_evicted > physical_available_space)) { |
+ // Evict another origin immediately. |
+ io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( |
+ this, &QuotaTemporaryStorageEvictor::Evict, true)); |
kinuko
2011/05/19 03:04:13
Any reason we don't directory call Evict here? (J
Dai Mikurube (NOT FULLTIME)
2011/05/19 03:33:36
It's just a remnant from the days when the Evictor
|
+ } else if (repeated_eviction_) { |
+ // Post the next delayed task. |
+ io_message_loop_->PostDelayedTask(FROM_HERE, NewRunnableMethod( |
+ this, &QuotaTemporaryStorageEvictor::Evict, false), delay_ms_); |
+ } |
+} |
+ |
+void QuotaTemporaryStorageEvictor::CallGetUsageAndQuotaOnIOThread() { |
+ LOG(ERROR) << "CallGetUsageAndQuotaOnIOThread"; |
+ DCHECK(io_message_loop_->BelongsToCurrentThread()); |
+ if (quota_manager_ != NULL) { |
+ quota_manager_->GetUsageAndQuotaForEviction(callback_factory_.NewCallback( |
+ &QuotaTemporaryStorageEvictor::OnGottenUsageAndQuotaOnIOThread)); |
+ } |
+} |
+ |
+void QuotaTemporaryStorageEvictor::OnEvictionCompletedOnIOThread( |
+ QuotaStatusCode status) { |
+ LOG(ERROR) << "OnDeletionCompletedOnIOThread"; |
+ DCHECK(io_message_loop_->BelongsToCurrentThread()); |
+ io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, |
+ &QuotaTemporaryStorageEvictor::CallGetUsageAndQuotaOnIOThread)); |
kinuko
2011/05/19 03:04:13
We can just chain to call mgr->GetUsageAndQuotaFor
|
+} |
+ |
+void QuotaTemporaryStorageEvictor::CallEvictOriginOnIOThread( |
+ const GURL& origin) { |
+ LOG(ERROR) << "CallEvictOriginOnIOThread"; |
+ DCHECK(io_message_loop_->BelongsToCurrentThread()); |
+ if (quota_manager_ != NULL) { |
+ quota_manager_->EvictOriginData( |
+ origin, kStorageTypeTemporary, callback_factory_.NewCallback( |
+ &QuotaTemporaryStorageEvictor::OnEvictionCompletedOnIOThread)); |
+ } |
+} |
+ |
+void QuotaTemporaryStorageEvictor::Evict(bool delete_immediately) { |
+ LOG(ERROR) << "Evict: immedeate?=" << delete_immediately; |
+ if (delete_immediately) { |
+ GURL origin; |
+ // origin = manager_->GetLRUOriginExceptFor(/* fs_type?, */ in_use); |
+ origin = GURL("http://www.example.com"); // test. |
+ |
+ if (origin.is_empty()) { |
+ LOG(ERROR) << "empty"; |
+ if (repeated_eviction_) { |
+ io_message_loop_->PostDelayedTask(FROM_HERE, NewRunnableMethod( |
+ this, &QuotaTemporaryStorageEvictor::Evict, false), delay_ms_); |
+ } |
+ return; |
+ } |
+ |
+ io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, |
+ &QuotaTemporaryStorageEvictor::CallEvictOriginOnIOThread, origin)); |
+ } else { |
+ io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, |
+ &QuotaTemporaryStorageEvictor::CallGetUsageAndQuotaOnIOThread)); |
kinuko
2011/05/19 03:04:13
ditto
|
+ } |
+} |
+ |
+void QuotaTemporaryStorageEvictor::Start() { |
+ LOG(ERROR) << "Start"; |
+ io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( |
+ this, &QuotaTemporaryStorageEvictor::Evict, false)); |
+} |
+ |
+void QuotaTemporaryStorageEvictor::DeleteOnCorrectThread() const { |
+ LOG(ERROR) << "DeleteOnCorrectThread"; |
+ if (!io_message_loop_->BelongsToCurrentThread()) { |
+ LOG(ERROR) << "io"; |
+ io_message_loop_->DeleteSoon(FROM_HERE, this); |
+ return; |
+ } |
+ delete this; |
+} |
+ |
+} // namespace quota |