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..f15ebdb35a79974acb99502ecdc34b4f368f7992 |
--- /dev/null |
+++ b/webkit/quota/quota_temporary_storage_evictor.cc |
@@ -0,0 +1,96 @@ |
+// 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 "base/message_loop.h" |
+#include "base/task.h" |
+#include "googleurl/src/gurl.h" |
+#include "webkit/quota/quota_client.h" |
+ |
+#include <vector> |
+#include <list> |
+ |
+namespace quota { |
+ |
+QuotaTemporaryStorageEvictor::QuotaTemporaryStorageEvictor( |
+ QuotaManager* manager, |
+ QuotaDatabase* database, |
+ int64 delay_ms, |
+ scoped_refptr<base::MessageLoopProxy> db_message_loop) |
+ : manager_(manager), |
+ database_(database), |
+ delay_ms_(delay_ms), |
+ db_message_loop_(db_message_loop), |
+ num_clients_(0), |
+ num_deleted_(0), |
+ runnable_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
+} |
+ |
+QuotaTemporaryStorageEvictor::~QuotaTemporaryStorageEvictor() {} |
+ |
+void QuotaTemporaryStorageEvictor::OnDeleted(QuotaStatusCode status) { |
+ LOG(ERROR) << "OnDeleted " << num_deleted_ << "/" << num_clients_; |
+ if (status != kQuotaStatusOk) { |
+ // Post the next task. |
+ MessageLoop::current()->PostDelayedTask(FROM_HERE, runnable_factory_. |
+ NewRunnableMethod(&QuotaTemporaryStorageEvictor::Evict), delay_ms_); |
kinuko
2011/05/11 12:43:30
How would we do handle other already running clien
Dai Mikurube (NOT FULLTIME)
2011/05/12 02:45:50
Exactly. At first, I've added an error flag.
|
+ return; |
+ } |
+ |
+ ++num_deleted_; |
+ DCHECK(num_deleted_ <= num_clients_); |
+ if (num_deleted_ == num_clients_) { |
+ num_clients_ = 0; |
+ num_deleted_ = 0; |
+ if (false /* More deletion required? */) { |
kinuko
2011/05/11 12:43:30
This part would need some design doc.
There's a r
Dai Mikurube (NOT FULLTIME)
2011/05/12 02:45:50
Yes, that's the point. Let's discuss later. I'll
|
+ // Delete another origin. |
+ MessageLoop::current()->PostTask(FROM_HERE, runnable_factory_. |
+ NewRunnableMethod(&QuotaTemporaryStorageEvictor::Evict)); |
+ } else { |
+ // Post the next task. |
+ MessageLoop::current()->PostDelayedTask(FROM_HERE, runnable_factory_. |
+ NewRunnableMethod(&QuotaTemporaryStorageEvictor::Evict), delay_ms_); |
+ } |
+ } |
+} |
+ |
+void QuotaTemporaryStorageEvictor::Evict() { |
+ LOG(ERROR) << "Evict"; |
+ GURL origin; |
+ // origin = database_->GetLRUOrigin(/* fs_type?, */ in_use); |
+ origin = GURL("http://www.example.com"); // test. |
+ |
+ QuotaClientList clients; |
+ // manager_->GetClients(...); |
+ clients.push_back(NULL); // test. |
+ clients.push_back(NULL); // test. |
+ clients.push_back(NULL); // test. |
+ num_clients_ = clients.size(); |
kinuko
2011/05/11 12:43:30
:) Let's start thinking how we could test this cla
Dai Mikurube (NOT FULLTIME)
2011/05/12 02:45:50
Before that, I think some method to get a list of
|
+ |
+ if (origin.is_empty() || num_clients_ == 0 || num_deleted_ > 0 |
+ /* || not quota exceeded */) { |
Dai Mikurube (NOT FULLTIME)
2011/05/11 12:30:21
Calling QuotaManager and callback would be require
|
+ MessageLoop::current()->PostDelayedTask(FROM_HERE, runnable_factory_. |
+ NewRunnableMethod(&QuotaTemporaryStorageEvictor::Evict), delay_ms_); |
+ return; |
+ } |
+ |
+ for (QuotaClientList::iterator p = clients.begin(); |
+ p != clients.end(); |
+ ++p) { |
+ /* |
+ p->DeleteOriginData(origin, kStorageTypeTemporary, runnable_factory_. |
+ NewRunnableMethod(&QuotaTemporaryStorageEvictor::OnDeleted)); |
+ */ |
+ OnDeleted(kQuotaStatusOk); // test. |
+ } |
+} |
+ |
+void QuotaTemporaryStorageEvictor::Start() { |
+ // TODO(dmikurube): Check if it's in the db_thread. ( + re-post in db_thread?) |
+ MessageLoop::current()->PostTask(FROM_HERE, runnable_factory_. |
kinuko
2011/05/11 12:43:30
I think we should replace MessageLoop::current() w
Dai Mikurube (NOT FULLTIME)
2011/05/11 13:59:22
Actually, just replacing with db_message_loop_ cau
Dai Mikurube (NOT FULLTIME)
2011/05/12 04:12:02
FYI: base/task.h:71-72 says
// The factories are n
kinuko
2011/05/12 05:41:34
:( ...I see, so it's only to post tasks to the cu
|
+ NewRunnableMethod(&QuotaTemporaryStorageEvictor::Evict)); |
+} |
+ |
+} // namespace quota |