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::kUsageRatioToBeEvicted = 0.7; | |
12 | |
13 QuotaTemporaryStorageEvictor::QuotaTemporaryStorageEvictor( | |
14 QuotaEvictionHandler* quota_eviction_handler, | |
15 int64 target_available_space, | |
16 int64 delay_ms, | |
17 scoped_refptr<base::MessageLoopProxy> io_thread) | |
18 : physical_available_space_to_be_evicted(1000 * 1000 * 500), | |
kinuko
2011/05/19 09:27:18
nit: to be evicted -> to start eviction ? (from th
Dai Mikurube (NOT FULLTIME)
2011/05/20 02:42:24
Renamed them to:
static const double kUsageRatio
| |
19 quota_eviction_handler_(quota_eviction_handler), | |
20 target_available_space_(target_available_space), | |
kinuko
2011/05/19 09:27:18
not used now?
Dai Mikurube (NOT FULLTIME)
2011/05/20 02:42:24
Done.
| |
21 delay_ms_(delay_ms), | |
kinuko
2011/05/19 09:27:18
interval_ms_? (since this is used for repeated evi
Dai Mikurube (NOT FULLTIME)
2011/05/20 02:42:24
My thought was that it might be changed at run-tim
kinuko
2011/05/20 06:41:13
Ok if we change the value it makes sense.
| |
22 repeated_eviction_(false), | |
23 io_thread_(io_thread), | |
24 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | |
kinuko
2011/05/19 09:27:18
I guess now we can DCHECK(quota_eviction_handler)
Dai Mikurube (NOT FULLTIME)
2011/05/20 02:42:24
Done.
| |
25 } | |
26 | |
27 QuotaTemporaryStorageEvictor::~QuotaTemporaryStorageEvictor() { | |
28 } | |
29 | |
30 void QuotaTemporaryStorageEvictor::OnQuotaManagerDestroyedOnIOThread() { | |
kinuko
2011/05/19 09:27:18
Now we can happily get rid of this.
Dai Mikurube (NOT FULLTIME)
2011/05/20 02:42:24
Done.
| |
31 DCHECK(io_thread_->BelongsToCurrentThread()); | |
32 quota_eviction_handler_ = NULL; | |
33 } | |
34 | |
35 void QuotaTemporaryStorageEvictor::OnEvictionCompleted( | |
36 QuotaStatusCode status) { | |
37 DCHECK(io_thread_->BelongsToCurrentThread()); | |
38 | |
39 // Check if more eviction is immediately required? | |
40 if (quota_eviction_handler_ != NULL) { | |
41 quota_eviction_handler_->GetUsageAndQuotaForEviction(callback_factory_. | |
42 NewCallback(&QuotaTemporaryStorageEvictor::EvictIfRequired)); | |
43 } | |
44 } | |
45 | |
46 void QuotaTemporaryStorageEvictor::DoEvict(const GURL& origin) { | |
47 DCHECK(io_thread_->BelongsToCurrentThread()); | |
48 | |
49 if (origin.is_empty()) { | |
50 if (repeated_eviction_) | |
51 repeated_eviction_ = false; | |
kinuko
2011/05/19 09:27:18
why do we flip the flag here?
GetLRUOrigin may re
Dai Mikurube (NOT FULLTIME)
2011/05/20 02:42:24
Oh, I wrongly edited this line. MayStartEviction(
| |
52 return; | |
53 } | |
54 | |
55 if (quota_eviction_handler_ != NULL) { | |
56 quota_eviction_handler_->EvictOriginData( | |
57 origin, kStorageTypeTemporary, callback_factory_.NewCallback( | |
58 &QuotaTemporaryStorageEvictor::OnEvictionCompleted)); | |
59 } | |
60 } | |
61 | |
62 void QuotaTemporaryStorageEvictor::EvictIfRequired( | |
63 QuotaStatusCode status, | |
64 int64 usage, | |
65 int64 quota, | |
66 int64 physical_available_space) { | |
67 DCHECK(io_thread_->BelongsToCurrentThread()); | |
68 | |
69 if (status == kQuotaStatusOk && | |
70 (usage > quota * kUsageRatioToBeEvicted || | |
71 physical_available_space_to_be_evicted > physical_available_space)) { | |
72 if (quota_eviction_handler_ != NULL) { | |
73 quota_eviction_handler_->GetLRUOrigin(kStorageTypeTemporary, | |
74 callback_factory_.NewCallback( | |
75 &QuotaTemporaryStorageEvictor::DoEvict)); | |
76 } | |
77 } else if (repeated_eviction_) { | |
kinuko
2011/05/19 09:27:18
Maybe if we get status != kQuotaStatusOk more than
Dai Mikurube (NOT FULLTIME)
2011/05/20 02:42:24
We should discuss error handling for the entire ev
kinuko
2011/05/20 06:41:13
sgtm.
For the latter case we may also want to remo
| |
78 MayStartEviction(delay_ms_); | |
79 } | |
80 } | |
81 | |
82 void QuotaTemporaryStorageEvictor::GetUsageAndQuotaThenEvict() { | |
83 if (quota_eviction_handler_ != NULL) { | |
84 quota_eviction_handler_->GetUsageAndQuotaForEviction(callback_factory_. | |
85 NewCallback(&QuotaTemporaryStorageEvictor::EvictIfRequired)); | |
86 } | |
87 } | |
88 | |
89 void QuotaTemporaryStorageEvictor::MayStartEviction(int delay_ms) { | |
90 if (timer_.IsRunning()) | |
91 return; | |
92 timer_.Start(base::TimeDelta::FromMilliseconds(delay_ms), this, | |
93 &QuotaTemporaryStorageEvictor::GetUsageAndQuotaThenEvict); | |
94 } | |
95 | |
96 void QuotaTemporaryStorageEvictor::Start() { | |
kinuko
2011/05/19 09:27:18
Do we need this func? (I guess we could either cal
Dai Mikurube (NOT FULLTIME)
2011/05/20 02:42:24
Hmm, MayStartEviction and GetUsageAndQuotaThenEvic
kinuko
2011/05/20 06:43:49
First I thought GetUsageAndQuotaThenEvict could be
Dai Mikurube (NOT FULLTIME)
2011/05/20 07:36:54
Finally, you say which should be MayStartEviction(
| |
97 DCHECK(io_thread_->BelongsToCurrentThread()); | |
98 MayStartEviction(0); | |
99 } | |
100 | |
101 } // namespace quota | |
OLD | NEW |