| 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 #ifndef STORAGE_BROWSER_QUOTA_QUOTA_TEMPORARY_STORAGE_EVICTOR_H_ | 5 #ifndef STORAGE_BROWSER_QUOTA_QUOTA_TEMPORARY_STORAGE_EVICTOR_H_ |
| 6 #define STORAGE_BROWSER_QUOTA_QUOTA_TEMPORARY_STORAGE_EVICTOR_H_ | 6 #define STORAGE_BROWSER_QUOTA_QUOTA_TEMPORARY_STORAGE_EVICTOR_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/threading/non_thread_safe.h" | 16 #include "base/threading/non_thread_safe.h" |
| 17 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
| 18 #include "storage/browser/storage_browser_export.h" | 18 #include "storage/browser/storage_browser_export.h" |
| 19 #include "storage/common/quota/quota_types.h" | 19 #include "storage/common/quota/quota_types.h" |
| 20 | 20 |
| 21 class GURL; | 21 class GURL; |
| 22 | 22 |
| 23 namespace content { | 23 namespace content { |
| 24 class QuotaTemporaryStorageEvictorTest; | 24 class QuotaTemporaryStorageEvictorTest; |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace storage { | 27 namespace storage { |
| 28 | 28 |
| 29 class QuotaEvictionHandler; | 29 class QuotaEvictionHandler; |
| 30 struct UsageAndQuota; | 30 struct TemporaryStorageConfiguration; |
| 31 | 31 |
| 32 class STORAGE_EXPORT QuotaTemporaryStorageEvictor : public base::NonThreadSafe { | 32 class STORAGE_EXPORT QuotaTemporaryStorageEvictor : public base::NonThreadSafe { |
| 33 public: | 33 public: |
| 34 struct Statistics { | 34 struct Statistics { |
| 35 Statistics() | 35 Statistics() |
| 36 : num_errors_on_evicting_origin(0), | 36 : num_errors_on_evicting_origin(0), |
| 37 num_errors_on_getting_usage_and_quota(0), | 37 num_errors_on_getting_usage_and_quota(0), |
| 38 num_evicted_origins(0), | 38 num_evicted_origins(0), |
| 39 num_eviction_rounds(0), | 39 num_eviction_rounds(0), |
| 40 num_skipped_eviction_rounds(0) {} | 40 num_skipped_eviction_rounds(0) {} |
| (...skipping 30 matching lines...) Expand all Loading... |
| 71 | 71 |
| 72 QuotaTemporaryStorageEvictor(QuotaEvictionHandler* quota_eviction_handler, | 72 QuotaTemporaryStorageEvictor(QuotaEvictionHandler* quota_eviction_handler, |
| 73 int64_t interval_ms); | 73 int64_t interval_ms); |
| 74 virtual ~QuotaTemporaryStorageEvictor(); | 74 virtual ~QuotaTemporaryStorageEvictor(); |
| 75 | 75 |
| 76 void GetStatistics(std::map<std::string, int64_t>* statistics); | 76 void GetStatistics(std::map<std::string, int64_t>* statistics); |
| 77 void ReportPerRoundHistogram(); | 77 void ReportPerRoundHistogram(); |
| 78 void ReportPerHourHistogram(); | 78 void ReportPerHourHistogram(); |
| 79 void Start(); | 79 void Start(); |
| 80 | 80 |
| 81 void reset_min_available_disk_space_to_start_eviction() { | |
| 82 min_available_to_start_eviction_ = | |
| 83 kMinAvailableToStartEvictionNotSpecified; | |
| 84 } | |
| 85 void set_min_available_disk_space_to_start_eviction(int64_t value) { | |
| 86 min_available_to_start_eviction_ = value; | |
| 87 } | |
| 88 | |
| 89 private: | 81 private: |
| 90 friend class content::QuotaTemporaryStorageEvictorTest; | 82 friend class content::QuotaTemporaryStorageEvictorTest; |
| 91 | 83 |
| 92 void StartEvictionTimerWithDelay(int delay_ms); | 84 void StartEvictionTimerWithDelay(int delay_ms); |
| 93 void ConsiderEviction(); | 85 void ConsiderEviction(); |
| 94 void OnGotVolumeInfo(bool success, | 86 void OnGotEvictionRoundInfo( |
| 95 uint64_t available_space, | 87 QuotaStatusCode status, const TemporaryStorageConfiguration& config, |
| 96 uint64_t total_size); | 88 int64_t available_space, int64_t total_space, |
| 97 void OnGotUsageAndQuotaForEviction( | 89 int64_t current_usage, bool current_usage_is_complete); |
| 98 int64_t must_remain_available_space, | |
| 99 QuotaStatusCode status, | |
| 100 const UsageAndQuota& quota_and_usage); | |
| 101 void OnGotEvictionOrigin(const GURL& origin); | 90 void OnGotEvictionOrigin(const GURL& origin); |
| 102 void OnEvictionComplete(QuotaStatusCode status); | 91 void OnEvictionComplete(QuotaStatusCode status); |
| 103 | 92 |
| 104 void OnEvictionRoundStarted(); | 93 void OnEvictionRoundStarted(); |
| 105 void OnEvictionRoundFinished(); | 94 void OnEvictionRoundFinished(); |
| 106 | 95 |
| 107 // This is only used for tests. | |
| 108 void set_repeated_eviction(bool repeated_eviction) { | |
| 109 repeated_eviction_ = repeated_eviction; | |
| 110 } | |
| 111 | |
| 112 static const int kMinAvailableToStartEvictionNotSpecified; | |
| 113 | |
| 114 int64_t min_available_to_start_eviction_; | |
| 115 | |
| 116 // Not owned; quota_eviction_handler owns us. | 96 // Not owned; quota_eviction_handler owns us. |
| 117 QuotaEvictionHandler* quota_eviction_handler_; | 97 QuotaEvictionHandler* quota_eviction_handler_; |
| 118 | 98 |
| 119 Statistics statistics_; | 99 Statistics statistics_; |
| 120 Statistics previous_statistics_; | 100 Statistics previous_statistics_; |
| 121 EvictionRoundStatistics round_statistics_; | 101 EvictionRoundStatistics round_statistics_; |
| 122 base::Time time_of_end_of_last_nonskipped_round_; | 102 base::Time time_of_end_of_last_nonskipped_round_; |
| 123 base::Time time_of_end_of_last_round_; | 103 base::Time time_of_end_of_last_round_; |
| 124 std::set<GURL> in_progress_eviction_origins_; | 104 std::set<GURL> in_progress_eviction_origins_; |
| 125 | 105 |
| 126 int64_t interval_ms_; | 106 int64_t interval_ms_; |
| 127 bool repeated_eviction_; | 107 bool timer_disabled_for_testing_; |
| 128 | 108 |
| 129 base::OneShotTimer eviction_timer_; | 109 base::OneShotTimer eviction_timer_; |
| 130 base::RepeatingTimer histogram_timer_; | 110 base::RepeatingTimer histogram_timer_; |
| 131 base::WeakPtrFactory<QuotaTemporaryStorageEvictor> weak_factory_; | 111 base::WeakPtrFactory<QuotaTemporaryStorageEvictor> weak_factory_; |
| 132 | 112 |
| 133 DISALLOW_COPY_AND_ASSIGN(QuotaTemporaryStorageEvictor); | 113 DISALLOW_COPY_AND_ASSIGN(QuotaTemporaryStorageEvictor); |
| 134 }; | 114 }; |
| 135 | 115 |
| 136 } // namespace storage | 116 } // namespace storage |
| 137 | 117 |
| 138 #endif // STORAGE_BROWSER_QUOTA_QUOTA_TEMPORARY_STORAGE_EVICTOR_H_ | 118 #endif // STORAGE_BROWSER_QUOTA_QUOTA_TEMPORARY_STORAGE_EVICTOR_H_ |
| OLD | NEW |