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