We started redesigning GpuMemoryBuffer interface to handle multiple buffers [0].
[chromium-blink-merge.git] / storage / browser / quota / quota_temporary_storage_evictor.h
blob706355d37bd0265fe0d18f604fce6cd875311029
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
3 // found in the LICENSE file.
5 #ifndef STORAGE_BROWSER_QUOTA_QUOTA_TEMPORARY_STORAGE_EVICTOR_H_
6 #define STORAGE_BROWSER_QUOTA_QUOTA_TEMPORARY_STORAGE_EVICTOR_H_
8 #include <map>
9 #include <string>
11 #include "base/memory/weak_ptr.h"
12 #include "base/threading/non_thread_safe.h"
13 #include "base/timer/timer.h"
14 #include "storage/browser/storage_browser_export.h"
15 #include "storage/common/quota/quota_types.h"
17 class GURL;
19 namespace content {
20 class QuotaTemporaryStorageEvictorTest;
23 namespace storage {
25 class QuotaEvictionHandler;
26 struct UsageAndQuota;
28 class STORAGE_EXPORT_PRIVATE QuotaTemporaryStorageEvictor
29 : public base::NonThreadSafe {
30 public:
31 struct Statistics {
32 Statistics()
33 : num_errors_on_evicting_origin(0),
34 num_errors_on_getting_usage_and_quota(0),
35 num_evicted_origins(0),
36 num_eviction_rounds(0),
37 num_skipped_eviction_rounds(0) {}
38 int64 num_errors_on_evicting_origin;
39 int64 num_errors_on_getting_usage_and_quota;
40 int64 num_evicted_origins;
41 int64 num_eviction_rounds;
42 int64 num_skipped_eviction_rounds;
44 void subtract_assign(const Statistics& rhs) {
45 num_errors_on_evicting_origin -= rhs.num_errors_on_evicting_origin;
46 num_errors_on_getting_usage_and_quota -=
47 rhs.num_errors_on_getting_usage_and_quota;
48 num_evicted_origins -= rhs.num_evicted_origins;
49 num_eviction_rounds -= rhs.num_eviction_rounds;
50 num_skipped_eviction_rounds -= rhs.num_skipped_eviction_rounds;
54 struct EvictionRoundStatistics {
55 EvictionRoundStatistics();
57 bool in_round;
58 bool is_initialized;
60 base::Time start_time;
61 int64 usage_overage_at_round;
62 int64 diskspace_shortage_at_round;
64 int64 usage_on_beginning_of_round;
65 int64 usage_on_end_of_round;
66 int64 num_evicted_origins_in_round;
69 QuotaTemporaryStorageEvictor(
70 QuotaEvictionHandler* quota_eviction_handler,
71 int64 interval_ms);
72 virtual ~QuotaTemporaryStorageEvictor();
74 void GetStatistics(std::map<std::string, int64>* statistics);
75 void ReportPerRoundHistogram();
76 void ReportPerHourHistogram();
77 void Start();
79 int64 min_available_disk_space_to_start_eviction() {
80 return min_available_disk_space_to_start_eviction_;
82 void reset_min_available_disk_space_to_start_eviction() {
83 min_available_disk_space_to_start_eviction_ =
84 kMinAvailableDiskSpaceToStartEvictionNotSpecified;
86 void set_min_available_disk_space_to_start_eviction(int64 value) {
87 min_available_disk_space_to_start_eviction_ = value;
90 private:
91 friend class content::QuotaTemporaryStorageEvictorTest;
93 void StartEvictionTimerWithDelay(int delay_ms);
94 void ConsiderEviction();
95 void OnGotUsageAndQuotaForEviction(
96 QuotaStatusCode status,
97 const UsageAndQuota& quota_and_usage);
98 void OnGotLRUOrigin(const GURL& origin);
99 void OnEvictionComplete(QuotaStatusCode status);
101 void OnEvictionRoundStarted();
102 void OnEvictionRoundFinished();
104 // This is only used for tests.
105 void set_repeated_eviction(bool repeated_eviction) {
106 repeated_eviction_ = repeated_eviction;
109 static const int kMinAvailableDiskSpaceToStartEvictionNotSpecified;
111 int64 min_available_disk_space_to_start_eviction_;
113 // Not owned; quota_eviction_handler owns us.
114 QuotaEvictionHandler* quota_eviction_handler_;
116 Statistics statistics_;
117 Statistics previous_statistics_;
118 EvictionRoundStatistics round_statistics_;
119 base::Time time_of_end_of_last_nonskipped_round_;
120 base::Time time_of_end_of_last_round_;
122 int64 interval_ms_;
123 bool repeated_eviction_;
125 base::OneShotTimer<QuotaTemporaryStorageEvictor> eviction_timer_;
126 base::RepeatingTimer<QuotaTemporaryStorageEvictor> histogram_timer_;
127 base::WeakPtrFactory<QuotaTemporaryStorageEvictor> weak_factory_;
129 DISALLOW_COPY_AND_ASSIGN(QuotaTemporaryStorageEvictor);
132 } // namespace storage
134 #endif // STORAGE_BROWSER_QUOTA_QUOTA_TEMPORARY_STORAGE_EVICTOR_H_