OLD | NEW |
---|---|
(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::OnEvictionCompleted( | |
michaeln
2011/05/23 19:53:47
Please define the methods in the .cc file in the s
Dai Mikurube (NOT FULLTIME)
2011/05/24 05:59:04
Exactly. Reordered them.
| |
33 QuotaStatusCode status) { | |
34 DCHECK(io_thread_->BelongsToCurrentThread()); | |
35 | |
36 // Check if more eviction is immediately required? | |
37 quota_eviction_handler_->GetUsageAndQuotaForEviction(callback_factory_. | |
38 NewCallback(&QuotaTemporaryStorageEvictor::EvictIfRequired)); | |
39 } | |
40 | |
41 void QuotaTemporaryStorageEvictor::DoEvict(const GURL& origin) { | |
42 DCHECK(io_thread_->BelongsToCurrentThread()); | |
43 | |
44 if (origin.is_empty()) { | |
45 if (repeated_eviction_) | |
46 MayStartEviction(interval_ms_); | |
47 return; | |
48 } | |
49 | |
50 quota_eviction_handler_->EvictOriginData(origin, kStorageTypeTemporary, | |
51 callback_factory_.NewCallback( | |
52 &QuotaTemporaryStorageEvictor::OnEvictionCompleted)); | |
53 } | |
54 | |
55 void QuotaTemporaryStorageEvictor::EvictIfRequired( | |
56 QuotaStatusCode status, | |
57 int64 usage, | |
58 int64 quota, | |
59 int64 available_disk_space) { | |
60 DCHECK(io_thread_->BelongsToCurrentThread()); | |
61 | |
62 if (status == kQuotaStatusOk && | |
63 (usage > quota * kUsageRatioToStartEviction || | |
64 min_available_disk_space_to_start_eviction_ > available_disk_space)) { | |
65 quota_eviction_handler_->GetLRUOrigin(kStorageTypeTemporary, | |
66 callback_factory_.NewCallback(&QuotaTemporaryStorageEvictor::DoEvict)); | |
67 } else if (repeated_eviction_) { | |
68 MayStartEviction(interval_ms_); | |
69 } | |
70 } | |
71 | |
72 void QuotaTemporaryStorageEvictor::GetUsageAndQuotaThenEvict() { | |
73 quota_eviction_handler_->GetUsageAndQuotaForEviction(callback_factory_. | |
74 NewCallback(&QuotaTemporaryStorageEvictor::EvictIfRequired)); | |
75 } | |
76 | |
77 void QuotaTemporaryStorageEvictor::MayStartEviction(int interval_ms) { | |
78 if (timer_.IsRunning()) | |
79 return; | |
80 timer_.Start(base::TimeDelta::FromMilliseconds(interval_ms), this, | |
81 &QuotaTemporaryStorageEvictor::GetUsageAndQuotaThenEvict); | |
82 } | |
83 | |
84 void QuotaTemporaryStorageEvictor::Start() { | |
85 DCHECK(io_thread_->BelongsToCurrentThread()); | |
86 MayStartEviction(0); | |
87 } | |
88 | |
89 } // namespace quota | |
OLD | NEW |