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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/sync/ProfileSyncService.java

Issue 551843003: Persist Directory to disk when the app is backgrounded. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Route through SyncBackendHostCore for Thread Safety(tm). Created 6 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: chrome/android/java/src/org/chromium/chrome/browser/sync/ProfileSyncService.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/sync/ProfileSyncService.java b/chrome/android/java/src/org/chromium/chrome/browser/sync/ProfileSyncService.java
index d47f8e0547ccdbe4b665ac18dce91019180169f3..c5921b56a0739d9f078e72b9ea6c41718d1d1154 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/sync/ProfileSyncService.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/sync/ProfileSyncService.java
@@ -4,9 +4,13 @@
package org.chromium.chrome.browser.sync;
+import android.app.Activity;
import android.content.Context;
import android.util.Log;
+import org.chromium.base.ActivityState;
+import org.chromium.base.ApplicationStatus;
+import org.chromium.base.ApplicationStatus.ActivityStateListener;
import org.chromium.base.CalledByNative;
import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
@@ -35,6 +39,9 @@ import java.util.concurrent.CopyOnWriteArrayList;
*/
public class ProfileSyncService {
+ /**
+ * Listener for sync status changes.
+ */
public interface SyncStateChangedListener {
// Invoked when the underlying sync status has changed.
public void syncStateChanged();
@@ -85,6 +92,16 @@ public class ProfileSyncService {
// been set up, but ProfileSyncService::Startup() won't be called until
// credentials are available.
mNativeProfileSyncServiceAndroid = nativeInit();
+
+ // When the application gets paused, tell sync to flush the directory to disk.
+ ApplicationStatus.registerStateListenerForAllActivities(new ActivityStateListener() {
+ @Override
+ public void onActivityStateChange(Activity activity, int newState) {
+ if (newState == ActivityState.PAUSED) {
+ flushDirectory();
+ }
+ }
+ });
}
@CalledByNative
@@ -502,6 +519,13 @@ public class ProfileSyncService {
}
/**
+ * Flushes the sync directory.
+ */
+ public void flushDirectory() {
+ nativeFlushDirectory(mNativeProfileSyncServiceAndroid);
+ }
+
+ /**
* Returns the time when the last sync cycle was completed.
*
* @return The difference measured in microseconds, between last sync cycle completion time
@@ -552,6 +576,7 @@ public class ProfileSyncService {
private native long nativeInit();
private native void nativeEnableSync(long nativeProfileSyncServiceAndroid);
private native void nativeDisableSync(long nativeProfileSyncServiceAndroid);
+ private native void nativeFlushDirectory(long nativeProfileSyncServiceAndroid);
private native void nativeSignInSync(long nativeProfileSyncServiceAndroid);
private native void nativeSignOutSync(long nativeProfileSyncServiceAndroid);
private native boolean nativeSetSyncSessionsId(
« no previous file with comments | « no previous file | chrome/browser/sync/glue/sync_backend_host.h » ('j') | chrome/browser/sync/glue/sync_backend_host_core.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698