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

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

Issue 400673008: Get rid of FileThreadDeserializer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: inline PostTaskAndReplyWithResult Created 6 years, 5 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
« no previous file with comments | « no previous file | base/prefs/json_pref_store.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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" 12 #include "base/callback_forward.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/files/important_file_writer.h" 15 #include "base/files/important_file_writer.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "base/message_loop/message_loop_proxy.h" 18 #include "base/message_loop/message_loop_proxy.h"
19 #include "base/observer_list.h" 19 #include "base/observer_list.h"
20 #include "base/prefs/base_prefs_export.h" 20 #include "base/prefs/base_prefs_export.h"
21 #include "base/prefs/persistent_pref_store.h" 21 #include "base/prefs/persistent_pref_store.h"
22 #include "base/threading/non_thread_safe.h"
22 23
23 class PrefFilter; 24 class PrefFilter;
24 25
25 namespace base { 26 namespace base {
26 class DictionaryValue; 27 class DictionaryValue;
27 class FilePath; 28 class FilePath;
28 class SequencedTaskRunner; 29 class SequencedTaskRunner;
29 class SequencedWorkerPool; 30 class SequencedWorkerPool;
30 class Value; 31 class Value;
31 } 32 }
32 33
33
34 // A writable PrefStore implementation that is used for user preferences. 34 // A writable PrefStore implementation that is used for user preferences.
35 class BASE_PREFS_EXPORT JsonPrefStore 35 class BASE_PREFS_EXPORT JsonPrefStore
36 : public PersistentPrefStore, 36 : public PersistentPrefStore,
37 public base::ImportantFileWriter::DataSerializer, 37 public base::ImportantFileWriter::DataSerializer,
38 public base::SupportsWeakPtr<JsonPrefStore> { 38 public base::SupportsWeakPtr<JsonPrefStore>,
39 public base::NonThreadSafe {
39 public: 40 public:
41 struct ReadResult;
42
40 // Returns instance of SequencedTaskRunner which guarantees that file 43 // Returns instance of SequencedTaskRunner which guarantees that file
41 // operations on the same file will be executed in sequenced order. 44 // operations on the same file will be executed in sequenced order.
42 static scoped_refptr<base::SequencedTaskRunner> GetTaskRunnerForFile( 45 static scoped_refptr<base::SequencedTaskRunner> GetTaskRunnerForFile(
43 const base::FilePath& pref_filename, 46 const base::FilePath& pref_filename,
44 base::SequencedWorkerPool* worker_pool); 47 base::SequencedWorkerPool* worker_pool);
45 48
46 // Same as the constructor below with no alternate filename. 49 // Same as the constructor below with no alternate filename.
47 JsonPrefStore(const base::FilePath& pref_filename, 50 JsonPrefStore(const base::FilePath& pref_filename,
48 base::SequencedTaskRunner* sequenced_task_runner, 51 base::SequencedTaskRunner* sequenced_task_runner,
49 scoped_ptr<PrefFilter> pref_filter); 52 scoped_ptr<PrefFilter> pref_filter);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 90
88 // Just like RemoveValue(), but doesn't notify observers. Used when doing some 91 // Just like RemoveValue(), but doesn't notify observers. Used when doing some
89 // cleanup that shouldn't otherwise alert observers. 92 // cleanup that shouldn't otherwise alert observers.
90 void RemoveValueSilently(const std::string& key); 93 void RemoveValueSilently(const std::string& key);
91 94
92 // Registers |on_next_successful_write| to be called once, on the next 95 // Registers |on_next_successful_write| to be called once, on the next
93 // successful write event of |writer_|. 96 // successful write event of |writer_|.
94 void RegisterOnNextSuccessfulWriteCallback( 97 void RegisterOnNextSuccessfulWriteCallback(
95 const base::Closure& on_next_successful_write); 98 const base::Closure& on_next_successful_write);
96 99
100 private:
101 virtual ~JsonPrefStore();
102
97 // This method is called after the JSON file has been read. It then hands 103 // This method is called after the JSON file has been read. It then hands
98 // |value| (or an empty dictionary in some read error cases) to the 104 // |value| (or an empty dictionary in some read error cases) to the
99 // |pref_filter| if one is set. It also gives a callback pointing at 105 // |pref_filter| if one is set. It also gives a callback pointing at
100 // FinalizeFileRead() to that |pref_filter_| which is then responsible for 106 // FinalizeFileRead() to that |pref_filter_| which is then responsible for
101 // invoking it when done. If there is no |pref_filter_|, FinalizeFileRead() 107 // invoking it when done. If there is no |pref_filter_|, FinalizeFileRead()
102 // is invoked directly. 108 // is invoked directly.
103 // Note, this method is used with asynchronous file reading, so this class 109 void OnFileRead(scoped_ptr<ReadResult> read_result);
104 // exposes it only for the internal needs (read: do not call it manually).
105 // TODO(gab): Move this method to the private section and hand a callback to
106 // it to FileThreadDeserializer rather than exposing this public method and
107 // giving a JsonPrefStore* to FileThreadDeserializer.
108 void OnFileRead(scoped_ptr<base::Value> value,
109 PrefReadError error,
110 bool no_dir);
111
112 private:
113 virtual ~JsonPrefStore();
114 110
115 // ImportantFileWriter::DataSerializer overrides: 111 // ImportantFileWriter::DataSerializer overrides:
116 virtual bool SerializeData(std::string* output) OVERRIDE; 112 virtual bool SerializeData(std::string* output) OVERRIDE;
117 113
118 // This method is called after the JSON file has been read and the result has 114 // This method is called after the JSON file has been read and the result has
119 // potentially been intercepted and modified by |pref_filter_|. 115 // potentially been intercepted and modified by |pref_filter_|.
120 // |initialization_successful| is pre-determined by OnFileRead() and should 116 // |initialization_successful| is pre-determined by OnFileRead() and should
121 // be used when reporting OnInitializationCompleted(). 117 // be used when reporting OnInitializationCompleted().
122 // |schedule_write| indicates whether a write should be immediately scheduled 118 // |schedule_write| indicates whether a write should be immediately scheduled
123 // (typically because the |pref_filter_| has already altered the |prefs|) -- 119 // (typically because the |pref_filter_| has already altered the |prefs|) --
(...skipping 21 matching lines...) Expand all
145 bool initialized_; 141 bool initialized_;
146 bool filtering_in_progress_; 142 bool filtering_in_progress_;
147 PrefReadError read_error_; 143 PrefReadError read_error_;
148 144
149 std::set<std::string> keys_need_empty_value_; 145 std::set<std::string> keys_need_empty_value_;
150 146
151 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); 147 DISALLOW_COPY_AND_ASSIGN(JsonPrefStore);
152 }; 148 };
153 149
154 #endif // BASE_PREFS_JSON_PREF_STORE_H_ 150 #endif // BASE_PREFS_JSON_PREF_STORE_H_
OLDNEW
« no previous file with comments | « no previous file | base/prefs/json_pref_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698