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

Unified Diff: base/prefs/json_pref_store.h

Issue 257003007: Introduce a new framework for back-and-forth tracked/protected preferences migration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: git cl format Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/prefs/json_pref_store.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/prefs/json_pref_store.h
diff --git a/base/prefs/json_pref_store.h b/base/prefs/json_pref_store.h
index ad13feba3f6e1279c7c2bee4d597df35d1698842..b7dfc021198a77d5844013fc77fc5b0e59db79f5 100644
--- a/base/prefs/json_pref_store.h
+++ b/base/prefs/json_pref_store.h
@@ -9,6 +9,7 @@
#include <string>
#include "base/basictypes.h"
+#include "base/callback_forward.h"
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/files/important_file_writer.h"
@@ -34,6 +35,29 @@ class BASE_PREFS_EXPORT JsonPrefStore
: public PersistentPrefStore,
public base::ImportantFileWriter::DataSerializer {
public:
+ // A callback to be invoked when |prefs| have been read (and possibly
+ // pre-modified) and are now ready to be handed back to this callback's
+ // builder. |schedule_write| indicates whether a write should be immediately
+ // scheduled (typically because the OnFileReadInterceptor has already altered
+ // the |prefs|).
+ typedef base::Callback<void(scoped_ptr<base::DictionaryValue> prefs,
+ bool schedule_write)>
+ FinalizePrefsReadCallback;
+
+ // A callback to be invoked from OnFileRead, after the read errors have been
+ // handled, but before |prefs| is handed to this JsonPrefStore.
+ // |read_only| indicates whether this store was turned read-only because of
+ // an error (in which case it is still possible to alter the in-memory state
+ // of this store, but the result won't be flushed back to disk). The callee
+ // of this callback is responsible for invoking |finalize_prefs_read| to hand
+ // |prefs| back to this JsonPrefStore when it's done -- this JsonPrefStore
+ // will not consider its read complete nor invoke observers until it has been
+ // invoked.
+ typedef base::Callback<void(scoped_ptr<base::DictionaryValue> prefs,
+ bool read_only,
+ const FinalizePrefsReadCallback&
+ finalize_prefs_read)> OnFileReadInterceptor;
+
// Returns instance of SequencedTaskRunner which guarantees that file
// operations on the same file will be executed in sequenced order.
static scoped_refptr<base::SequencedTaskRunner> GetTaskRunnerForFile(
@@ -68,11 +92,22 @@ class BASE_PREFS_EXPORT JsonPrefStore
virtual void CommitPendingWrite() OVERRIDE;
virtual void ReportValueChanged(const std::string& key) OVERRIDE;
- // This method is called after JSON file has been read. Method takes
- // ownership of the |value| pointer. Note, this method is used with
- // asynchronous file reading, so class exposes it only for the internal needs.
- // (read: do not call it manually).
- void OnFileRead(base::Value* value_owned, PrefReadError error, bool no_dir);
+ // Registers |on_file_read_interceptor| to intercept the next OnFileRead
+ // event.
+ void InterceptNextFileRead(
+ const OnFileReadInterceptor& on_file_read_interceptor);
+
+ // This method is called after the JSON file has been read. It then hands
+ // |value| (or an empty dictionary in some read error cases) to the
+ // |on_file_read_interceptor_| if one is set. It also gives a callback
+ // pointing at FinalizeFileRead() to the |on_file_read_interceptor_| which is
+ // then responsible for invoking it when done. If there is no
+ // |on_file_read_interceptor_|, FinalizeFileRead() is invoked directly.
+ // Note, this method is used with asynchronous file reading, so class exposes
Bernhard Bauer 2014/04/29 16:38:54 Nit: "this class"
gab 2014/04/29 20:12:14 Done.
+ // it only for the internal needs (read: do not call it manually).
Bernhard Bauer 2014/04/29 16:38:54 Wait, now I'm confused. Who calls this method, and
gab 2014/04/29 20:12:14 This is just putting back a comment that was on th
Bernhard Bauer 2014/04/29 21:20:28 Oh, OK. If you want to update it, that would be gr
gab 2014/04/29 22:36:05 SG, added TODO.
+ void OnFileRead(scoped_ptr<base::Value> value,
+ PrefReadError error,
+ bool no_dir);
private:
virtual ~JsonPrefStore();
@@ -80,6 +115,26 @@ class BASE_PREFS_EXPORT JsonPrefStore
// ImportantFileWriter::DataSerializer overrides:
virtual bool SerializeData(std::string* output) OVERRIDE;
+ // This method is called after the JSON file has been read and the result has
+ // potentially been intercepted and modified by |on_file_read_interceptor_|.
+ // |initialization_successful| is pre-determined by OnFileRead() and should
+ // be used when reporting OnInitializationCompleted().
+ // |schedule_write| indicates whether a write should be immediately scheduled
+ // (typically because the OnFileReadInterceptor has already altered the
+ // |prefs|) -- this will be ignored if this store is read-only.
+ void FinalizeFileRead(bool initialization_successful,
+ scoped_ptr<base::DictionaryValue> prefs,
+ bool schedule_write);
+
+ // Callback to be invoked only once (and subsequently deleted) on the next
+ // OnFileRead event. It will be allowed to modify the JSON value read from
+ // disk before this JsonPrefStore gets to declare itself initialized and
+ // begins using it. It is responsible for handing it back to this
+ // JsonPrefStore via the FinalizePrefReadCallback handed to it.
+ // Note: Setting an |on_file_read_interceptor_| may make ReadPrefs()
+ // asynchronous if the |on_file_read_interceptor_| is asynchronous.
+ scoped_ptr<OnFileReadInterceptor> on_file_read_interceptor_;
+
base::FilePath path_;
const scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_;
« 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