OLD | NEW |
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.content.Context; | 7 import android.content.Context; |
8 import android.util.Log; | 8 import android.util.Log; |
9 | 9 |
10 import org.chromium.base.CalledByNative; | 10 import org.chromium.base.CalledByNative; |
11 import org.chromium.base.ThreadUtils; | 11 import org.chromium.base.ThreadUtils; |
12 import org.chromium.base.VisibleForTesting; | 12 import org.chromium.base.VisibleForTesting; |
13 import org.chromium.chrome.browser.identity.UniqueIdentificationGenerator; | 13 import org.chromium.chrome.browser.identity.UniqueIdentificationGenerator; |
| 14 import org.chromium.chrome.browser.invalidation.InvalidationServiceFactory; |
| 15 import org.chromium.chrome.browser.profiles.Profile; |
14 import org.chromium.sync.internal_api.pub.SyncDecryptionPassphraseType; | 16 import org.chromium.sync.internal_api.pub.SyncDecryptionPassphraseType; |
15 import org.chromium.sync.internal_api.pub.base.ModelType; | 17 import org.chromium.sync.internal_api.pub.base.ModelType; |
16 | 18 |
17 import java.util.HashSet; | 19 import java.util.HashSet; |
18 import java.util.Iterator; | 20 import java.util.Iterator; |
19 import java.util.List; | 21 import java.util.List; |
20 import java.util.Set; | 22 import java.util.Set; |
21 import java.util.SortedSet; | 23 import java.util.SortedSet; |
22 import java.util.TreeSet; | 24 import java.util.TreeSet; |
23 import java.util.concurrent.CopyOnWriteArrayList; | 25 import java.util.concurrent.CopyOnWriteArrayList; |
24 | 26 |
25 /** | 27 /** |
26 * Android wrapper of the ProfileSyncService which provides access from the Java
layer. | 28 * Android wrapper of the ProfileSyncService which provides access from the Java
layer. |
27 * <p/> | 29 * <p/> |
28 * This class mostly wraps native classes, but it make a few business logic deci
sions, both in Java | 30 * This class mostly wraps native classes, but it make a few business logic deci
sions, both in Java |
29 * and in native. | 31 * and in native. |
30 * <p/> | 32 * <p/> |
31 * Only usable from the UI thread as the native ProfileSyncService requires its
access to be in the | 33 * Only usable from the UI thread as the native ProfileSyncService requires its
access to be in the |
32 * UI thread. | 34 * UI thread. |
33 * <p/> | 35 * <p/> |
34 * See chrome/browser/sync/profile_sync_service.h for more details. | 36 * See chrome/browser/sync/profile_sync_service.h for more details. |
35 */ | 37 */ |
36 public class ProfileSyncService { | 38 public class ProfileSyncService { |
37 | 39 |
| 40 /** |
| 41 * Listener for the underlying sync status. |
| 42 */ |
38 public interface SyncStateChangedListener { | 43 public interface SyncStateChangedListener { |
39 // Invoked when the underlying sync status has changed. | 44 // Invoked when the status has changed. |
40 public void syncStateChanged(); | 45 public void syncStateChanged(); |
41 } | 46 } |
42 | 47 |
43 private static final String TAG = "ProfileSyncService"; | 48 private static final String TAG = "ProfileSyncService"; |
44 | 49 |
45 @VisibleForTesting | 50 @VisibleForTesting |
46 public static final String SESSION_TAG_PREFIX = "session_sync"; | 51 public static final String SESSION_TAG_PREFIX = "session_sync"; |
47 | 52 |
48 private static ProfileSyncService sSyncSetupManager; | 53 private static ProfileSyncService sSyncSetupManager; |
49 | 54 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 * | 136 * |
132 * @param account The username of the account that is signing in. | 137 * @param account The username of the account that is signing in. |
133 * @param authToken Not used. ProfileSyncService switched to OAuth2 tokens. | 138 * @param authToken Not used. ProfileSyncService switched to OAuth2 tokens. |
134 * Deprecated. Use syncSignIn instead. | 139 * Deprecated. Use syncSignIn instead. |
135 */ | 140 */ |
136 @Deprecated | 141 @Deprecated |
137 public void syncSignInWithAuthToken(String account, String authToken) { | 142 public void syncSignInWithAuthToken(String account, String authToken) { |
138 syncSignIn(account); | 143 syncSignIn(account); |
139 } | 144 } |
140 | 145 |
141 public void requestSyncFromNativeChrome( | 146 // TODO(maxbogue): Remove once downstream use is removed. See http://crbug.c
om/259559. |
142 int objectSource, String objectId, long version, String payload) { | 147 // Callers should use InvalidationService.requestSyncFromNativeChromeForAllT
ypes() instead. |
143 ThreadUtils.assertOnUiThread(); | 148 @Deprecated |
144 nativeNudgeSyncer( | |
145 mNativeProfileSyncServiceAndroid, objectSource, objectId, versio
n, payload); | |
146 } | |
147 | |
148 public void requestSyncFromNativeChromeForAllTypes() { | 149 public void requestSyncFromNativeChromeForAllTypes() { |
149 ThreadUtils.assertOnUiThread(); | 150 ThreadUtils.assertOnUiThread(); |
150 nativeNudgeSyncerForAllTypes(mNativeProfileSyncServiceAndroid); | 151 InvalidationServiceFactory.getForProfile(Profile.getLastUsedProfile()) |
151 } | 152 .requestSyncFromNativeChromeForAllTypes(); |
152 | |
153 /** | |
154 * Nudge the syncer to start a new sync cycle. | |
155 */ | |
156 @VisibleForTesting | |
157 public void requestSyncCycleForTest() { | |
158 ThreadUtils.assertOnUiThread(); | |
159 requestSyncFromNativeChromeForAllTypes(); | |
160 } | 153 } |
161 | 154 |
162 public String querySyncStatus() { | 155 public String querySyncStatus() { |
163 ThreadUtils.assertOnUiThread(); | 156 ThreadUtils.assertOnUiThread(); |
164 return nativeQuerySyncStatusSummary(mNativeProfileSyncServiceAndroid); | 157 return nativeQuerySyncStatusSummary(mNativeProfileSyncServiceAndroid); |
165 } | 158 } |
166 | 159 |
167 /** | 160 /** |
168 * Sets the the machine tag used by session sync to a unique value. | 161 * Sets the the machine tag used by session sync to a unique value. |
169 */ | 162 */ |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 sb.append(it.next()); | 531 sb.append(it.next()); |
539 while (it.hasNext()) { | 532 while (it.hasNext()) { |
540 sb.append(", "); | 533 sb.append(", "); |
541 sb.append(it.next()); | 534 sb.append(it.next()); |
542 } | 535 } |
543 } | 536 } |
544 return sb.toString(); | 537 return sb.toString(); |
545 } | 538 } |
546 | 539 |
547 // Native methods | 540 // Native methods |
548 private native void nativeNudgeSyncer( | |
549 long nativeProfileSyncServiceAndroid, int objectSource, String objec
tId, long version, | |
550 String payload); | |
551 private native void nativeNudgeSyncerForAllTypes(long nativeProfileSyncServi
ceAndroid); | |
552 private native long nativeInit(); | 541 private native long nativeInit(); |
553 private native void nativeEnableSync(long nativeProfileSyncServiceAndroid); | 542 private native void nativeEnableSync(long nativeProfileSyncServiceAndroid); |
554 private native void nativeDisableSync(long nativeProfileSyncServiceAndroid); | 543 private native void nativeDisableSync(long nativeProfileSyncServiceAndroid); |
555 private native void nativeSignInSync(long nativeProfileSyncServiceAndroid); | 544 private native void nativeSignInSync(long nativeProfileSyncServiceAndroid); |
556 private native void nativeSignOutSync(long nativeProfileSyncServiceAndroid); | 545 private native void nativeSignOutSync(long nativeProfileSyncServiceAndroid); |
557 private native boolean nativeSetSyncSessionsId( | 546 private native boolean nativeSetSyncSessionsId( |
558 long nativeProfileSyncServiceAndroid, String tag); | 547 long nativeProfileSyncServiceAndroid, String tag); |
559 private native String nativeQuerySyncStatusSummary(long nativeProfileSyncSer
viceAndroid); | 548 private native String nativeQuerySyncStatusSummary(long nativeProfileSyncSer
viceAndroid); |
560 private native int nativeGetAuthError(long nativeProfileSyncServiceAndroid); | 549 private native int nativeGetAuthError(long nativeProfileSyncServiceAndroid); |
561 private native boolean nativeIsSyncInitialized(long nativeProfileSyncService
Android); | 550 private native boolean nativeIsSyncInitialized(long nativeProfileSyncService
Android); |
(...skipping 29 matching lines...) Expand all Loading... |
591 private native void nativeSetSyncSetupCompleted(long nativeProfileSyncServic
eAndroid); | 580 private native void nativeSetSyncSetupCompleted(long nativeProfileSyncServic
eAndroid); |
592 private native boolean nativeHasSyncSetupCompleted(long nativeProfileSyncSer
viceAndroid); | 581 private native boolean nativeHasSyncSetupCompleted(long nativeProfileSyncSer
viceAndroid); |
593 private native boolean nativeIsStartSuppressed(long nativeProfileSyncService
Android); | 582 private native boolean nativeIsStartSuppressed(long nativeProfileSyncService
Android); |
594 private native boolean nativeHasKeepEverythingSynced(long nativeProfileSyncS
erviceAndroid); | 583 private native boolean nativeHasKeepEverythingSynced(long nativeProfileSyncS
erviceAndroid); |
595 private native boolean nativeHasUnrecoverableError(long nativeProfileSyncSer
viceAndroid); | 584 private native boolean nativeHasUnrecoverableError(long nativeProfileSyncSer
viceAndroid); |
596 private native String nativeGetAboutInfoForTest(long nativeProfileSyncServic
eAndroid); | 585 private native String nativeGetAboutInfoForTest(long nativeProfileSyncServic
eAndroid); |
597 private native long nativeGetLastSyncedTimeForTest(long nativeProfileSyncSer
viceAndroid); | 586 private native long nativeGetLastSyncedTimeForTest(long nativeProfileSyncSer
viceAndroid); |
598 private native void nativeOverrideNetworkResourcesForTest( | 587 private native void nativeOverrideNetworkResourcesForTest( |
599 long nativeProfileSyncServiceAndroid, long networkResources); | 588 long nativeProfileSyncServiceAndroid, long networkResources); |
600 } | 589 } |
OLD | NEW |