OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/quota/quota_temporary_storage_evictor.h" | 5 #include "webkit/quota/quota_temporary_storage_evictor.h" |
6 | 6 |
| 7 #include <algorithm> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
9 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
10 #include "webkit/quota/quota_manager.h" | 12 #include "webkit/quota/quota_manager.h" |
11 | 13 |
12 #define UMA_HISTOGRAM_MBYTES(name, sample) \ | 14 #define UMA_HISTOGRAM_MBYTES(name, sample) \ |
13 UMA_HISTOGRAM_CUSTOM_COUNTS( \ | 15 UMA_HISTOGRAM_CUSTOM_COUNTS( \ |
14 (name), static_cast<int>((sample) / kMBytes), \ | 16 (name), static_cast<int>((sample) / kMBytes), \ |
15 1, 10 * 1024 * 1024 /* 10TB */, 100) | 17 1, 10 * 1024 * 1024 /* 10TB */, 100) |
16 | 18 |
(...skipping 17 matching lines...) Expand all Loading... |
34 kMinAvailableDiskSpaceToStartEvictionNotSpecified = -1; | 36 kMinAvailableDiskSpaceToStartEvictionNotSpecified = -1; |
35 | 37 |
36 QuotaTemporaryStorageEvictor::QuotaTemporaryStorageEvictor( | 38 QuotaTemporaryStorageEvictor::QuotaTemporaryStorageEvictor( |
37 QuotaEvictionHandler* quota_eviction_handler, | 39 QuotaEvictionHandler* quota_eviction_handler, |
38 int64 interval_ms) | 40 int64 interval_ms) |
39 : min_available_disk_space_to_start_eviction_( | 41 : min_available_disk_space_to_start_eviction_( |
40 kMinAvailableDiskSpaceToStartEvictionNotSpecified), | 42 kMinAvailableDiskSpaceToStartEvictionNotSpecified), |
41 quota_eviction_handler_(quota_eviction_handler), | 43 quota_eviction_handler_(quota_eviction_handler), |
42 interval_ms_(interval_ms), | 44 interval_ms_(interval_ms), |
43 repeated_eviction_(true), | 45 repeated_eviction_(true), |
44 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | |
45 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 46 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
46 DCHECK(quota_eviction_handler); | 47 DCHECK(quota_eviction_handler); |
47 } | 48 } |
48 | 49 |
49 QuotaTemporaryStorageEvictor::~QuotaTemporaryStorageEvictor() { | 50 QuotaTemporaryStorageEvictor::~QuotaTemporaryStorageEvictor() { |
50 } | 51 } |
51 | 52 |
52 void QuotaTemporaryStorageEvictor::GetStatistics( | 53 void QuotaTemporaryStorageEvictor::GetStatistics( |
53 std::map<std::string, int64>* statistics) { | 54 std::map<std::string, int64>* statistics) { |
54 DCHECK(statistics); | 55 DCHECK(statistics); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 DCHECK(CalledOnValidThread()); | 212 DCHECK(CalledOnValidThread()); |
212 | 213 |
213 if (origin.is_empty()) { | 214 if (origin.is_empty()) { |
214 if (repeated_eviction_) | 215 if (repeated_eviction_) |
215 StartEvictionTimerWithDelay(interval_ms_); | 216 StartEvictionTimerWithDelay(interval_ms_); |
216 OnEvictionRoundFinished(); | 217 OnEvictionRoundFinished(); |
217 return; | 218 return; |
218 } | 219 } |
219 | 220 |
220 quota_eviction_handler_->EvictOriginData(origin, kStorageTypeTemporary, | 221 quota_eviction_handler_->EvictOriginData(origin, kStorageTypeTemporary, |
221 callback_factory_.NewCallback( | 222 base::Bind( |
222 &QuotaTemporaryStorageEvictor::OnEvictionComplete)); | 223 &QuotaTemporaryStorageEvictor::OnEvictionComplete, |
| 224 weak_factory_.GetWeakPtr())); |
223 } | 225 } |
224 | 226 |
225 void QuotaTemporaryStorageEvictor::OnEvictionComplete( | 227 void QuotaTemporaryStorageEvictor::OnEvictionComplete( |
226 QuotaStatusCode status) { | 228 QuotaStatusCode status) { |
227 DCHECK(CalledOnValidThread()); | 229 DCHECK(CalledOnValidThread()); |
228 | 230 |
229 // Just calling ConsiderEviction() or StartEvictionTimerWithDelay() here is | 231 // Just calling ConsiderEviction() or StartEvictionTimerWithDelay() here is |
230 // ok. No need to deal with the case that all of the Delete operations fail | 232 // ok. No need to deal with the case that all of the Delete operations fail |
231 // for a certain origin. It doesn't result in trying to evict the same | 233 // for a certain origin. It doesn't result in trying to evict the same |
232 // origin permanently. The evictor skips origins which had deletion errors | 234 // origin permanently. The evictor skips origins which had deletion errors |
233 // a few times. | 235 // a few times. |
234 | 236 |
235 if (status == kQuotaStatusOk) { | 237 if (status == kQuotaStatusOk) { |
236 ++statistics_.num_evicted_origins; | 238 ++statistics_.num_evicted_origins; |
237 ++round_statistics_.num_evicted_origins_in_round; | 239 ++round_statistics_.num_evicted_origins_in_round; |
238 // We many need to get rid of more space so reconsider immediately. | 240 // We many need to get rid of more space so reconsider immediately. |
239 ConsiderEviction(); | 241 ConsiderEviction(); |
240 } else { | 242 } else { |
241 ++statistics_.num_errors_on_evicting_origin; | 243 ++statistics_.num_errors_on_evicting_origin; |
242 if (repeated_eviction_) { | 244 if (repeated_eviction_) { |
243 // Sleep for a while and retry again until we see too many errors. | 245 // Sleep for a while and retry again until we see too many errors. |
244 StartEvictionTimerWithDelay(interval_ms_); | 246 StartEvictionTimerWithDelay(interval_ms_); |
245 } | 247 } |
246 OnEvictionRoundFinished(); | 248 OnEvictionRoundFinished(); |
247 } | 249 } |
248 } | 250 } |
249 | 251 |
250 } // namespace quota | 252 } // namespace quota |
OLD | NEW |