Revert "Merged all Chromoting Host code into remoting_core.dll (Windows)."
[chromium-blink-merge.git] / webkit / quota / quota_temporary_storage_evictor.h
blobd3eb14fed04cd5a5fbfb9130935978495d3e1c58
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
3 // found in the LICENSE file.
5 #ifndef WEBKIT_QUOTA_QUOTA_TEMPORARY_STORAGE_EVICTOR_H_
6 #define WEBKIT_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.h"
14 #include "webkit/quota/quota_types.h"
15 #include "webkit/storage/webkit_storage_export.h"
17 class GURL;
19 namespace quota {
21 class QuotaEvictionHandler;
22 struct QuotaAndUsage;
24 class WEBKIT_STORAGE_EXPORT_PRIVATE QuotaTemporaryStorageEvictor
25 : public base::NonThreadSafe {
26 public:
27 struct Statistics {
28 Statistics()
29 : num_errors_on_evicting_origin(0),
30 num_errors_on_getting_usage_and_quota(0),
31 num_evicted_origins(0),
32 num_eviction_rounds(0),
33 num_skipped_eviction_rounds(0) {}
34 int64 num_errors_on_evicting_origin;
35 int64 num_errors_on_getting_usage_and_quota;
36 int64 num_evicted_origins;
37 int64 num_eviction_rounds;
38 int64 num_skipped_eviction_rounds;
40 void subtract_assign(const Statistics& rhs) {
41 num_errors_on_evicting_origin -= rhs.num_errors_on_evicting_origin;
42 num_errors_on_getting_usage_and_quota -=
43 rhs.num_errors_on_getting_usage_and_quota;
44 num_evicted_origins -= rhs.num_evicted_origins;
45 num_eviction_rounds -= rhs.num_eviction_rounds;
46 num_skipped_eviction_rounds -= rhs.num_skipped_eviction_rounds;
50 struct EvictionRoundStatistics {
51 EvictionRoundStatistics();
53 bool in_round;
54 bool is_initialized;
56 base::Time start_time;
57 int64 usage_overage_at_round;
58 int64 diskspace_shortage_at_round;
60 int64 usage_on_beginning_of_round;
61 int64 usage_on_end_of_round;
62 int64 num_evicted_origins_in_round;
65 QuotaTemporaryStorageEvictor(
66 QuotaEvictionHandler* quota_eviction_handler,
67 int64 interval_ms);
68 virtual ~QuotaTemporaryStorageEvictor();
70 void GetStatistics(std::map<std::string, int64>* statistics);
71 void ReportPerRoundHistogram();
72 void ReportPerHourHistogram();
73 void Start();
75 int64 min_available_disk_space_to_start_eviction() {
76 return min_available_disk_space_to_start_eviction_;
78 void reset_min_available_disk_space_to_start_eviction() {
79 min_available_disk_space_to_start_eviction_ =
80 kMinAvailableDiskSpaceToStartEvictionNotSpecified;
82 void set_min_available_disk_space_to_start_eviction(int64 value) {
83 min_available_disk_space_to_start_eviction_ = value;
86 private:
87 friend class QuotaTemporaryStorageEvictorTest;
89 void StartEvictionTimerWithDelay(int delay_ms);
90 void ConsiderEviction();
91 void OnGotUsageAndQuotaForEviction(
92 QuotaStatusCode status,
93 const QuotaAndUsage& quota_and_usage);
94 void OnGotLRUOrigin(const GURL& origin);
95 void OnEvictionComplete(QuotaStatusCode status);
97 void OnEvictionRoundStarted();
98 void OnEvictionRoundFinished();
100 // This is only used for tests.
101 void set_repeated_eviction(bool repeated_eviction) {
102 repeated_eviction_ = repeated_eviction;
105 static const int kMinAvailableDiskSpaceToStartEvictionNotSpecified;
107 int64 min_available_disk_space_to_start_eviction_;
109 // Not owned; quota_eviction_handler owns us.
110 QuotaEvictionHandler* quota_eviction_handler_;
112 Statistics statistics_;
113 Statistics previous_statistics_;
114 EvictionRoundStatistics round_statistics_;
115 base::Time time_of_end_of_last_nonskipped_round_;
116 base::Time time_of_end_of_last_round_;
118 int64 interval_ms_;
119 bool repeated_eviction_;
121 base::OneShotTimer<QuotaTemporaryStorageEvictor> eviction_timer_;
122 base::RepeatingTimer<QuotaTemporaryStorageEvictor> histogram_timer_;
123 base::WeakPtrFactory<QuotaTemporaryStorageEvictor> weak_factory_;
125 DISALLOW_COPY_AND_ASSIGN(QuotaTemporaryStorageEvictor);
128 } // namespace quota
130 #endif // WEBKIT_QUOTA_QUOTA_TEMPORARY_STORAGE_EVICTOR_H_