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

Unified Diff: components/prefs/json_pref_store.h

Issue 2299523003: Add synchronous callback support to important_file_writer.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments on #14 Created 4 years, 3 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
Index: components/prefs/json_pref_store.h
diff --git a/components/prefs/json_pref_store.h b/components/prefs/json_pref_store.h
index 047fe74abcd88857597e7ac0d398274820de5b7d..c902e9f780ab91d7c4763ce7ca2cd3529b343c1c 100644
--- a/components/prefs/json_pref_store.h
+++ b/components/prefs/json_pref_store.h
@@ -30,6 +30,7 @@ class Clock;
class DictionaryValue;
class FilePath;
class HistogramBase;
+class JsonPrefStoreCallbackTest;
class JsonPrefStoreLossyWriteTest;
class SequencedTaskRunner;
class SequencedWorkerPool;
@@ -106,10 +107,18 @@ class COMPONENTS_PREFS_EXPORT JsonPrefStore
// cleanup that shouldn't otherwise alert observers.
void RemoveValueSilently(const std::string& key, uint32_t flags);
- // Registers |on_next_successful_write| to be called once, on the next
+ // Registers |on_next_successful_write_reply| to be called once, on the next
// successful write event of |writer_|.
- void RegisterOnNextSuccessfulWriteCallback(
- const base::Closure& on_next_successful_write);
+ // |on_next_successful_write_reply| will be called on the thread from which
+ // this method is called and does not need to be thread safe.
+ void RegisterOnNextSuccessfulWriteReply(
+ const base::Closure& on_next_successful_write_reply);
+
+ // Registers |on_next_write_callback| to be called once synchronously, on the
+ // next write event of |writer_|.
+ // |on_next_write_callback| must be thread-safe.
+ void RegisterOnNextWriteSynchronousCallback(
+ const base::Callback<void(bool success)>& on_next_write_callback);
void ClearMutableValues() override;
@@ -170,10 +179,24 @@ class COMPONENTS_PREFS_EXPORT JsonPrefStore
WriteCountHistogramTestMultiplePeriods);
FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest,
WriteCountHistogramTestPeriodWithGaps);
+ friend class base::JsonPrefStoreCallbackTest;
friend class base::JsonPrefStoreLossyWriteTest;
~JsonPrefStore() override;
+ // If |write_success| is true, runs |on_next_successful_write_|.
+ // Otherwise, re-registers |on_next_successful_write_|.
+ void RunOrScheduleNextSuccessfulWriteCallback(bool write_success);
+
+ // Handles the result of a write with result |write_success|. Runs
+ // |on_next_write| callback on the current thread and posts
+ // |RunOrScheduleNextSuccessfulWriteCallback| on |reply_task_runner|.
+ static void PostWriteCallback(
+ const base::Callback<void(bool success)>& on_next_write_reply,
+ const base::Callback<void(bool success)>& on_next_write_callback,
+ scoped_refptr<base::SequencedTaskRunner> reply_task_runner,
+ bool write_success);
+
// 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
// |pref_filter| if one is set. It also gives a callback pointing at
@@ -206,6 +229,10 @@ class COMPONENTS_PREFS_EXPORT JsonPrefStore
std::unique_ptr<base::DictionaryValue> prefs_;
+ bool has_pending_successful_write_reply_;
+ bool has_pending_write_callback_;
+ base::Closure on_next_successful_write_reply_;
+
bool read_only_;
// Helper for safely writing pref data.

Powered by Google App Engine
This is Rietveld 408576698