OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 EXTENSIONS_BROWSER_API_STORAGE_SETTINGS_STORAGE_QUOTA_ENFORCER_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_STORAGE_SETTINGS_STORAGE_QUOTA_ENFORCER_H_ |
6 #define EXTENSIONS_BROWSER_API_STORAGE_SETTINGS_STORAGE_QUOTA_ENFORCER_H_ | 6 #define EXTENSIONS_BROWSER_API_STORAGE_SETTINGS_STORAGE_QUOTA_ENFORCER_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "extensions/browser/value_store/value_store.h" | 10 #include "extensions/browser/value_store/value_store.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 // The maximum number of items allowed. | 25 // The maximum number of items allowed. |
26 size_t max_items; | 26 size_t max_items; |
27 }; | 27 }; |
28 | 28 |
29 SettingsStorageQuotaEnforcer(const Limits& limits, ValueStore* delegate); | 29 SettingsStorageQuotaEnforcer(const Limits& limits, ValueStore* delegate); |
30 | 30 |
31 virtual ~SettingsStorageQuotaEnforcer(); | 31 virtual ~SettingsStorageQuotaEnforcer(); |
32 | 32 |
33 // ValueStore implementation. | 33 // ValueStore implementation. |
34 virtual size_t GetBytesInUse(const std::string& key) OVERRIDE; | 34 virtual size_t GetBytesInUse(const std::string& key) override; |
35 virtual size_t GetBytesInUse(const std::vector<std::string>& keys) OVERRIDE; | 35 virtual size_t GetBytesInUse(const std::vector<std::string>& keys) override; |
36 virtual size_t GetBytesInUse() OVERRIDE; | 36 virtual size_t GetBytesInUse() override; |
37 virtual ReadResult Get(const std::string& key) OVERRIDE; | 37 virtual ReadResult Get(const std::string& key) override; |
38 virtual ReadResult Get(const std::vector<std::string>& keys) OVERRIDE; | 38 virtual ReadResult Get(const std::vector<std::string>& keys) override; |
39 virtual ReadResult Get() OVERRIDE; | 39 virtual ReadResult Get() override; |
40 virtual WriteResult Set( | 40 virtual WriteResult Set( |
41 WriteOptions options, | 41 WriteOptions options, |
42 const std::string& key, | 42 const std::string& key, |
43 const base::Value& value) OVERRIDE; | 43 const base::Value& value) override; |
44 virtual WriteResult Set( | 44 virtual WriteResult Set( |
45 WriteOptions options, const base::DictionaryValue& values) OVERRIDE; | 45 WriteOptions options, const base::DictionaryValue& values) override; |
46 virtual WriteResult Remove(const std::string& key) OVERRIDE; | 46 virtual WriteResult Remove(const std::string& key) override; |
47 virtual WriteResult Remove(const std::vector<std::string>& keys) OVERRIDE; | 47 virtual WriteResult Remove(const std::vector<std::string>& keys) override; |
48 virtual WriteResult Clear() OVERRIDE; | 48 virtual WriteResult Clear() override; |
49 virtual bool Restore() OVERRIDE; | 49 virtual bool Restore() override; |
50 virtual bool RestoreKey(const std::string& key) OVERRIDE; | 50 virtual bool RestoreKey(const std::string& key) override; |
51 | 51 |
52 ValueStore* get_delegate_for_test() { return delegate_.get(); } | 52 ValueStore* get_delegate_for_test() { return delegate_.get(); } |
53 | 53 |
54 private: | 54 private: |
55 // Calculate the current usage for the database. | 55 // Calculate the current usage for the database. |
56 void CalculateUsage(); | 56 void CalculateUsage(); |
57 | 57 |
58 // Limits configuration. | 58 // Limits configuration. |
59 const Limits limits_; | 59 const Limits limits_; |
60 | 60 |
61 // The delegate storage area. | 61 // The delegate storage area. |
62 scoped_ptr<ValueStore> const delegate_; | 62 scoped_ptr<ValueStore> const delegate_; |
63 | 63 |
64 // Total bytes in used by |delegate_|. Includes both key lengths and | 64 // Total bytes in used by |delegate_|. Includes both key lengths and |
65 // JSON-encoded values. | 65 // JSON-encoded values. |
66 size_t used_total_; | 66 size_t used_total_; |
67 | 67 |
68 // Map of item key to its size, including the key itself. | 68 // Map of item key to its size, including the key itself. |
69 std::map<std::string, size_t> used_per_setting_; | 69 std::map<std::string, size_t> used_per_setting_; |
70 | 70 |
71 DISALLOW_COPY_AND_ASSIGN(SettingsStorageQuotaEnforcer); | 71 DISALLOW_COPY_AND_ASSIGN(SettingsStorageQuotaEnforcer); |
72 }; | 72 }; |
73 | 73 |
74 } // namespace extensions | 74 } // namespace extensions |
75 | 75 |
76 #endif // EXTENSIONS_BROWSER_API_STORAGE_SETTINGS_STORAGE_QUOTA_ENFORCER_H_ | 76 #endif // EXTENSIONS_BROWSER_API_STORAGE_SETTINGS_STORAGE_QUOTA_ENFORCER_H_ |
OLD | NEW |