OLD | NEW |
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_COMMON_JSON_PREF_STORE_H_ | 5 #ifndef CHROME_COMMON_JSON_PREF_STORE_H_ |
6 #define CHROME_COMMON_JSON_PREF_STORE_H_ | 6 #define CHROME_COMMON_JSON_PREF_STORE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 15 matching lines...) Expand all Loading... |
26 class FilePath; | 26 class FilePath; |
27 | 27 |
28 // A writable PrefStore implementation that is used for user preferences. | 28 // A writable PrefStore implementation that is used for user preferences. |
29 class JsonPrefStore : public PersistentPrefStore, | 29 class JsonPrefStore : public PersistentPrefStore, |
30 public ImportantFileWriter::DataSerializer { | 30 public ImportantFileWriter::DataSerializer { |
31 public: | 31 public: |
32 // |file_message_loop_proxy| is the MessageLoopProxy for a thread on which | 32 // |file_message_loop_proxy| is the MessageLoopProxy for a thread on which |
33 // file I/O can be done. | 33 // file I/O can be done. |
34 JsonPrefStore(const FilePath& pref_filename, | 34 JsonPrefStore(const FilePath& pref_filename, |
35 base::MessageLoopProxy* file_message_loop_proxy); | 35 base::MessageLoopProxy* file_message_loop_proxy); |
36 virtual ~JsonPrefStore(); | |
37 | 36 |
38 // PrefStore overrides: | 37 // PrefStore overrides: |
39 virtual ReadResult GetValue(const std::string& key, | 38 virtual ReadResult GetValue(const std::string& key, |
40 const base::Value** result) const OVERRIDE; | 39 const base::Value** result) const OVERRIDE; |
41 virtual void AddObserver(PrefStore::Observer* observer) OVERRIDE; | 40 virtual void AddObserver(PrefStore::Observer* observer) OVERRIDE; |
42 virtual void RemoveObserver(PrefStore::Observer* observer) OVERRIDE; | 41 virtual void RemoveObserver(PrefStore::Observer* observer) OVERRIDE; |
43 virtual size_t NumberOfObservers() const OVERRIDE; | 42 virtual size_t NumberOfObservers() const OVERRIDE; |
44 virtual bool IsInitializationComplete() const OVERRIDE; | 43 virtual bool IsInitializationComplete() const OVERRIDE; |
45 | 44 |
46 // PersistentPrefStore overrides: | 45 // PersistentPrefStore overrides: |
(...skipping 11 matching lines...) Expand all Loading... |
58 virtual void CommitPendingWrite() OVERRIDE; | 57 virtual void CommitPendingWrite() OVERRIDE; |
59 virtual void ReportValueChanged(const std::string& key) OVERRIDE; | 58 virtual void ReportValueChanged(const std::string& key) OVERRIDE; |
60 | 59 |
61 // This method is called after JSON file has been read. Method takes | 60 // This method is called after JSON file has been read. Method takes |
62 // ownership of the |value| pointer. Note, this method is used with | 61 // ownership of the |value| pointer. Note, this method is used with |
63 // asynchronous file reading, so class exposes it only for the internal needs. | 62 // asynchronous file reading, so class exposes it only for the internal needs. |
64 // (read: do not call it manually). | 63 // (read: do not call it manually). |
65 void OnFileRead(base::Value* value_owned, PrefReadError error, bool no_dir); | 64 void OnFileRead(base::Value* value_owned, PrefReadError error, bool no_dir); |
66 | 65 |
67 private: | 66 private: |
| 67 virtual ~JsonPrefStore(); |
| 68 |
68 // ImportantFileWriter::DataSerializer overrides: | 69 // ImportantFileWriter::DataSerializer overrides: |
69 virtual bool SerializeData(std::string* output) OVERRIDE; | 70 virtual bool SerializeData(std::string* output) OVERRIDE; |
70 | 71 |
71 FilePath path_; | 72 FilePath path_; |
72 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy_; | 73 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy_; |
73 | 74 |
74 scoped_ptr<base::DictionaryValue> prefs_; | 75 scoped_ptr<base::DictionaryValue> prefs_; |
75 | 76 |
76 bool read_only_; | 77 bool read_only_; |
77 | 78 |
78 // Helper for safely writing pref data. | 79 // Helper for safely writing pref data. |
79 ImportantFileWriter writer_; | 80 ImportantFileWriter writer_; |
80 | 81 |
81 ObserverList<PrefStore::Observer, true> observers_; | 82 ObserverList<PrefStore::Observer, true> observers_; |
82 | 83 |
83 scoped_ptr<ReadErrorDelegate> error_delegate_; | 84 scoped_ptr<ReadErrorDelegate> error_delegate_; |
84 | 85 |
85 bool initialized_; | 86 bool initialized_; |
86 PrefReadError read_error_; | 87 PrefReadError read_error_; |
87 | 88 |
88 std::set<std::string> keys_need_empty_value_; | 89 std::set<std::string> keys_need_empty_value_; |
89 | 90 |
90 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); | 91 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); |
91 }; | 92 }; |
92 | 93 |
93 #endif // CHROME_COMMON_JSON_PREF_STORE_H_ | 94 #endif // CHROME_COMMON_JSON_PREF_STORE_H_ |
OLD | NEW |