Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: chrome/browser/extensions/settings/settings_storage_quota_enforcer.h

Issue 9284013: Extension Storage API: expose storage quota information to extensions, via: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: with use-after-free fixed Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_STORAGE_QUOTA_ENFORCER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_STORAGE_QUOTA_ENFORCER_H_
6 #define CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_STORAGE_QUOTA_ENFORCER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_STORAGE_QUOTA_ENFORCER_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "chrome/browser/extensions/settings/settings_storage.h" 11 #include "chrome/browser/extensions/settings/settings_storage.h"
12 12
13 namespace extensions { 13 namespace extensions {
14 14
15 // Enforces total quota and a per-setting quota in bytes, and a maximum number 15 // Enforces total quota and a per-setting quota in bytes, and a maximum number
16 // of setting keys, for a delegate storage area. 16 // of setting keys, for a delegate storage area.
17 class SettingsStorageQuotaEnforcer : public SettingsStorage { 17 class SettingsStorageQuotaEnforcer : public SettingsStorage {
18 public: 18 public:
19 struct Limits { 19 struct Limits {
20 // The storage quota in bytes. 20 // The total quota in bytes.
21 size_t quota_bytes; 21 size_t quota_bytes;
22 22
23 // The quota per individual setting in bytes. 23 // The quota for each individual item in bytes.
24 size_t quota_bytes_per_setting; 24 size_t quota_bytes_per_item;
25 25
26 // The maximum number of settings keys allowed. 26 // The maximum number of items allowed.
27 size_t max_keys; 27 size_t max_items;
28 }; 28 };
29 29
30 SettingsStorageQuotaEnforcer(const Limits& limits, SettingsStorage* delegate); 30 SettingsStorageQuotaEnforcer(const Limits& limits, SettingsStorage* delegate);
31 31
32 virtual ~SettingsStorageQuotaEnforcer(); 32 virtual ~SettingsStorageQuotaEnforcer();
33 33
34 // SettingsStorage implementation. 34 // SettingsStorage implementation.
35 virtual size_t GetBytesInUse(const std::string& key) OVERRIDE;
36 virtual size_t GetBytesInUse(const std::vector<std::string>& keys) OVERRIDE;
37 virtual size_t GetBytesInUse() OVERRIDE;
35 virtual ReadResult Get(const std::string& key) OVERRIDE; 38 virtual ReadResult Get(const std::string& key) OVERRIDE;
36 virtual ReadResult Get(const std::vector<std::string>& keys) OVERRIDE; 39 virtual ReadResult Get(const std::vector<std::string>& keys) OVERRIDE;
37 virtual ReadResult Get() OVERRIDE; 40 virtual ReadResult Get() OVERRIDE;
38 virtual WriteResult Set( 41 virtual WriteResult Set(
39 WriteOptions options, 42 WriteOptions options,
40 const std::string& key, 43 const std::string& key,
41 const Value& value) OVERRIDE; 44 const Value& value) OVERRIDE;
42 virtual WriteResult Set( 45 virtual WriteResult Set(
43 WriteOptions options, const DictionaryValue& values) OVERRIDE; 46 WriteOptions options, const DictionaryValue& values) OVERRIDE;
44 virtual WriteResult Remove(const std::string& key) OVERRIDE; 47 virtual WriteResult Remove(const std::string& key) OVERRIDE;
45 virtual WriteResult Remove(const std::vector<std::string>& keys) OVERRIDE; 48 virtual WriteResult Remove(const std::vector<std::string>& keys) OVERRIDE;
46 virtual WriteResult Clear() OVERRIDE; 49 virtual WriteResult Clear() OVERRIDE;
47 50
48 private: 51 private:
49 // Limits configuration. 52 // Limits configuration.
50 const Limits limits_; 53 const Limits limits_;
51 54
52 // The delegate storage area. 55 // The delegate storage area.
53 scoped_ptr<SettingsStorage> const delegate_; 56 scoped_ptr<SettingsStorage> const delegate_;
54 57
55 // Total size of the settings currently being used. Includes both settings 58 // Total bytes in used by |delegate_|. Includes both key lengths and
56 // keys and their JSON-encoded values. 59 // JSON-encoded values.
57 size_t used_total_; 60 size_t used_total_;
58 61
59 // Map of key to size of that key, including the key itself. 62 // Map of item key to its size, including the key itself.
60 std::map<std::string, size_t> used_per_setting_; 63 std::map<std::string, size_t> used_per_setting_;
61 64
62 DISALLOW_COPY_AND_ASSIGN(SettingsStorageQuotaEnforcer); 65 DISALLOW_COPY_AND_ASSIGN(SettingsStorageQuotaEnforcer);
63 }; 66 };
64 67
65 } // namespace extensions 68 } // namespace extensions
66 69
67 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_STORAGE_QUOTA_ENFORCER_H_ 70 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_STORAGE_QUOTA_ENFORCER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698