OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_EXTENSIONS_SETTINGS_POLICY_VALUE_STORE_H_ | |
6 #define CHROME_BROWSER_EXTENSIONS_SETTINGS_POLICY_VALUE_STORE_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/compiler_specific.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "chrome/browser/extensions/settings/settings_observer.h" | |
15 #include "chrome/browser/value_store/value_store.h" | |
16 | |
17 namespace policy { | |
18 class PolicyMap; | |
19 } | |
20 | |
21 namespace extensions { | |
22 | |
23 // A ValueStore that is backed by another, persistent ValueStore, and stores | |
24 // the policies for a specific extension there. This ValueStore is used to | |
25 // run the function of the storage.managed namespace; it's read-only for the | |
26 // extension. The ManagedValueStoreCache sends updated policy to this store | |
27 // and manages its lifetime. | |
28 class PolicyValueStore : public ValueStore { | |
29 public: | |
30 PolicyValueStore(const std::string& extension_id, | |
31 const scoped_refptr<SettingsObserverList>& observers, | |
32 scoped_ptr<ValueStore> delegate); | |
33 virtual ~PolicyValueStore(); | |
34 | |
35 // Stores |policy| in the persistent database represented by the |delegate_|. | |
36 // If |notify_if_changed| and |policy| differs from the previously persisted | |
37 // version, then a notification is sent to the |observers_| with a list of the | |
38 // changes detected. | |
39 void SetCurrentPolicy(const policy::PolicyMap& policy, | |
40 bool notify_if_changed); | |
41 | |
42 // Clears all the stored data and deletes the database. | |
43 void DeleteStorage(); | |
44 | |
45 // ValueStore implementation: | |
46 virtual size_t GetBytesInUse(const std::string& key) OVERRIDE; | |
47 virtual size_t GetBytesInUse(const std::vector<std::string>& keys) OVERRIDE; | |
48 virtual size_t GetBytesInUse() OVERRIDE; | |
49 virtual ReadResult Get(const std::string& key) OVERRIDE; | |
50 virtual ReadResult Get(const std::vector<std::string>& keys) OVERRIDE; | |
51 virtual ReadResult Get() OVERRIDE; | |
52 virtual WriteResult Set( | |
53 WriteOptions options, | |
54 const std::string& key, | |
55 const base::Value& value) OVERRIDE; | |
56 virtual WriteResult Set( | |
57 WriteOptions options, const base::DictionaryValue& values) OVERRIDE; | |
58 virtual WriteResult Remove(const std::string& key) OVERRIDE; | |
59 virtual WriteResult Remove(const std::vector<std::string>& keys) OVERRIDE; | |
60 virtual WriteResult Clear() OVERRIDE; | |
61 | |
62 // For unit tests. | |
63 ValueStore* delegate() { return delegate_.get(); } | |
64 | |
65 private: | |
66 std::string extension_id_; | |
67 scoped_refptr<SettingsObserverList> observers_; | |
68 scoped_ptr<ValueStore> delegate_; | |
69 | |
70 DISALLOW_COPY_AND_ASSIGN(PolicyValueStore); | |
71 }; | |
72 | |
73 } // namespace extensions | |
74 | |
75 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_POLICY_VALUE_STORE_H_ | |
OLD | NEW |