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..3957842f3b09b10d59b366ffc1b1bea5e87a8dbf 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, on the |
+ // next write event of |writer_|. |
+ // |on_next_write_callback| must be thread-safe. |
+ void RegisterOnNextWriteCallback( |
+ const base::Callback<void(bool success)>& on_next_write_callback); |
void ClearMutableValues() override; |
@@ -170,10 +179,27 @@ 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_| on the thread |
gab
2016/09/20 01:27:42
s/thread/sequence/
proberge
2016/09/20 15:15:53
Done.
|
+ // owning |calling_store|. Otherwise, re-registers |on_next_successful_write| |
+ // on |calling_store|. |
+ static void RunOrScheduleNextSuccessfulWriteCallback( |
+ base::WeakPtr<JsonPrefStore> calling_store, |
gab
2016/09/20 01:27:42
Make this a member method, essentially what you ar
proberge
2016/09/20 15:15:53
Done.
|
+ bool write_success); |
+ |
+ // Handles the result of a write with result |write_success|. Runs the |
+ // |on_next_write| callback on the current thread and calls |PostWriteReply| |
gab
2016/09/20 01:27:42
s/calls/posts/
Also, what's |PostWriteReply|?
proberge
2016/09/20 15:15:53
My bad, had renamed PostWriteReply -> RunOrSchedul
|
+ // on |reply_task_runner|. |
+ static void PostWriteCallback( |
+ base::WeakPtr<JsonPrefStore> calling_store, |
+ const base::Callback<void(bool success)>& on_next_write, |
+ 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 +232,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. |