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

Side by Side 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: Use SyncBackendHost to get to the sync thread. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.sync; 5 package org.chromium.chrome.browser.sync;
6 6
7 import android.app.Activity;
7 import android.content.Context; 8 import android.content.Context;
8 import android.util.Log; 9 import android.util.Log;
9 10
10 import com.google.common.base.Joiner; 11 import com.google.common.base.Joiner;
11 12
13 import org.chromium.base.ActivityState;
14 import org.chromium.base.ApplicationStatus;
15 import org.chromium.base.ApplicationStatus.ActivityStateListener;
12 import org.chromium.base.CalledByNative; 16 import org.chromium.base.CalledByNative;
13 import org.chromium.base.ThreadUtils; 17 import org.chromium.base.ThreadUtils;
14 import org.chromium.base.VisibleForTesting; 18 import org.chromium.base.VisibleForTesting;
15 import org.chromium.chrome.browser.identity.UniqueIdentificationGenerator; 19 import org.chromium.chrome.browser.identity.UniqueIdentificationGenerator;
16 import org.chromium.sync.internal_api.pub.SyncDecryptionPassphraseType; 20 import org.chromium.sync.internal_api.pub.SyncDecryptionPassphraseType;
17 import org.chromium.sync.internal_api.pub.base.ModelType; 21 import org.chromium.sync.internal_api.pub.base.ModelType;
18 22
19 import java.util.HashSet; 23 import java.util.HashSet;
20 import java.util.List; 24 import java.util.List;
21 import java.util.Set; 25 import java.util.Set;
22 import java.util.SortedSet; 26 import java.util.SortedSet;
23 import java.util.TreeSet; 27 import java.util.TreeSet;
24 import java.util.concurrent.CopyOnWriteArrayList; 28 import java.util.concurrent.CopyOnWriteArrayList;
25 29
26 /** 30 /**
27 * Android wrapper of the ProfileSyncService which provides access from the Java layer. 31 * Android wrapper of the ProfileSyncService which provides access from the Java layer.
28 * <p/> 32 * <p/>
29 * This class mostly wraps native classes, but it make a few business logic deci sions, both in Java 33 * This class mostly wraps native classes, but it make a few business logic deci sions, both in Java
30 * and in native. 34 * and in native.
31 * <p/> 35 * <p/>
32 * Only usable from the UI thread as the native ProfileSyncService requires its access to be in the 36 * Only usable from the UI thread as the native ProfileSyncService requires its access to be in the
33 * UI thread. 37 * UI thread.
34 * <p/> 38 * <p/>
35 * See chrome/browser/sync/profile_sync_service.h for more details. 39 * See chrome/browser/sync/profile_sync_service.h for more details.
36 */ 40 */
37 public class ProfileSyncService { 41 public class ProfileSyncService {
38 42
43 /**
44 * Listener for sync status changes.
45 */
39 public interface SyncStateChangedListener { 46 public interface SyncStateChangedListener {
40 // Invoked when the underlying sync status has changed. 47 // Invoked when the underlying sync status has changed.
41 public void syncStateChanged(); 48 public void syncStateChanged();
42 } 49 }
43 50
44 private static final String TAG = "ProfileSyncService"; 51 private static final String TAG = "ProfileSyncService";
45 52
46 @VisibleForTesting 53 @VisibleForTesting
47 public static final String SESSION_TAG_PREFIX = "session_sync"; 54 public static final String SESSION_TAG_PREFIX = "session_sync";
48 55
(...skipping 30 matching lines...) Expand all
79 */ 86 */
80 private ProfileSyncService(Context context) { 87 private ProfileSyncService(Context context) {
81 ThreadUtils.assertOnUiThread(); 88 ThreadUtils.assertOnUiThread();
82 // We should store the application context, as we outlive any activity w hich may create us. 89 // We should store the application context, as we outlive any activity w hich may create us.
83 mContext = context.getApplicationContext(); 90 mContext = context.getApplicationContext();
84 91
85 // This may cause us to create ProfileSyncService even if sync has not 92 // This may cause us to create ProfileSyncService even if sync has not
86 // been set up, but ProfileSyncService::Startup() won't be called until 93 // been set up, but ProfileSyncService::Startup() won't be called until
87 // credentials are available. 94 // credentials are available.
88 mNativeProfileSyncServiceAndroid = nativeInit(); 95 mNativeProfileSyncServiceAndroid = nativeInit();
96
97 // When the application gets paused, tell sync to flush the directory to disk.
98 ApplicationStatus.registerStateListenerForAllActivities(new ActivityStat eListener() {
99 @Override
100 public void onActivityStateChange(Activity activity, int newState) {
101 if (newState == ActivityState.PAUSED) {
102 flushDirectory();
103 }
104 }
105 });
89 } 106 }
90 107
91 @CalledByNative 108 @CalledByNative
92 private static long getProfileSyncServiceAndroid(Context context) { 109 private static long getProfileSyncServiceAndroid(Context context) {
93 return get(context).mNativeProfileSyncServiceAndroid; 110 return get(context).mNativeProfileSyncServiceAndroid;
94 } 111 }
95 112
96 /** 113 /**
97 * If we are currently in the process of setting up sync, this method clears the 114 * If we are currently in the process of setting up sync, this method clears the
98 * sync setup in progress flag. 115 * sync setup in progress flag.
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 } 513 }
497 514
498 /** 515 /**
499 * Stops the sync engine. 516 * Stops the sync engine.
500 */ 517 */
501 public void disableSync() { 518 public void disableSync() {
502 nativeDisableSync(mNativeProfileSyncServiceAndroid); 519 nativeDisableSync(mNativeProfileSyncServiceAndroid);
503 } 520 }
504 521
505 /** 522 /**
523 * Flushes the sync directory.
524 */
525 public void flushDirectory() {
526 nativeFlushDirectory(mNativeProfileSyncServiceAndroid);
527 }
528
529 /**
506 * Returns the time when the last sync cycle was completed. 530 * Returns the time when the last sync cycle was completed.
507 * 531 *
508 * @return The difference measured in microseconds, between last sync cycle completion time 532 * @return The difference measured in microseconds, between last sync cycle completion time
509 * and 1 January 1970 00:00:00 UTC. 533 * and 1 January 1970 00:00:00 UTC.
510 */ 534 */
511 @VisibleForTesting 535 @VisibleForTesting
512 public long getLastSyncedTimeForTest() { 536 public long getLastSyncedTimeForTest() {
513 return nativeGetLastSyncedTimeForTest(mNativeProfileSyncServiceAndroid); 537 return nativeGetLastSyncedTimeForTest(mNativeProfileSyncServiceAndroid);
514 } 538 }
515 539
(...skipping 21 matching lines...) Expand all
537 } 561 }
538 562
539 // Native methods 563 // Native methods
540 private native void nativeNudgeSyncer( 564 private native void nativeNudgeSyncer(
541 long nativeProfileSyncServiceAndroid, int objectSource, String objec tId, long version, 565 long nativeProfileSyncServiceAndroid, int objectSource, String objec tId, long version,
542 String payload); 566 String payload);
543 private native void nativeNudgeSyncerForAllTypes(long nativeProfileSyncServi ceAndroid); 567 private native void nativeNudgeSyncerForAllTypes(long nativeProfileSyncServi ceAndroid);
544 private native long nativeInit(); 568 private native long nativeInit();
545 private native void nativeEnableSync(long nativeProfileSyncServiceAndroid); 569 private native void nativeEnableSync(long nativeProfileSyncServiceAndroid);
546 private native void nativeDisableSync(long nativeProfileSyncServiceAndroid); 570 private native void nativeDisableSync(long nativeProfileSyncServiceAndroid);
571 private native void nativeFlushDirectory(long nativeProfileSyncServiceAndroi d);
547 private native void nativeSignInSync(long nativeProfileSyncServiceAndroid); 572 private native void nativeSignInSync(long nativeProfileSyncServiceAndroid);
548 private native void nativeSignOutSync(long nativeProfileSyncServiceAndroid); 573 private native void nativeSignOutSync(long nativeProfileSyncServiceAndroid);
549 private native boolean nativeSetSyncSessionsId( 574 private native boolean nativeSetSyncSessionsId(
550 long nativeProfileSyncServiceAndroid, String tag); 575 long nativeProfileSyncServiceAndroid, String tag);
551 private native String nativeQuerySyncStatusSummary(long nativeProfileSyncSer viceAndroid); 576 private native String nativeQuerySyncStatusSummary(long nativeProfileSyncSer viceAndroid);
552 private native int nativeGetAuthError(long nativeProfileSyncServiceAndroid); 577 private native int nativeGetAuthError(long nativeProfileSyncServiceAndroid);
553 private native boolean nativeIsSyncInitialized(long nativeProfileSyncService Android); 578 private native boolean nativeIsSyncInitialized(long nativeProfileSyncService Android);
554 private native boolean nativeIsFirstSetupInProgress(long nativeProfileSyncSe rviceAndroid); 579 private native boolean nativeIsFirstSetupInProgress(long nativeProfileSyncSe rviceAndroid);
555 private native boolean nativeIsEncryptEverythingEnabled(long nativeProfileSy ncServiceAndroid); 580 private native boolean nativeIsEncryptEverythingEnabled(long nativeProfileSy ncServiceAndroid);
556 private native void nativeEnableEncryptEverything(long nativeProfileSyncServ iceAndroid); 581 private native void nativeEnableEncryptEverything(long nativeProfileSyncServ iceAndroid);
(...skipping 26 matching lines...) Expand all
583 private native void nativeSetSyncSetupCompleted(long nativeProfileSyncServic eAndroid); 608 private native void nativeSetSyncSetupCompleted(long nativeProfileSyncServic eAndroid);
584 private native boolean nativeHasSyncSetupCompleted(long nativeProfileSyncSer viceAndroid); 609 private native boolean nativeHasSyncSetupCompleted(long nativeProfileSyncSer viceAndroid);
585 private native boolean nativeIsStartSuppressed(long nativeProfileSyncService Android); 610 private native boolean nativeIsStartSuppressed(long nativeProfileSyncService Android);
586 private native boolean nativeHasKeepEverythingSynced(long nativeProfileSyncS erviceAndroid); 611 private native boolean nativeHasKeepEverythingSynced(long nativeProfileSyncS erviceAndroid);
587 private native boolean nativeHasUnrecoverableError(long nativeProfileSyncSer viceAndroid); 612 private native boolean nativeHasUnrecoverableError(long nativeProfileSyncSer viceAndroid);
588 private native String nativeGetAboutInfoForTest(long nativeProfileSyncServic eAndroid); 613 private native String nativeGetAboutInfoForTest(long nativeProfileSyncServic eAndroid);
589 private native long nativeGetLastSyncedTimeForTest(long nativeProfileSyncSer viceAndroid); 614 private native long nativeGetLastSyncedTimeForTest(long nativeProfileSyncSer viceAndroid);
590 private native void nativeOverrideNetworkResourcesForTest( 615 private native void nativeOverrideNetworkResourcesForTest(
591 long nativeProfileSyncServiceAndroid, long networkResources); 616 long nativeProfileSyncServiceAndroid, long networkResources);
592 } 617 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sync/glue/sync_backend_host.h » ('j') | chrome/browser/sync/glue/sync_backend_host_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698