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..218b2051b0dc764ed3b4dfe4b6583e0a931e4390 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( |
gab
2016/09/21 17:49:59
Just realized from https://codereview.chromium.org
|
+ 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 |
@@ -223,6 +246,10 @@ class COMPONENTS_PREFS_EXPORT JsonPrefStore |
std::set<std::string> keys_need_empty_value_; |
+ bool has_pending_successful_write_reply_; |
+ bool has_pending_write_callback_; |
+ base::Closure on_next_successful_write_reply_; |
+ |
WriteCountHistogram write_count_histogram_; |
DISALLOW_COPY_AND_ASSIGN(JsonPrefStore); |