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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_ANDROID_H_
6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_ANDROID_H_
11 #include "base/android/jni_helper.h"
12 #include "base/callback.h"
13 #include "base/compiler_specific.h"
14 #include "base/time/time.h"
15 #include "chrome/browser/sync/profile_sync_service_observer.h"
16 #include "chrome/browser/sync/sync_prefs.h"
17 #include "google/cacheinvalidation/include/types.h"
18 #include "google_apis/gaia/google_service_auth_error.h"
21 class ProfileSyncService
;
23 // Android wrapper of the ProfileSyncService which provides access from the Java
24 // layer. Note that on Android, there's only a single profile, and therefore
25 // a single instance of this wrapper. The name of the Java class is
26 // ProfileSyncService.
27 // This class should only be accessed from the UI thread.
28 class ProfileSyncServiceAndroid
: public ProfileSyncServiceObserver
{
31 ProfileSyncServiceAndroid(JNIEnv
* env
, jobject obj
);
33 // This method should be called once right after contructing the object.
36 // Called from Java when we need to nudge native syncer. The |objectSource|,
37 // |objectId|, |version| and |payload| values should come from an
39 void NudgeSyncer(JNIEnv
* env
,
46 // Called from Java when we need to nudge native syncer but have lost state on
47 // which types have changed.
48 void NudgeSyncerForAllTypes(JNIEnv
* env
, jobject obj
);
50 // Called from Java when the user manually enables sync
51 void EnableSync(JNIEnv
* env
, jobject obj
);
53 // Called from Java when the user manually disables sync
54 void DisableSync(JNIEnv
* env
, jobject obj
);
56 // Called from Java when the user signs in to Chrome. Starts up sync.
57 void SignInSync(JNIEnv
* env
, jobject obj
);
59 // Called from Java when the user signs out of Chrome
60 void SignOutSync(JNIEnv
* env
, jobject obj
);
62 // Returns a string version of browser_sync::SyncBackendHost::StatusSummary
63 base::android::ScopedJavaLocalRef
<jstring
> QuerySyncStatusSummary(
64 JNIEnv
* env
, jobject obj
);
66 // Called from Java early during startup to ensure we use the correct
67 // unique machine tag in session sync. Returns true if the machine tag was
69 // This must be called before the |SessionModelAssociator| is initialized.
70 jboolean
SetSyncSessionsId(JNIEnv
* env
, jobject obj
, jstring tag
);
72 // Returns true if the sync backend is initialized.
73 jboolean
IsSyncInitialized(JNIEnv
* env
, jobject obj
);
75 // Returns true if the sync is currently being setup for the first time.
76 jboolean
IsFirstSetupInProgress(JNIEnv
* env
, jobject obj
);
78 // Returns true if the user is currently encrypting everything.
79 jboolean
IsEncryptEverythingEnabled(JNIEnv
* env
, jobject obj
);
81 // Returns true if the sync code needs a passphrase for either encryption or
82 // decryption (can need a passphrase for encryption if the user is turning on
83 // encryption and no passphrase has been set yet).
84 jboolean
IsPassphraseRequired(JNIEnv
* env
, jobject obj
);
86 // Returns true if the sync code needs a decryption passphrase for one of the
87 // currently enabled types.
88 jboolean
IsPassphraseRequiredForDecryption(JNIEnv
* env
, jobject obj
);
90 // Returns true if the sync code needs a decryption passphrase for *any* type,
91 // even types that aren't supported on this platform (like passwords).
92 jboolean
IsPassphraseRequiredForExternalType(JNIEnv
* env
, jobject obj
);
94 // Returns true if the sync code needs a custom decryption passphrase.
95 // Can not be called if the sync backend is not initialized.
96 jboolean
IsUsingSecondaryPassphrase(JNIEnv
* env
, jobject obj
);
98 // Returns true if the decryption passphrase works (was able to decrypt the
99 // stored sync data). Should only be called if
100 // IsPassphraseRequiredForDecryption() returns true.
101 jboolean
SetDecryptionPassphrase(JNIEnv
* env
,
105 // Encrypts the user's data with the passed passphrase. If |is_gaia| == true
106 // then the passphrase is treated as a google (GAIA) passphrase, otherwise
107 // it's treated like an explicit/custom passphrase.
108 void SetEncryptionPassphrase(JNIEnv
* env
,
113 // Returns whether the cryptographer is ready (i.e. encrypted types can be
115 jboolean
IsCryptographerReady(JNIEnv
* env
, jobject
);
117 // Returns the actual passphrase type being used for encryption. This is a
118 // value from the enum defined in syncer::PassphraseType and must be matched
120 jint
GetPassphraseType(JNIEnv
* env
, jobject obj
);
122 // Returns true if the current explicit passphrase time is defined.
123 jboolean
HasExplicitPassphraseTime(JNIEnv
* env
, jobject
);
125 base::android::ScopedJavaLocalRef
<jstring
>
126 GetSyncEnterGooglePassphraseBodyWithDateText(
127 JNIEnv
* env
, jobject
);
129 base::android::ScopedJavaLocalRef
<jstring
>
130 GetSyncEnterCustomPassphraseBodyWithDateText(
131 JNIEnv
* env
, jobject
);
133 base::android::ScopedJavaLocalRef
<jstring
>
134 GetCurrentSignedInAccountText(
135 JNIEnv
* env
, jobject
);
137 base::android::ScopedJavaLocalRef
<jstring
>
138 GetSyncEnterCustomPassphraseBodyText(
139 JNIEnv
* env
, jobject
);
141 // Returns true if sync has been migrated.
142 jboolean
IsSyncKeystoreMigrationDone(JNIEnv
* env
, jobject obj
);
144 // Get the set of enabled data types. These are the types currently both
145 // registered and preferred. Note that control types are always included here.
146 // Returns a bit map of the values from
147 // profile_sync_service_model_type_selection_android.h.
148 jlong
GetEnabledDataTypes(JNIEnv
* env
, jobject obj
);
150 // Enables the passed data types.
151 // If |sync_everything| is true, then all data types are enabled and the
152 // contents of |model_type_selection| is
154 // Otherwise, the values of |model_type_selection| must contain a bit map of
155 // values from profile_sync_service_model_type_selection_android.h.
156 void SetPreferredDataTypes(JNIEnv
* env
,
158 jboolean sync_everything
,
159 jlong model_type_selection
);
161 // Tells sync that we're currently configuring so no data types should be
163 void SetSetupInProgress(JNIEnv
* env
, jobject obj
, jboolean in_progress
);
165 // Tells sync that sync setup is complete so we can start syncing now.
166 void SetSyncSetupCompleted(JNIEnv
* env
, jobject obj
);
168 // Returns true if sync setup has been completed.
169 jboolean
HasSyncSetupCompleted(JNIEnv
* env
, jobject obj
);
171 // Returns true if sync startup is currently suppressed.
172 jboolean
IsStartSuppressed(JNIEnv
* env
, jobject obj
);
174 // Returns true if sync is configured to "sync everything".
175 jboolean
HasKeepEverythingSynced(JNIEnv
* env
, jobject obj
);
177 // Turns on encryption for all data types. This is an asynchronous operation
178 // which happens after the current configuration pass is done, so a call to
179 // this routine must be followed by a call to SetEnabledDataTypes().
180 void EnableEncryptEverything(JNIEnv
* env
, jobject obj
);
182 // Returns true if sync has encountered an unrecoverable error.
183 jboolean
HasUnrecoverableError(JNIEnv
* env
, jobject obj
);
185 // Returns sync internals in a JSON-formatted Java string.
186 base::android::ScopedJavaLocalRef
<jstring
> GetAboutInfoForTest(JNIEnv
* env
,
189 // Returns the integer value corresponding to the current auth error state
190 // (GoogleServiceAuthError.State).
191 jint
GetAuthError(JNIEnv
* env
, jobject obj
);
193 // ProfileSyncServiceObserver:
194 virtual void OnStateChanged() OVERRIDE
;
196 // Returns a timestamp for when a sync was last executed. The return value is
197 // the internal value of base::Time.
198 jlong
GetLastSyncedTimeForTest(JNIEnv
* env
, jobject obj
);
200 static ProfileSyncServiceAndroid
* GetProfileSyncServiceAndroid();
202 // Registers the ProfileSyncServiceAndroid's native methods through JNI.
203 static bool Register(JNIEnv
* env
);
206 typedef std::map
<invalidation::ObjectId
,
208 syncer::ObjectIdLessThan
> ObjectIdVersionMap
;
210 virtual ~ProfileSyncServiceAndroid();
211 // Remove observers to profile sync service.
212 void RemoveObserver();
213 // Called from Java when we need to nudge native syncer. The |object_source|,
214 // |objectId|, |version| and |payload| values should come from an
216 void SendNudgeNotification(int object_source
,
217 const std::string
& str_object_id
,
219 const std::string
& payload
);
222 ProfileSyncService
* sync_service_
;
223 // The class that handles getting, setting, and persisting sync
225 scoped_ptr
<browser_sync::SyncPrefs
> sync_prefs_
;
227 // Java-side ProfileSyncService object.
228 JavaObjectWeakGlobalRef weak_java_profile_sync_service_
;
230 // The invalidation API spec allows for the possibility of redundant
231 // invalidations, so keep track of the max versions and drop
232 // invalidations with old versions.
233 ObjectIdVersionMap max_invalidation_versions_
;
235 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceAndroid
);
238 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_ANDROID_H_