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