diff options
author | maxbogue <maxbogue@chromium.org> | 2015-12-10 10:42:58 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-10 18:43:40 +0000 |
commit | dea09d3b7ac5fd50ca7ba3baa70fb37920895487 (patch) | |
tree | 6da46d862277e9349c29a304b655da6e908e12ac /sync/android | |
parent | 0fc40f9403a782b6fb01237fd1fe9d730e1206b2 (diff) | |
download | chromium_src-dea09d3b7ac5fd50ca7ba3baa70fb37920895487.zip chromium_src-dea09d3b7ac5fd50ca7ba3baa70fb37920895487.tar.gz chromium_src-dea09d3b7ac5fd50ca7ba3baa70fb37920895487.tar.bz2 |
[Sync] Make InvalidationPreferences.commit() thread-safe.
The lock is static because we make many instances of
InvalidationPreferences but only one can be committing at a time.
BUG=568369
Review URL: https://codereview.chromium.org/1512183002
Cr-Commit-Position: refs/heads/master@{#364410}
Diffstat (limited to 'sync/android')
-rw-r--r-- | sync/android/java/src/org/chromium/sync/notifier/InvalidationPreferences.java | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/sync/android/java/src/org/chromium/sync/notifier/InvalidationPreferences.java b/sync/android/java/src/org/chromium/sync/notifier/InvalidationPreferences.java index 0a12849..b209b3c 100644 --- a/sync/android/java/src/org/chromium/sync/notifier/InvalidationPreferences.java +++ b/sync/android/java/src/org/chromium/sync/notifier/InvalidationPreferences.java @@ -76,6 +76,9 @@ public class InvalidationPreferences { private static final String TAG = "InvalidationPreferences"; + // Only one commit call can be in progress at a time. + private static final Object sCommitLock = new Object(); + private final Context mContext; public InvalidationPreferences(Context context) { @@ -96,11 +99,13 @@ public class InvalidationPreferences { * NOTE: this method performs blocking I/O and must not be called from the UI thread. */ public boolean commit(EditContext editContext) { - if (!editContext.mEditor.commit()) { - Log.w(TAG, "Failed to commit invalidation preferences"); - return false; + synchronized (sCommitLock) { + if (!editContext.mEditor.commit()) { + Log.w(TAG, "Failed to commit invalidation preferences"); + return false; + } + return true; } - return true; } /** Returns the saved sync types, or {@code null} if none exist. */ |