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

Side by Side Diff: chrome/common/json_pref_store.h

Issue 5646003: Sanitize PrefStore interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, fix up unit tests. Created 10 years 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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"
12 #include "base/file_path.h"
13 #include "base/observer_list.h"
11 #include "base/scoped_ptr.h" 14 #include "base/scoped_ptr.h"
12 #include "chrome/common/pref_store.h" 15 #include "chrome/common/persistent_pref_store.h"
danno 2010/12/08 13:08:45 alpha
Mattias Nissler (ping if slow) 2010/12/09 10:20:20 Done.
13 #include "chrome/common/important_file_writer.h" 16 #include "chrome/common/important_file_writer.h"
14 17
15 namespace base { 18 namespace base {
16 class MessageLoopProxy; 19 class MessageLoopProxy;
17 } 20 }
18 21
19 class DictionaryValue; 22 class DictionaryValue;
20 class FilePath; 23 class FilePath;
24 class Value;
21 25
22 class JsonPrefStore : public PrefStore, 26 // A writable PrefStore implementation that is used for user preferences.
27 class JsonPrefStore : public PersistentPrefStore,
23 public ImportantFileWriter::DataSerializer { 28 public ImportantFileWriter::DataSerializer {
24 public: 29 public:
25 // |file_message_loop_proxy| is the MessageLoopProxy for a thread on which 30 // |file_message_loop_proxy| is the MessageLoopProxy for a thread on which
26 // file I/O can be done. 31 // file I/O can be done.
27 JsonPrefStore(const FilePath& pref_filename, 32 JsonPrefStore(const FilePath& pref_filename,
28 base::MessageLoopProxy* file_message_loop_proxy); 33 base::MessageLoopProxy* file_message_loop_proxy);
29 virtual ~JsonPrefStore(); 34 virtual ~JsonPrefStore();
30 35
31 // PrefStore methods: 36 // PrefStore overrides:
37 virtual ReadResult GetValue(const std::string& key, Value** result) const;
38
39 // PersistentPrefStore overrides:
40 virtual void SetValue(const std::string& key, Value* value);
41 virtual void SetValueSilently(const std::string& key, Value* value);
42 virtual void RemoveValue(const std::string& key);
32 virtual bool ReadOnly() const { return read_only_; } 43 virtual bool ReadOnly() const { return read_only_; }
33
34 virtual DictionaryValue* prefs() const { return prefs_.get(); }
35
36 virtual PrefReadError ReadPrefs(); 44 virtual PrefReadError ReadPrefs();
37
38 virtual bool WritePrefs(); 45 virtual bool WritePrefs();
39
40 virtual void ScheduleWritePrefs(); 46 virtual void ScheduleWritePrefs();
41 47
42 // ImportantFileWriter::DataSerializer methods: 48 private:
43 virtual bool SerializeData(std::string* data); 49 // Overriden from PrefStore.
danno 2010/12/08 13:08:45 Why do you make these private? By upcasting you ca
Mattias Nissler (ping if slow) 2010/12/09 10:20:20 I don't care really, but I thought consumers shoul
50 virtual void AddObserver(PrefStore::ObserverInterface* observer);
51 virtual void RemoveObserver(PrefStore::ObserverInterface* observer);
44 52
45 private: 53 // ImportantFileWriter::DataSerializer overrides:
54 bool SerializeData(std::string* output);
55
46 FilePath path_; 56 FilePath path_;
47 57
48 scoped_ptr<DictionaryValue> prefs_; 58 scoped_ptr<DictionaryValue> prefs_;
49 59
50 bool read_only_; 60 bool read_only_;
51 61
52 // Helper for safely writing pref data. 62 // Helper for safely writing pref data.
53 ImportantFileWriter writer_; 63 ImportantFileWriter writer_;
64
65 ObserverList<PrefStore::ObserverInterface, true> observers_;
66
67 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore);
54 }; 68 };
55 69
56 #endif // CHROME_COMMON_JSON_PREF_STORE_H_ 70 #endif // CHROME_COMMON_JSON_PREF_STORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698