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

Side by Side Diff: trunk/src/base/prefs/json_pref_store.h

Issue 273243002: Revert 269415 "Introduce a new framework for back-and-forth trac..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 7 months 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) 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 BASE_PREFS_JSON_PREF_STORE_H_ 5 #ifndef BASE_PREFS_JSON_PREF_STORE_H_
6 #define BASE_PREFS_JSON_PREF_STORE_H_ 6 #define BASE_PREFS_JSON_PREF_STORE_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback_forward.h"
13 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
14 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
15 #include "base/files/important_file_writer.h" 14 #include "base/files/important_file_writer.h"
16 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h"
18 #include "base/message_loop/message_loop_proxy.h" 16 #include "base/message_loop/message_loop_proxy.h"
19 #include "base/observer_list.h" 17 #include "base/observer_list.h"
20 #include "base/prefs/base_prefs_export.h" 18 #include "base/prefs/base_prefs_export.h"
21 #include "base/prefs/persistent_pref_store.h" 19 #include "base/prefs/persistent_pref_store.h"
22 20
23 class PrefFilter; 21 class PrefFilter;
24 22
25 namespace base { 23 namespace base {
26 class DictionaryValue; 24 class DictionaryValue;
27 class FilePath; 25 class FilePath;
28 class SequencedTaskRunner; 26 class SequencedTaskRunner;
29 class SequencedWorkerPool; 27 class SequencedWorkerPool;
30 class Value; 28 class Value;
31 } 29 }
32 30
33 31
34 // A writable PrefStore implementation that is used for user preferences. 32 // A writable PrefStore implementation that is used for user preferences.
35 class BASE_PREFS_EXPORT JsonPrefStore 33 class BASE_PREFS_EXPORT JsonPrefStore
36 : public PersistentPrefStore, 34 : public PersistentPrefStore,
37 public base::ImportantFileWriter::DataSerializer, 35 public base::ImportantFileWriter::DataSerializer {
38 public base::SupportsWeakPtr<JsonPrefStore> {
39 public: 36 public:
40 // Returns instance of SequencedTaskRunner which guarantees that file 37 // Returns instance of SequencedTaskRunner which guarantees that file
41 // operations on the same file will be executed in sequenced order. 38 // operations on the same file will be executed in sequenced order.
42 static scoped_refptr<base::SequencedTaskRunner> GetTaskRunnerForFile( 39 static scoped_refptr<base::SequencedTaskRunner> GetTaskRunnerForFile(
43 const base::FilePath& pref_filename, 40 const base::FilePath& pref_filename,
44 base::SequencedWorkerPool* worker_pool); 41 base::SequencedWorkerPool* worker_pool);
45 42
46 // |sequenced_task_runner| is must be a shutdown-blocking task runner, ideally 43 // |sequenced_task_runner| is must be a shutdown-blocking task runner, ideally
47 // created by GetTaskRunnerForFile() method above. 44 // created by GetTaskRunnerForFile() method above.
48 JsonPrefStore(const base::FilePath& pref_filename, 45 JsonPrefStore(const base::FilePath& pref_filename,
(...skipping 10 matching lines...) Expand all
59 56
60 // PersistentPrefStore overrides: 57 // PersistentPrefStore overrides:
61 virtual bool GetMutableValue(const std::string& key, 58 virtual bool GetMutableValue(const std::string& key,
62 base::Value** result) OVERRIDE; 59 base::Value** result) OVERRIDE;
63 virtual void SetValue(const std::string& key, base::Value* value) OVERRIDE; 60 virtual void SetValue(const std::string& key, base::Value* value) OVERRIDE;
64 virtual void SetValueSilently(const std::string& key, 61 virtual void SetValueSilently(const std::string& key,
65 base::Value* value) OVERRIDE; 62 base::Value* value) OVERRIDE;
66 virtual void RemoveValue(const std::string& key) OVERRIDE; 63 virtual void RemoveValue(const std::string& key) OVERRIDE;
67 virtual bool ReadOnly() const OVERRIDE; 64 virtual bool ReadOnly() const OVERRIDE;
68 virtual PrefReadError GetReadError() const OVERRIDE; 65 virtual PrefReadError GetReadError() const OVERRIDE;
69 // Note this method may be asynchronous if this instance has a |pref_filter_|
70 // in which case it will return PREF_READ_ERROR_ASYNCHRONOUS_TASK_INCOMPLETE.
71 // See details in pref_filter.h.
72 virtual PrefReadError ReadPrefs() OVERRIDE; 66 virtual PrefReadError ReadPrefs() OVERRIDE;
73 virtual void ReadPrefsAsync(ReadErrorDelegate* error_delegate) OVERRIDE; 67 virtual void ReadPrefsAsync(ReadErrorDelegate* error_delegate) OVERRIDE;
74 virtual void CommitPendingWrite() OVERRIDE; 68 virtual void CommitPendingWrite() OVERRIDE;
75 virtual void ReportValueChanged(const std::string& key) OVERRIDE; 69 virtual void ReportValueChanged(const std::string& key) OVERRIDE;
76 70
77 // Just like RemoveValue(), but doesn't notify observers. Used when doing some 71 // This method is called after JSON file has been read. Method takes
78 // cleanup that shouldn't otherwise alert observers. 72 // ownership of the |value| pointer. Note, this method is used with
79 void RemoveValueSilently(const std::string& key); 73 // asynchronous file reading, so class exposes it only for the internal needs.
80 74 // (read: do not call it manually).
81 // Registers |on_next_successful_write| to be called once, on the next 75 void OnFileRead(base::Value* value_owned, PrefReadError error, bool no_dir);
82 // successful write event of |writer_|.
83 void RegisterOnNextSuccessfulWriteCallback(
84 const base::Closure& on_next_successful_write);
85
86 // This method is called after the JSON file has been read. It then hands
87 // |value| (or an empty dictionary in some read error cases) to the
88 // |pref_filter| if one is set. It also gives a callback pointing at
89 // FinalizeFileRead() to that |pref_filter_| which is then responsible for
90 // invoking it when done. If there is no |pref_filter_|, FinalizeFileRead()
91 // is invoked directly.
92 // Note, this method is used with asynchronous file reading, so this class
93 // exposes it only for the internal needs (read: do not call it manually).
94 // TODO(gab): Move this method to the private section and hand a callback to
95 // it to FileThreadDeserializer rather than exposing this public method and
96 // giving a JsonPrefStore* to FileThreadDeserializer.
97 void OnFileRead(scoped_ptr<base::Value> value,
98 PrefReadError error,
99 bool no_dir);
100 76
101 private: 77 private:
102 virtual ~JsonPrefStore(); 78 virtual ~JsonPrefStore();
103 79
104 // ImportantFileWriter::DataSerializer overrides: 80 // ImportantFileWriter::DataSerializer overrides:
105 virtual bool SerializeData(std::string* output) OVERRIDE; 81 virtual bool SerializeData(std::string* output) OVERRIDE;
106 82
107 // This method is called after the JSON file has been read and the result has
108 // potentially been intercepted and modified by |pref_filter_|.
109 // |initialization_successful| is pre-determined by OnFileRead() and should
110 // be used when reporting OnInitializationCompleted().
111 // |schedule_write| indicates whether a write should be immediately scheduled
112 // (typically because the |pref_filter_| has already altered the |prefs|) --
113 // this will be ignored if this store is read-only.
114 void FinalizeFileRead(bool initialization_successful,
115 scoped_ptr<base::DictionaryValue> prefs,
116 bool schedule_write);
117
118 base::FilePath path_; 83 base::FilePath path_;
119 const scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; 84 const scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_;
120 85
121 scoped_ptr<base::DictionaryValue> prefs_; 86 scoped_ptr<base::DictionaryValue> prefs_;
122 87
123 bool read_only_; 88 bool read_only_;
124 89
125 // Helper for safely writing pref data. 90 // Helper for safely writing pref data.
126 base::ImportantFileWriter writer_; 91 base::ImportantFileWriter writer_;
127 92
128 scoped_ptr<PrefFilter> pref_filter_; 93 scoped_ptr<PrefFilter> pref_filter_;
129 ObserverList<PrefStore::Observer, true> observers_; 94 ObserverList<PrefStore::Observer, true> observers_;
130 95
131 scoped_ptr<ReadErrorDelegate> error_delegate_; 96 scoped_ptr<ReadErrorDelegate> error_delegate_;
132 97
133 bool initialized_; 98 bool initialized_;
134 bool filtering_in_progress_;
135 PrefReadError read_error_; 99 PrefReadError read_error_;
136 100
137 std::set<std::string> keys_need_empty_value_; 101 std::set<std::string> keys_need_empty_value_;
138 102
139 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); 103 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore);
140 }; 104 };
141 105
142 #endif // BASE_PREFS_JSON_PREF_STORE_H_ 106 #endif // BASE_PREFS_JSON_PREF_STORE_H_
OLDNEW
« no previous file with comments | « trunk/src/base/files/important_file_writer_unittest.cc ('k') | trunk/src/base/prefs/json_pref_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698