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

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: Address nits. 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
« no previous file with comments | « no previous file | chrome/android/sync_shell/javatests/src/chromium/chrome/browser/sync/SyncTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 aac2631f5590859a2074606ca3a5cf489094d596..0a669bda261e75109cf60ea48aec35f2b1cb07a8 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;
@@ -90,6 +94,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
@@ -495,6 +509,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
@@ -541,6 +562,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/android/sync_shell/javatests/src/chromium/chrome/browser/sync/SyncTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698