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

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: Extracted. 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 <list>
8 #include <vector>
9
10 #include "base/message_loop.h"
11 #include "base/task.h"
12 #include "googleurl/src/gurl.h"
13 #include "webkit/quota/quota_client.h"
14
15 namespace quota {
16
17 const double QuotaTemporaryStorageEvictor::kUsageRatioToBeEvicted = 0.7;
18
19 QuotaTemporaryStorageEvictor::QuotaTemporaryStorageEvictor(
20 int64 target_available_space,
21 int64 delay_ms,
22 scoped_refptr<base::MessageLoopProxy> io_message_loop)
23 : physical_available_space_to_be_evicted(1000 * 1000 * 500),
24 quota_manager_(NULL),
25 target_available_space_(target_available_space),
26 delay_ms_(delay_ms),
27 repeated_eviction_(false),
28 io_message_loop_(io_message_loop),
29 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
30 }
31
32 QuotaTemporaryStorageEvictor::~QuotaTemporaryStorageEvictor() {
33 LOG(ERROR) << "destruct";
34 }
35
36 void QuotaTemporaryStorageEvictor::RegisterQuotaManagerOnIOThread(
37 QuotaEvictionHandler* quota_manager) {
38 LOG(ERROR) << "RegisterQuotaManagerOnIOThread";
39 DCHECK(io_message_loop_->BelongsToCurrentThread());
40 quota_manager_ = quota_manager;
41 }
42
43 void QuotaTemporaryStorageEvictor::OnQuotaManagerDestroyedOnIOThread() {
44 LOG(ERROR) << "OnQuotaManagerDestroyedOnIOThread";
45 DCHECK(io_message_loop_->BelongsToCurrentThread());
46 LOG(ERROR) << "OnQuotaManagerDestroyedOnIOThread 2";
47 quota_manager_ = NULL;
48 }
49
50 void QuotaTemporaryStorageEvictor::OnDeletionCompletedOnIOThread(
51 QuotaStatusCode status,
52 int64 usage,
53 int64 quota,
54 int64 physical_available_space) {
55 LOG(ERROR) << "OnDeletionCompletedOnIOThread";
56 DCHECK(io_message_loop_->BelongsToCurrentThread());
57
58 if (status == kQuotaStatusOk &&
59 (usage > quota * kUsageRatioToBeEvicted ||
60 physical_available_space_to_be_evicted > physical_available_space)) {
61 // Delete another origin immediately.
62 io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
63 this, &QuotaTemporaryStorageEvictor::Evict, true));
64 } else if (repeated_eviction_) {
65 // Post the next delayed task.
66 // TODO(dmikurube): How to avoid that this DelayedTask is called in tests?
67 io_message_loop_->PostDelayedTask(FROM_HERE, NewRunnableMethod(
68 this, &QuotaTemporaryStorageEvictor::Evict, false), delay_ms_);
69 }
70 }
71
72 void QuotaTemporaryStorageEvictor::CallDeleteOriginOnIOThread(
73 const GURL& origin) {
74 LOG(ERROR) << "CallDeleteOriginOnIOThread";
75 DCHECK(io_message_loop_->BelongsToCurrentThread());
76 if (quota_manager_ != NULL) {
77 quota_manager_->DeleteOriginData(
78 origin, kStorageTypeTemporary, callback_factory_.NewCallback(
79 &QuotaTemporaryStorageEvictor::OnDeletionCompletedOnIOThread));
80 }
81 }
82
83 void QuotaTemporaryStorageEvictor::CallGetUsageAndQuotaOnIOThread() {
84 LOG(ERROR) << "CallGetUsageAndQuotaOnIOThread";
85 DCHECK(io_message_loop_->BelongsToCurrentThread());
86 if (quota_manager_ != NULL) {
87 quota_manager_->GetUsageAndQuotaForEviction(callback_factory_.NewCallback(
88 &QuotaTemporaryStorageEvictor::OnDeletionCompletedOnIOThread));
89 }
90 }
91
92 void QuotaTemporaryStorageEvictor::Evict(bool delete_immediately) {
93 LOG(ERROR) << "Evict: immedeate?=" << delete_immediately;
94 if (delete_immediately) {
95 GURL origin;
96 // origin = manager_->GetLRUOriginExceptFor(/* fs_type?, */ in_use);
97 origin = GURL("http://www.example.com"); // test.
98
99 if (origin.is_empty()) {
100 LOG(ERROR) << "empty";
101 if (repeated_eviction_) {
102 io_message_loop_->PostDelayedTask(FROM_HERE, NewRunnableMethod(
103 this, &QuotaTemporaryStorageEvictor::Evict, false), delay_ms_);
104 }
105 return;
106 }
107
108 io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
109 &QuotaTemporaryStorageEvictor::CallDeleteOriginOnIOThread, origin));
110 } else {
111 io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
112 &QuotaTemporaryStorageEvictor::CallGetUsageAndQuotaOnIOThread));
113 }
114 }
115
116 void QuotaTemporaryStorageEvictor::Start() {
117 LOG(ERROR) << "Start";
118 io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
119 this, &QuotaTemporaryStorageEvictor::Evict, false));
120 }
121
122 void QuotaTemporaryStorageEvictor::DeleteOnCorrectThread() const {
123 LOG(ERROR) << "DeleteOnCorrectThread";
124 if (!io_message_loop_->BelongsToCurrentThread()) {
125 LOG(ERROR) << "io";
126 io_message_loop_->DeleteSoon(FROM_HERE, this);
127 return;
128 }
129 delete this;
130 }
131
132 } // namespace quota
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698