| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "storage/browser/quota/quota_temporary_storage_evictor.h" | 5 #include "storage/browser/quota/quota_temporary_storage_evictor.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 QuotaEvictionHandler* quota_eviction_handler, | 49 QuotaEvictionHandler* quota_eviction_handler, |
| 50 int64_t interval_ms) | 50 int64_t interval_ms) |
| 51 : quota_eviction_handler_(quota_eviction_handler), | 51 : quota_eviction_handler_(quota_eviction_handler), |
| 52 interval_ms_(interval_ms), | 52 interval_ms_(interval_ms), |
| 53 timer_disabled_for_testing_(false), | 53 timer_disabled_for_testing_(false), |
| 54 weak_factory_(this) { | 54 weak_factory_(this) { |
| 55 DCHECK(quota_eviction_handler); | 55 DCHECK(quota_eviction_handler); |
| 56 } | 56 } |
| 57 | 57 |
| 58 QuotaTemporaryStorageEvictor::~QuotaTemporaryStorageEvictor() { | 58 QuotaTemporaryStorageEvictor::~QuotaTemporaryStorageEvictor() { |
| 59 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 59 } | 60 } |
| 60 | 61 |
| 61 void QuotaTemporaryStorageEvictor::GetStatistics( | 62 void QuotaTemporaryStorageEvictor::GetStatistics( |
| 62 std::map<std::string, int64_t>* statistics) { | 63 std::map<std::string, int64_t>* statistics) { |
| 63 DCHECK(statistics); | 64 DCHECK(statistics); |
| 64 | 65 |
| 65 (*statistics)["errors-on-evicting-origin"] = | 66 (*statistics)["errors-on-evicting-origin"] = |
| 66 statistics_.num_errors_on_evicting_origin; | 67 statistics_.num_errors_on_evicting_origin; |
| 67 (*statistics)["errors-on-getting-usage-and-quota"] = | 68 (*statistics)["errors-on-getting-usage-and-quota"] = |
| 68 statistics_.num_errors_on_getting_usage_and_quota; | 69 statistics_.num_errors_on_getting_usage_and_quota; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 ReportPerRoundHistogram(); | 129 ReportPerRoundHistogram(); |
| 129 time_of_end_of_last_nonskipped_round_ = base::Time::Now(); | 130 time_of_end_of_last_nonskipped_round_ = base::Time::Now(); |
| 130 } else { | 131 } else { |
| 131 ++statistics_.num_skipped_eviction_rounds; | 132 ++statistics_.num_skipped_eviction_rounds; |
| 132 } | 133 } |
| 133 // Reset stats for next round. | 134 // Reset stats for next round. |
| 134 round_statistics_ = EvictionRoundStatistics(); | 135 round_statistics_ = EvictionRoundStatistics(); |
| 135 } | 136 } |
| 136 | 137 |
| 137 void QuotaTemporaryStorageEvictor::Start() { | 138 void QuotaTemporaryStorageEvictor::Start() { |
| 138 DCHECK(CalledOnValidThread()); | 139 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 139 | 140 |
| 140 base::AutoReset<bool> auto_reset(&timer_disabled_for_testing_, false); | 141 base::AutoReset<bool> auto_reset(&timer_disabled_for_testing_, false); |
| 141 StartEvictionTimerWithDelay(0); | 142 StartEvictionTimerWithDelay(0); |
| 142 | 143 |
| 143 if (histogram_timer_.IsRunning()) | 144 if (histogram_timer_.IsRunning()) |
| 144 return; | 145 return; |
| 145 | 146 |
| 146 histogram_timer_.Start( | 147 histogram_timer_.Start( |
| 147 FROM_HERE, base::TimeDelta::FromMinutes(kHistogramReportIntervalMinutes), | 148 FROM_HERE, base::TimeDelta::FromMinutes(kHistogramReportIntervalMinutes), |
| 148 this, &QuotaTemporaryStorageEvictor::ReportPerHourHistogram); | 149 this, &QuotaTemporaryStorageEvictor::ReportPerHourHistogram); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 } else { | 222 } else { |
| 222 // TODO(dmikurube): Add error handling for the case status is not OK. | 223 // TODO(dmikurube): Add error handling for the case status is not OK. |
| 223 // TODO(dmikurube): Try restarting eviction after a while. | 224 // TODO(dmikurube): Try restarting eviction after a while. |
| 224 LOG(WARNING) << "Stopped eviction of temporary storage due to errors"; | 225 LOG(WARNING) << "Stopped eviction of temporary storage due to errors"; |
| 225 } | 226 } |
| 226 | 227 |
| 227 OnEvictionRoundFinished(); | 228 OnEvictionRoundFinished(); |
| 228 } | 229 } |
| 229 | 230 |
| 230 void QuotaTemporaryStorageEvictor::OnGotEvictionOrigin(const GURL& origin) { | 231 void QuotaTemporaryStorageEvictor::OnGotEvictionOrigin(const GURL& origin) { |
| 231 DCHECK(CalledOnValidThread()); | 232 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 232 | 233 |
| 233 if (origin.is_empty()) { | 234 if (origin.is_empty()) { |
| 234 StartEvictionTimerWithDelay(interval_ms_); | 235 StartEvictionTimerWithDelay(interval_ms_); |
| 235 OnEvictionRoundFinished(); | 236 OnEvictionRoundFinished(); |
| 236 return; | 237 return; |
| 237 } | 238 } |
| 238 | 239 |
| 239 in_progress_eviction_origins_.insert(origin); | 240 in_progress_eviction_origins_.insert(origin); |
| 240 | 241 |
| 241 quota_eviction_handler_->EvictOriginData(origin, kStorageTypeTemporary, | 242 quota_eviction_handler_->EvictOriginData(origin, kStorageTypeTemporary, |
| 242 base::Bind( | 243 base::Bind( |
| 243 &QuotaTemporaryStorageEvictor::OnEvictionComplete, | 244 &QuotaTemporaryStorageEvictor::OnEvictionComplete, |
| 244 weak_factory_.GetWeakPtr())); | 245 weak_factory_.GetWeakPtr())); |
| 245 } | 246 } |
| 246 | 247 |
| 247 void QuotaTemporaryStorageEvictor::OnEvictionComplete( | 248 void QuotaTemporaryStorageEvictor::OnEvictionComplete( |
| 248 QuotaStatusCode status) { | 249 QuotaStatusCode status) { |
| 249 DCHECK(CalledOnValidThread()); | 250 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 250 | 251 |
| 251 // Just calling ConsiderEviction() or StartEvictionTimerWithDelay() here is | 252 // Just calling ConsiderEviction() or StartEvictionTimerWithDelay() here is |
| 252 // ok. No need to deal with the case that all of the Delete operations fail | 253 // ok. No need to deal with the case that all of the Delete operations fail |
| 253 // for a certain origin. It doesn't result in trying to evict the same | 254 // for a certain origin. It doesn't result in trying to evict the same |
| 254 // origin permanently. The evictor skips origins which had deletion errors | 255 // origin permanently. The evictor skips origins which had deletion errors |
| 255 // a few times. | 256 // a few times. |
| 256 | 257 |
| 257 if (status == kQuotaStatusOk) { | 258 if (status == kQuotaStatusOk) { |
| 258 ++statistics_.num_evicted_origins; | 259 ++statistics_.num_evicted_origins; |
| 259 ++round_statistics_.num_evicted_origins_in_round; | 260 ++round_statistics_.num_evicted_origins_in_round; |
| 260 // We many need to get rid of more space so reconsider immediately. | 261 // We many need to get rid of more space so reconsider immediately. |
| 261 ConsiderEviction(); | 262 ConsiderEviction(); |
| 262 } else { | 263 } else { |
| 263 ++statistics_.num_errors_on_evicting_origin; | 264 ++statistics_.num_errors_on_evicting_origin; |
| 264 // Sleep for a while and retry again until we see too many errors. | 265 // Sleep for a while and retry again until we see too many errors. |
| 265 StartEvictionTimerWithDelay(interval_ms_); | 266 StartEvictionTimerWithDelay(interval_ms_); |
| 266 OnEvictionRoundFinished(); | 267 OnEvictionRoundFinished(); |
| 267 } | 268 } |
| 268 } | 269 } |
| 269 | 270 |
| 270 } // namespace storage | 271 } // namespace storage |
| OLD | NEW |