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

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: Modified to fit http://codereview.chromium.org/7029009/. 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(
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.
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::OnGottenUsageAndQuotaOnIOThread(
51 QuotaStatusCode status,
52 int64 usage,
53 int64 quota,
54 int64 physical_available_space) {
55 LOG(ERROR) << "OnGottenUsageAndQuotaOnIOThread";
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 // Evict another origin immediately.
62 io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
63 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
64 } else if (repeated_eviction_) {
65 // Post the next delayed task.
66 io_message_loop_->PostDelayedTask(FROM_HERE, NewRunnableMethod(
67 this, &QuotaTemporaryStorageEvictor::Evict, false), delay_ms_);
68 }
69 }
70
71 void QuotaTemporaryStorageEvictor::CallGetUsageAndQuotaOnIOThread() {
72 LOG(ERROR) << "CallGetUsageAndQuotaOnIOThread";
73 DCHECK(io_message_loop_->BelongsToCurrentThread());
74 if (quota_manager_ != NULL) {
75 quota_manager_->GetUsageAndQuotaForEviction(callback_factory_.NewCallback(
76 &QuotaTemporaryStorageEvictor::OnGottenUsageAndQuotaOnIOThread));
77 }
78 }
79
80 void QuotaTemporaryStorageEvictor::OnEvictionCompletedOnIOThread(
81 QuotaStatusCode status) {
82 LOG(ERROR) << "OnDeletionCompletedOnIOThread";
83 DCHECK(io_message_loop_->BelongsToCurrentThread());
84 io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
85 &QuotaTemporaryStorageEvictor::CallGetUsageAndQuotaOnIOThread));
kinuko 2011/05/19 03:04:13 We can just chain to call mgr->GetUsageAndQuotaFor
86 }
87
88 void QuotaTemporaryStorageEvictor::CallEvictOriginOnIOThread(
89 const GURL& origin) {
90 LOG(ERROR) << "CallEvictOriginOnIOThread";
91 DCHECK(io_message_loop_->BelongsToCurrentThread());
92 if (quota_manager_ != NULL) {
93 quota_manager_->EvictOriginData(
94 origin, kStorageTypeTemporary, callback_factory_.NewCallback(
95 &QuotaTemporaryStorageEvictor::OnEvictionCompletedOnIOThread));
96 }
97 }
98
99 void QuotaTemporaryStorageEvictor::Evict(bool delete_immediately) {
100 LOG(ERROR) << "Evict: immedeate?=" << delete_immediately;
101 if (delete_immediately) {
102 GURL origin;
103 // origin = manager_->GetLRUOriginExceptFor(/* fs_type?, */ in_use);
104 origin = GURL("http://www.example.com"); // test.
105
106 if (origin.is_empty()) {
107 LOG(ERROR) << "empty";
108 if (repeated_eviction_) {
109 io_message_loop_->PostDelayedTask(FROM_HERE, NewRunnableMethod(
110 this, &QuotaTemporaryStorageEvictor::Evict, false), delay_ms_);
111 }
112 return;
113 }
114
115 io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
116 &QuotaTemporaryStorageEvictor::CallEvictOriginOnIOThread, origin));
117 } else {
118 io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
119 &QuotaTemporaryStorageEvictor::CallGetUsageAndQuotaOnIOThread));
kinuko 2011/05/19 03:04:13 ditto
120 }
121 }
122
123 void QuotaTemporaryStorageEvictor::Start() {
124 LOG(ERROR) << "Start";
125 io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
126 this, &QuotaTemporaryStorageEvictor::Evict, false));
127 }
128
129 void QuotaTemporaryStorageEvictor::DeleteOnCorrectThread() const {
130 LOG(ERROR) << "DeleteOnCorrectThread";
131 if (!io_message_loop_->BelongsToCurrentThread()) {
132 LOG(ERROR) << "io";
133 io_message_loop_->DeleteSoon(FROM_HERE, this);
134 return;
135 }
136 delete this;
137 }
138
139 } // namespace quota
OLDNEW
« no previous file with comments | « webkit/quota/quota_temporary_storage_evictor.h ('k') | webkit/quota/quota_temporary_storage_evictor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698