Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 15 #include "chrome/common/important_file_writer.h" | 15 #include "chrome/common/important_file_writer.h" |
| 16 #include "chrome/common/persistent_pref_store.h" | 16 #include "chrome/common/persistent_pref_store.h" |
| 17 | 17 |
| 18 namespace base { | 18 namespace base { |
| 19 class MessageLoopProxy; | 19 class MessageLoopProxy; |
| 20 } | 20 } |
| 21 | 21 |
| 22 class DictionaryValue; | 22 class DictionaryValue; |
| 23 class FilePath; | 23 class FilePath; |
| 24 class Value; | 24 class Value; |
| 25 | 25 |
| 26 // A writable PrefStore implementation that is used for user preferences. | 26 // A writable PrefStore implementation that is used for user preferences. |
| 27 class JsonPrefStore : public PersistentPrefStore, | 27 class JsonPrefStore : public PersistentPrefStore, |
| 28 public ImportantFileWriter::DataSerializer { | 28 public ImportantFileWriter::DataSerializer { |
| 29 public: | 29 public: |
| 30 class Delegate { | 30 class Delegate { |
|
Bernhard Bauer
2011/04/25 15:54:10
Is this interface still used somewhere?
altimofeev
2011/04/27 10:32:08
Oops. Deleted.
| |
| 31 public: | 31 public: |
| 32 virtual void OnPrefsRead(PrefReadError error, bool no_dir) = 0; | 32 virtual void OnPrefsRead(PrefReadError error, bool no_dir) = 0; |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 // |file_message_loop_proxy| is the MessageLoopProxy for a thread on which | 35 // |file_message_loop_proxy| is the MessageLoopProxy for a thread on which |
| 36 // file I/O can be done. | 36 // file I/O can be done. |
| 37 JsonPrefStore(const FilePath& pref_filename, | 37 JsonPrefStore(const FilePath& pref_filename, |
| 38 base::MessageLoopProxy* file_message_loop_proxy); | 38 base::MessageLoopProxy* file_message_loop_proxy); |
| 39 virtual ~JsonPrefStore(); | 39 virtual ~JsonPrefStore(); |
| 40 | 40 |
| 41 // PrefStore overrides: | 41 // PrefStore overrides: |
| 42 virtual ReadResult GetValue(const std::string& key, | 42 virtual ReadResult GetValue(const std::string& key, |
| 43 const Value** result) const; | 43 const Value** result) const; |
| 44 virtual void AddObserver(PrefStore::Observer* observer); | 44 virtual void AddObserver(PrefStore::Observer* observer); |
| 45 virtual void RemoveObserver(PrefStore::Observer* observer); | 45 virtual void RemoveObserver(PrefStore::Observer* observer); |
| 46 | 46 |
| 47 // PersistentPrefStore overrides: | 47 // PersistentPrefStore overrides: |
| 48 virtual ReadResult GetMutableValue(const std::string& key, Value** result); | 48 virtual ReadResult GetMutableValue(const std::string& key, Value** result); |
| 49 virtual void SetValue(const std::string& key, Value* value); | 49 virtual void SetValue(const std::string& key, Value* value); |
| 50 virtual void SetValueSilently(const std::string& key, Value* value); | 50 virtual void SetValueSilently(const std::string& key, Value* value); |
| 51 virtual void RemoveValue(const std::string& key); | 51 virtual void RemoveValue(const std::string& key); |
| 52 virtual bool ReadOnly() const; | 52 virtual bool ReadOnly() const; |
| 53 virtual PrefReadError ReadPrefs(); | 53 virtual PrefReadError ReadPrefs(); |
| 54 // todo(altimofeev): move it to the PersistentPrefStore inteface. | 54 virtual void ReadPrefsAsync(); |
| 55 void ReadPrefs(Delegate* delegate); | 55 virtual void GetErrors(PrefReadError* error, bool* is_fatal); |
| 56 virtual bool WritePrefs(); | 56 virtual bool WritePrefs(); |
| 57 virtual void ScheduleWritePrefs(); | 57 virtual void ScheduleWritePrefs(); |
| 58 virtual void CommitPendingWrite(); | 58 virtual void CommitPendingWrite(); |
| 59 virtual void ReportValueChanged(const std::string& key); | 59 virtual void ReportValueChanged(const std::string& key); |
| 60 | 60 |
| 61 // This method is called after JSON file has been read. Method takes | 61 // This method is called after JSON file has been read. Method takes |
| 62 // ownership of the |value| pointer. | 62 // ownership of the |value| pointer. Note, this method is used with |
| 63 // asynchronous file reading, so class exposes it only for the internal needs. | |
| 64 // (read: do not call it manually). | |
| 63 void OnFileRead(Value* value_owned, PrefReadError error, bool no_dir); | 65 void OnFileRead(Value* value_owned, PrefReadError error, bool no_dir); |
| 64 | 66 |
| 65 private: | 67 private: |
| 66 // ImportantFileWriter::DataSerializer overrides: | 68 // ImportantFileWriter::DataSerializer overrides: |
| 67 virtual bool SerializeData(std::string* output); | 69 virtual bool SerializeData(std::string* output); |
| 68 | 70 |
| 69 FilePath path_; | 71 FilePath path_; |
| 70 | 72 |
| 71 scoped_ptr<DictionaryValue> prefs_; | 73 scoped_ptr<DictionaryValue> prefs_; |
| 72 | 74 |
| 73 bool read_only_; | 75 bool read_only_; |
| 74 | 76 |
| 75 // Helper for safely writing pref data. | 77 // Helper for safely writing pref data. |
| 76 ImportantFileWriter writer_; | 78 ImportantFileWriter writer_; |
| 77 | 79 |
| 78 ObserverList<PrefStore::Observer, true> observers_; | 80 ObserverList<PrefStore::Observer, true> observers_; |
| 79 | 81 |
| 80 Delegate* delegate_; | 82 PrefReadError error_; |
| 83 bool is_fatal_; | |
| 81 | 84 |
| 82 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); | 85 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); |
| 83 }; | 86 }; |
| 84 | 87 |
| 85 #endif // CHROME_COMMON_JSON_PREF_STORE_H_ | 88 #endif // CHROME_COMMON_JSON_PREF_STORE_H_ |
| OLD | NEW |