| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 round_statistics_.usage_on_beginning_of_round = usage; | 188 round_statistics_.usage_on_beginning_of_round = usage; |
| 189 round_statistics_.is_initialized = true; | 189 round_statistics_.is_initialized = true; |
| 190 } | 190 } |
| 191 round_statistics_.usage_on_end_of_round = usage; | 191 round_statistics_.usage_on_end_of_round = usage; |
| 192 | 192 |
| 193 int64 amount_to_evict = std::max(usage_overage, diskspace_shortage); | 193 int64 amount_to_evict = std::max(usage_overage, diskspace_shortage); |
| 194 if (status == kQuotaStatusOk && amount_to_evict > 0) { | 194 if (status == kQuotaStatusOk && amount_to_evict > 0) { |
| 195 // Space is getting tight. Get the least recently used origin and continue. | 195 // Space is getting tight. Get the least recently used origin and continue. |
| 196 // TODO(michaeln): if the reason for eviction is low physical disk space, | 196 // TODO(michaeln): if the reason for eviction is low physical disk space, |
| 197 // make 'unlimited' origins subject to eviction too. | 197 // make 'unlimited' origins subject to eviction too. |
| 198 quota_eviction_handler_->GetLRUOrigin( | 198 quota_eviction_handler_->GetEvictionOrigin( |
| 199 kStorageTypeTemporary, | 199 kStorageTypeTemporary, |
| 200 base::Bind(&QuotaTemporaryStorageEvictor::OnGotLRUOrigin, | 200 base::Bind(&QuotaTemporaryStorageEvictor::OnGotEvictionOrigin, |
| 201 weak_factory_.GetWeakPtr())); | 201 weak_factory_.GetWeakPtr())); |
| 202 } else { | 202 } else { |
| 203 if (repeated_eviction_) { | 203 if (repeated_eviction_) { |
| 204 // No action required, sleep for a while and check again later. | 204 // No action required, sleep for a while and check again later. |
| 205 if (statistics_.num_errors_on_getting_usage_and_quota < | 205 if (statistics_.num_errors_on_getting_usage_and_quota < |
| 206 kThresholdOfErrorsToStopEviction) { | 206 kThresholdOfErrorsToStopEviction) { |
| 207 StartEvictionTimerWithDelay(interval_ms_); | 207 StartEvictionTimerWithDelay(interval_ms_); |
| 208 } else { | 208 } else { |
| 209 // TODO(dmikurube): Try restarting eviction after a while. | 209 // TODO(dmikurube): Try restarting eviction after a while. |
| 210 LOG(WARNING) << "Stopped eviction of temporary storage due to errors " | 210 LOG(WARNING) << "Stopped eviction of temporary storage due to errors " |
| 211 "in GetUsageAndQuotaForEviction."; | 211 "in GetUsageAndQuotaForEviction."; |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 OnEvictionRoundFinished(); | 214 OnEvictionRoundFinished(); |
| 215 } | 215 } |
| 216 | 216 |
| 217 // TODO(dmikurube): Add error handling for the case status != kQuotaStatusOk. | 217 // TODO(dmikurube): Add error handling for the case status != kQuotaStatusOk. |
| 218 } | 218 } |
| 219 | 219 |
| 220 void QuotaTemporaryStorageEvictor::OnGotLRUOrigin(const GURL& origin) { | 220 void QuotaTemporaryStorageEvictor::OnGotEvictionOrigin(const GURL& origin) { |
| 221 DCHECK(CalledOnValidThread()); | 221 DCHECK(CalledOnValidThread()); |
| 222 | 222 |
| 223 if (origin.is_empty()) { | 223 if (origin.is_empty()) { |
| 224 if (repeated_eviction_) | 224 if (repeated_eviction_) |
| 225 StartEvictionTimerWithDelay(interval_ms_); | 225 StartEvictionTimerWithDelay(interval_ms_); |
| 226 OnEvictionRoundFinished(); | 226 OnEvictionRoundFinished(); |
| 227 return; | 227 return; |
| 228 } | 228 } |
| 229 | 229 |
| 230 quota_eviction_handler_->EvictOriginData(origin, kStorageTypeTemporary, | 230 quota_eviction_handler_->EvictOriginData(origin, kStorageTypeTemporary, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 252 ++statistics_.num_errors_on_evicting_origin; | 252 ++statistics_.num_errors_on_evicting_origin; |
| 253 if (repeated_eviction_) { | 253 if (repeated_eviction_) { |
| 254 // Sleep for a while and retry again until we see too many errors. | 254 // Sleep for a while and retry again until we see too many errors. |
| 255 StartEvictionTimerWithDelay(interval_ms_); | 255 StartEvictionTimerWithDelay(interval_ms_); |
| 256 } | 256 } |
| 257 OnEvictionRoundFinished(); | 257 OnEvictionRoundFinished(); |
| 258 } | 258 } |
| 259 } | 259 } |
| 260 | 260 |
| 261 } // namespace storage | 261 } // namespace storage |
| OLD | NEW |