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

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: Reflected the comments, and rebased. 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 "googleurl/src/gurl.h"
8
9 namespace quota {
10
11 const double QuotaTemporaryStorageEvictor::kUsageRatioToStartEviction = 0.7;
12 const int64 QuotaTemporaryStorageEvictor::
13 kDefaultMinAvailableDiskSpaceToStartEviction = 1000 * 1000 * 500;
14
15 QuotaTemporaryStorageEvictor::QuotaTemporaryStorageEvictor(
16 QuotaEvictionHandler* quota_eviction_handler,
17 int64 interval_ms,
18 scoped_refptr<base::MessageLoopProxy> io_thread)
19 : min_available_disk_space_to_start_eviction_(
20 kDefaultMinAvailableDiskSpaceToStartEviction),
21 quota_eviction_handler_(quota_eviction_handler),
22 interval_ms_(interval_ms),
23 repeated_eviction_(false),
24 io_thread_(io_thread),
25 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
26 DCHECK(quota_eviction_handler);
27 }
28
29 QuotaTemporaryStorageEvictor::~QuotaTemporaryStorageEvictor() {
30 }
31
32 void QuotaTemporaryStorageEvictor::Start() {
33 DCHECK(io_thread_->BelongsToCurrentThread());
34 StartEvictionTimerWithDelay(0);
35 }
36
37 void QuotaTemporaryStorageEvictor::StartEvictionTimerWithDelay(int delay_ms) {
38 if (timer_.IsRunning())
39 return;
40 timer_.Start(base::TimeDelta::FromMilliseconds(delay_ms), this,
41 &QuotaTemporaryStorageEvictor::ConsiderEviction);
42 }
43
44 void QuotaTemporaryStorageEvictor::ConsiderEviction() {
45 // Get usage and disk space, then continue.
46 quota_eviction_handler_->GetUsageAndQuotaForEviction(callback_factory_.
47 NewCallback(
48 &QuotaTemporaryStorageEvictor::OnGotUsageAndQuotaForEviction));
49 }
50
51 void QuotaTemporaryStorageEvictor::OnGotUsageAndQuotaForEviction(
52 QuotaStatusCode status,
53 int64 usage,
54 int64 quota,
55 int64 available_disk_space) {
56 DCHECK(io_thread_->BelongsToCurrentThread());
57
58 if (status == kQuotaStatusOk &&
59 (usage > quota * kUsageRatioToStartEviction ||
60 min_available_disk_space_to_start_eviction_ > available_disk_space)) {
61 // Space is getting tight. Get the least recently used origin and continue.
62 quota_eviction_handler_->GetLRUOrigin(kStorageTypeTemporary,
63 callback_factory_.NewCallback(
64 &QuotaTemporaryStorageEvictor::OnGotLRUOrigin));
65 } else if (repeated_eviction_) {
66 // No action required, sleep for a while check again later.
kinuko 2011/05/24 09:20:53 nit: 'and' before 'check' (... sleep for a while *
Dai Mikurube (NOT FULLTIME) 2011/05/24 11:30:52 Done.
67 StartEvictionTimerWithDelay(interval_ms_);
68 }
kinuko 2011/05/24 09:20:53 Maybe we should have a TODO comment about error ca
Dai Mikurube (NOT FULLTIME) 2011/05/24 11:30:52 For now, added two TODO comments for stats and err
69 }
70
71 void QuotaTemporaryStorageEvictor::OnGotLRUOrigin(const GURL& origin) {
72 DCHECK(io_thread_->BelongsToCurrentThread());
73
74 if (origin.is_empty()) {
75 if (repeated_eviction_)
76 StartEvictionTimerWithDelay(interval_ms_);
77 return;
78 }
79
80 quota_eviction_handler_->EvictOriginData(origin, kStorageTypeTemporary,
81 callback_factory_.NewCallback(
82 &QuotaTemporaryStorageEvictor::OnEvictionComplete));
83 }
84
85 void QuotaTemporaryStorageEvictor::OnEvictionComplete(
86 QuotaStatusCode status) {
87 DCHECK(io_thread_->BelongsToCurrentThread());
88
89 // We many need to get rid of more space so reconsider immediately.
90 ConsiderEviction();
91 }
92
93 } // namespace quota
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698