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

Side by Side 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: Added a TODO to call OnQuotaManagerDestroyed. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "webkit/quota/quota_temporary_storage_evictor.h"
6
7 #include "base/message_loop.h"
8 #include "base/task.h"
9 #include "googleurl/src/gurl.h"
10 #include "webkit/quota/quota_client.h"
11
12 #include <vector>
13 #include <list>
14
15 namespace quota {
16
17 QuotaTemporaryStorageEvictor::QuotaTemporaryStorageEvictor(
18 QuotaManager* quota_manager,
19 QuotaDatabase* quota_database,
20 int64 delay_ms,
21 scoped_refptr<base::MessageLoopProxy> io_message_loop,
22 scoped_refptr<base::MessageLoopProxy> db_message_loop)
23 : quota_manager_(quota_manager),
24 quota_database_(quota_database),
25 delay_ms_(delay_ms),
26 io_message_loop_(io_message_loop),
27 db_message_loop_(db_message_loop),
28 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
29 }
30
31 QuotaTemporaryStorageEvictor::~QuotaTemporaryStorageEvictor() {}
32
33 void QuotaTemporaryStorageEvictor::OnQuotaManagerDestroyedOnIOThread() {
34 // TODO(dmikurbe): DCHECK(in the io_thread);
35 quota_manager_ = NULL;
36 }
37
38 void QuotaTemporaryStorageEvictor::OnDeletionCompletedOnIOThread(
39 QuotaStatusCode status) {
40 // TODO(dmikurube): DCHECK(in the io_thread);
41 LOG(ERROR) << "OnDeletionCompletedOnIOThread";
42
43 if (status != kQuotaStatusOk) {
44 // TODO(dmikurube): What to do in case of deletion failure?
45 }
46
47 if (false /* More deletion required? */) {
48 LOG(ERROR) << "false";
49 // Delete another origin.
50 db_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
51 this, &QuotaTemporaryStorageEvictor::Evict));
52 } else {
53 LOG(ERROR) << "true";
54 // Post the next task.
55 db_message_loop_->PostDelayedTask(FROM_HERE, NewRunnableMethod(
56 this, &QuotaTemporaryStorageEvictor::Evict), delay_ms_);
57 }
58 }
59
60 void QuotaTemporaryStorageEvictor::CallDeleteOriginOnIOThread(
61 const GURL& origin) {
62 // TODO(dmikurube): DCHECK(in the io_thread);
63 LOG(ERROR) << "CallDeleteOriginOnIOThread";
64 quota_manager_->DeleteOriginDataOnIOThread(
65 origin, kStorageTypeTemporary, callback_factory_.NewCallback(
66 &QuotaTemporaryStorageEvictor::OnDeletionCompletedOnIOThread));
67 }
68
69 void QuotaTemporaryStorageEvictor::Evict() {
70 LOG(ERROR) << "Evict";
71 GURL origin;
72 // origin = database_->GetLRUOrigin(/* fs_type?, */ in_use);
73 origin = GURL("http://www.example.com"); // test.
74
75 // TODO(dmikurube): Calling QuotaManager and callback would be required.
76 if (origin.is_empty() /* || not quota exceeded */) {
77 LOG(ERROR) << "empty";
78 db_message_loop_->PostDelayedTask(FROM_HERE, NewRunnableMethod(
79 this, &QuotaTemporaryStorageEvictor::Evict), delay_ms_);
80 return;
81 }
82
83 io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
84 this, &QuotaTemporaryStorageEvictor::CallDeleteOriginOnIOThread, origin));
85 }
86
87 void QuotaTemporaryStorageEvictor::Start() {
88 LOG(ERROR) << "Start";
89 db_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
90 this, &QuotaTemporaryStorageEvictor::Evict));
91 }
92
93 } // namespace quota
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698