| 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..94d95bf47aefd040fcc172f38e3e340cf67ff734
|
| --- /dev/null
|
| +++ b/webkit/quota/quota_temporary_storage_evictor.cc
|
| @@ -0,0 +1,93 @@
|
| +// 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* quota_manager,
|
| + QuotaDatabase* quota_database,
|
| + int64 delay_ms,
|
| + scoped_refptr<base::MessageLoopProxy> io_message_loop,
|
| + scoped_refptr<base::MessageLoopProxy> db_message_loop)
|
| + : quota_manager_(quota_manager),
|
| + quota_database_(quota_database),
|
| + delay_ms_(delay_ms),
|
| + io_message_loop_(io_message_loop),
|
| + db_message_loop_(db_message_loop),
|
| + callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
|
| +}
|
| +
|
| +QuotaTemporaryStorageEvictor::~QuotaTemporaryStorageEvictor() {}
|
| +
|
| +void QuotaTemporaryStorageEvictor::OnQuotaManagerDestroyedOnIOThread() {
|
| + // TODO(dmikurbe): DCHECK(in the io_thread);
|
| + quota_manager_ = NULL;
|
| +}
|
| +
|
| +void QuotaTemporaryStorageEvictor::OnDeletionCompletedOnIOThread(
|
| + QuotaStatusCode status) {
|
| + // TODO(dmikurube): DCHECK(in the io_thread);
|
| + LOG(ERROR) << "OnDeletionCompletedOnIOThread";
|
| +
|
| + if (status != kQuotaStatusOk) {
|
| + // TODO(dmikurube): What to do in case of deletion failure?
|
| + }
|
| +
|
| + if (false /* More deletion required? */) {
|
| + LOG(ERROR) << "false";
|
| + // Delete another origin.
|
| + db_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
|
| + this, &QuotaTemporaryStorageEvictor::Evict));
|
| + } else {
|
| + LOG(ERROR) << "true";
|
| + // Post the next task.
|
| + db_message_loop_->PostDelayedTask(FROM_HERE, NewRunnableMethod(
|
| + this, &QuotaTemporaryStorageEvictor::Evict), delay_ms_);
|
| + }
|
| +}
|
| +
|
| +void QuotaTemporaryStorageEvictor::CallDeleteOriginOnIOThread(
|
| + const GURL& origin) {
|
| + // TODO(dmikurube): DCHECK(in the io_thread);
|
| + LOG(ERROR) << "CallDeleteOriginOnIOThread";
|
| + quota_manager_->DeleteOriginDataOnIOThread(
|
| + origin, kStorageTypeTemporary, callback_factory_.NewCallback(
|
| + &QuotaTemporaryStorageEvictor::OnDeletionCompletedOnIOThread));
|
| +}
|
| +
|
| +void QuotaTemporaryStorageEvictor::Evict() {
|
| + LOG(ERROR) << "Evict";
|
| + GURL origin;
|
| + // origin = database_->GetLRUOrigin(/* fs_type?, */ in_use);
|
| + origin = GURL("http://www.example.com"); // test.
|
| +
|
| + // TODO(dmikurube): Calling QuotaManager and callback would be required.
|
| + if (origin.is_empty() /* || not quota exceeded */) {
|
| + LOG(ERROR) << "empty";
|
| + db_message_loop_->PostDelayedTask(FROM_HERE, NewRunnableMethod(
|
| + this, &QuotaTemporaryStorageEvictor::Evict), delay_ms_);
|
| + return;
|
| + }
|
| +
|
| + io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
|
| + this, &QuotaTemporaryStorageEvictor::CallDeleteOriginOnIOThread, origin));
|
| +}
|
| +
|
| +void QuotaTemporaryStorageEvictor::Start() {
|
| + LOG(ERROR) << "Start";
|
| + db_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
|
| + this, &QuotaTemporaryStorageEvictor::Evict));
|
| +}
|
| +
|
| +} // namespace quota
|
|
|