| 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 #ifndef WEBKIT_QUOTA_QUOTA_TEMPORARY_STORAGE_EVICTOR_H_ | 5 #ifndef WEBKIT_QUOTA_QUOTA_TEMPORARY_STORAGE_EVICTOR_H_ |
| 6 #define WEBKIT_QUOTA_QUOTA_TEMPORARY_STORAGE_EVICTOR_H_ | 6 #define WEBKIT_QUOTA_QUOTA_TEMPORARY_STORAGE_EVICTOR_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 num_evicted_origins(0), | 33 num_evicted_origins(0), |
| 34 num_eviction_rounds(0), | 34 num_eviction_rounds(0), |
| 35 num_skipped_eviction_rounds(0) {} | 35 num_skipped_eviction_rounds(0) {} |
| 36 int64 num_errors_on_evicting_origin; | 36 int64 num_errors_on_evicting_origin; |
| 37 int64 num_errors_on_getting_usage_and_quota; | 37 int64 num_errors_on_getting_usage_and_quota; |
| 38 int64 num_evicted_origins; | 38 int64 num_evicted_origins; |
| 39 int64 num_eviction_rounds; | 39 int64 num_eviction_rounds; |
| 40 int64 num_skipped_eviction_rounds; | 40 int64 num_skipped_eviction_rounds; |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 struct EvictionRoundStatistics { |
| 44 EvictionRoundStatistics() |
| 45 : started(false), |
| 46 amount_of_usage_overage(-1), |
| 47 amount_of_diskspace_shortage(-1), |
| 48 usage_on_beginning_of_round(-1), |
| 49 usage_on_end_of_round(-1), |
| 50 num_evicted_origins(0) { |
| 51 } |
| 52 |
| 53 void put_usage_overage(int64 overage) { |
| 54 if (amount_of_usage_overage < 0) |
| 55 amount_of_usage_overage = overage; |
| 56 } |
| 57 |
| 58 void put_diskspace_shortage(int64 diskspace_shortage) { |
| 59 if (amount_of_diskspace_shortage < 0) |
| 60 amount_of_diskspace_shortage = diskspace_shortage; |
| 61 } |
| 62 |
| 63 void put_usage(int64 usage) { |
| 64 if (usage_on_beginning_of_round < 0) |
| 65 usage_on_beginning_of_round = usage; |
| 66 usage_on_end_of_round = usage; |
| 67 } |
| 68 |
| 69 bool started; |
| 70 |
| 71 base::Time start_time; |
| 72 int64 amount_of_usage_overage; |
| 73 int64 amount_of_diskspace_shortage; |
| 74 |
| 75 int64 usage_on_beginning_of_round; |
| 76 int64 usage_on_end_of_round; |
| 77 int64 num_evicted_origins; |
| 78 }; |
| 79 |
| 43 QuotaTemporaryStorageEvictor( | 80 QuotaTemporaryStorageEvictor( |
| 44 QuotaEvictionHandler* quota_eviction_handler, | 81 QuotaEvictionHandler* quota_eviction_handler, |
| 45 int64 interval_ms); | 82 int64 interval_ms); |
| 46 virtual ~QuotaTemporaryStorageEvictor(); | 83 virtual ~QuotaTemporaryStorageEvictor(); |
| 47 | 84 |
| 48 void GetStatistics(std::map<std::string, int64>* statistics); | 85 void GetStatistics(std::map<std::string, int64>* statistics); |
| 49 void ReportHistogram(); | 86 void ReportPerRoundHistogram(); |
| 87 void ReportPerHourHistogram(); |
| 50 void Start(); | 88 void Start(); |
| 51 | 89 |
| 52 private: | 90 private: |
| 53 friend class QuotaTemporaryStorageEvictorTest; | 91 friend class QuotaTemporaryStorageEvictorTest; |
| 54 | 92 |
| 55 void StartEvictionTimerWithDelay(int delay_ms); | 93 void StartEvictionTimerWithDelay(int delay_ms); |
| 56 void ConsiderEviction(); | 94 void ConsiderEviction(); |
| 57 void OnGotUsageAndQuotaForEviction( | 95 void OnGotUsageAndQuotaForEviction( |
| 58 QuotaStatusCode status, | 96 QuotaStatusCode status, |
| 59 int64 usage, | 97 int64 usage, |
| 60 int64 unlimited_usage, | 98 int64 unlimited_usage, |
| 61 int64 quota, | 99 int64 quota, |
| 62 int64 available_disk_space); | 100 int64 available_disk_space); |
| 63 void OnGotLRUOrigin(const GURL& origin); | 101 void OnGotLRUOrigin(const GURL& origin); |
| 64 void OnEvictionComplete(QuotaStatusCode status); | 102 void OnEvictionComplete(QuotaStatusCode status); |
| 65 | 103 |
| 104 void OnEvictionRoundStarted(); |
| 105 void OnEvictionRoundFinished(); |
| 106 |
| 66 // This is only used for tests. | 107 // This is only used for tests. |
| 67 void set_repeated_eviction(bool repeated_eviction) { | 108 void set_repeated_eviction(bool repeated_eviction) { |
| 68 repeated_eviction_ = repeated_eviction; | 109 repeated_eviction_ = repeated_eviction; |
| 69 } | 110 } |
| 70 | 111 |
| 71 static const double kUsageRatioToStartEviction; | 112 static const double kUsageRatioToStartEviction; |
| 72 static const int64 kDefaultMinAvailableDiskSpaceToStartEviction; | 113 static const int64 kDefaultMinAvailableDiskSpaceToStartEviction; |
| 73 static const int kThresholdOfErrorsToStopEviction; | 114 static const int kThresholdOfErrorsToStopEviction; |
| 74 static const base::TimeDelta kHistogramReportInterval; | 115 static const base::TimeDelta kHistogramReportInterval; |
| 75 | 116 |
| 76 const int64 min_available_disk_space_to_start_eviction_; | 117 const int64 min_available_disk_space_to_start_eviction_; |
| 77 | 118 |
| 78 // Not owned; quota_eviction_handler owns us. | 119 // Not owned; quota_eviction_handler owns us. |
| 79 QuotaEvictionHandler* quota_eviction_handler_; | 120 QuotaEvictionHandler* quota_eviction_handler_; |
| 80 | 121 |
| 81 Statistics statistics_; | 122 Statistics statistics_; |
| 123 EvictionRoundStatistics round_statistics_; |
| 124 base::Time time_of_last_nonskipped_round_; |
| 125 base::Time time_of_end_of_last_round_; |
| 82 | 126 |
| 83 int64 interval_ms_; | 127 int64 interval_ms_; |
| 84 bool repeated_eviction_; | 128 bool repeated_eviction_; |
| 85 int num_evicted_origins_in_round_; | |
| 86 | |
| 87 int64 usage_on_beginning_of_round_; | |
| 88 base::Time time_of_beginning_of_round_; | |
| 89 base::Time time_of_end_of_last_round_; | |
| 90 | 129 |
| 91 base::OneShotTimer<QuotaTemporaryStorageEvictor> eviction_timer_; | 130 base::OneShotTimer<QuotaTemporaryStorageEvictor> eviction_timer_; |
| 92 base::RepeatingTimer<QuotaTemporaryStorageEvictor> histogram_timer_; | 131 base::RepeatingTimer<QuotaTemporaryStorageEvictor> histogram_timer_; |
| 93 | 132 |
| 94 base::ScopedCallbackFactory<QuotaTemporaryStorageEvictor> callback_factory_; | 133 base::ScopedCallbackFactory<QuotaTemporaryStorageEvictor> callback_factory_; |
| 95 | 134 |
| 96 DISALLOW_COPY_AND_ASSIGN(QuotaTemporaryStorageEvictor); | 135 DISALLOW_COPY_AND_ASSIGN(QuotaTemporaryStorageEvictor); |
| 97 }; | 136 }; |
| 98 | 137 |
| 99 } // namespace quota | 138 } // namespace quota |
| 100 | 139 |
| 101 #endif // WEBKIT_QUOTA_QUOTA_TEMPORARY_STORAGE_EVICTOR_H_ | 140 #endif // WEBKIT_QUOTA_QUOTA_TEMPORARY_STORAGE_EVICTOR_H_ |
| OLD | NEW |