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

Unified Diff: sync/android/java/src/org/chromium/sync/notifier/InvalidationPreferences.java

Issue 1580153002: [Sync] Make InvalidationPreferences.commit() thread-safe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2564
Patch Set: Created 4 years, 11 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/android/java/src/org/chromium/sync/notifier/InvalidationPreferences.java
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 0a128492ebf32a27d68ff03e37b0036dc0e6f211..b209b3c7d0f1e314cf5fe689f85f45065f192f8a 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. */
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698