| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> |
| 11 #include <string> | 12 #include <string> |
| 12 #include <vector> | 13 #include <vector> |
| 13 | 14 |
| 14 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 16 #include "base/memory/scoped_ptr.h" | |
| 17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 18 #include "extensions/browser/value_store/value_store.h" | 18 #include "extensions/browser/value_store/value_store.h" |
| 19 | 19 |
| 20 namespace extensions { | 20 namespace extensions { |
| 21 | 21 |
| 22 // Enforces total quota and a per-setting quota in bytes, and a maximum number | 22 // Enforces total quota and a per-setting quota in bytes, and a maximum number |
| 23 // of setting keys, for a delegate storage area. | 23 // of setting keys, for a delegate storage area. |
| 24 class SettingsStorageQuotaEnforcer : public ValueStore { | 24 class SettingsStorageQuotaEnforcer : public ValueStore { |
| 25 public: | 25 public: |
| 26 struct Limits { | 26 struct Limits { |
| 27 // The total quota in bytes. | 27 // The total quota in bytes. |
| 28 size_t quota_bytes; | 28 size_t quota_bytes; |
| 29 | 29 |
| 30 // The quota for each individual item in bytes. | 30 // The quota for each individual item in bytes. |
| 31 size_t quota_bytes_per_item; | 31 size_t quota_bytes_per_item; |
| 32 | 32 |
| 33 // The maximum number of items allowed. | 33 // The maximum number of items allowed. |
| 34 size_t max_items; | 34 size_t max_items; |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 SettingsStorageQuotaEnforcer(const Limits& limits, | 37 SettingsStorageQuotaEnforcer(const Limits& limits, |
| 38 scoped_ptr<ValueStore> delegate); | 38 std::unique_ptr<ValueStore> delegate); |
| 39 | 39 |
| 40 ~SettingsStorageQuotaEnforcer() override; | 40 ~SettingsStorageQuotaEnforcer() override; |
| 41 | 41 |
| 42 // ValueStore implementation. | 42 // ValueStore implementation. |
| 43 size_t GetBytesInUse(const std::string& key) override; | 43 size_t GetBytesInUse(const std::string& key) override; |
| 44 size_t GetBytesInUse(const std::vector<std::string>& keys) override; | 44 size_t GetBytesInUse(const std::vector<std::string>& keys) override; |
| 45 size_t GetBytesInUse() override; | 45 size_t GetBytesInUse() override; |
| 46 ReadResult Get(const std::string& key) override; | 46 ReadResult Get(const std::string& key) override; |
| 47 ReadResult Get(const std::vector<std::string>& keys) override; | 47 ReadResult Get(const std::vector<std::string>& keys) override; |
| 48 ReadResult Get() override; | 48 ReadResult Get() override; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 65 void LazyCalculateUsage(); | 65 void LazyCalculateUsage(); |
| 66 | 66 |
| 67 // Frees the allocation of a setting in a record of total and per-setting | 67 // Frees the allocation of a setting in a record of total and per-setting |
| 68 // usage. | 68 // usage. |
| 69 void Free(const std::string& key); | 69 void Free(const std::string& key); |
| 70 | 70 |
| 71 // Limits configuration. | 71 // Limits configuration. |
| 72 const Limits limits_; | 72 const Limits limits_; |
| 73 | 73 |
| 74 // The delegate storage area. | 74 // The delegate storage area. |
| 75 scoped_ptr<ValueStore> const delegate_; | 75 std::unique_ptr<ValueStore> const delegate_; |
| 76 | 76 |
| 77 // Total bytes in used by |delegate_|. Includes both key lengths and | 77 // Total bytes in used by |delegate_|. Includes both key lengths and |
| 78 // JSON-encoded values. | 78 // JSON-encoded values. |
| 79 size_t used_total_; | 79 size_t used_total_; |
| 80 | 80 |
| 81 // Have the total bytes used been calculated? | 81 // Have the total bytes used been calculated? |
| 82 bool usage_calculated_; | 82 bool usage_calculated_; |
| 83 | 83 |
| 84 // Map of item key to its size, including the key itself. | 84 // Map of item key to its size, including the key itself. |
| 85 std::map<std::string, size_t> used_per_setting_; | 85 std::map<std::string, size_t> used_per_setting_; |
| 86 | 86 |
| 87 DISALLOW_COPY_AND_ASSIGN(SettingsStorageQuotaEnforcer); | 87 DISALLOW_COPY_AND_ASSIGN(SettingsStorageQuotaEnforcer); |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 } // namespace extensions | 90 } // namespace extensions |
| 91 | 91 |
| 92 #endif // EXTENSIONS_BROWSER_API_STORAGE_SETTINGS_STORAGE_QUOTA_ENFORCER_H_ | 92 #endif // EXTENSIONS_BROWSER_API_STORAGE_SETTINGS_STORAGE_QUOTA_ENFORCER_H_ |
| OLD | NEW |