Componentize component_updater: Copy over test data with executable bit.
[chromium-blink-merge.git] / chrome / browser / sync / profile_sync_service_android.h
blob372045088dba99320d7b87a7b0cf93aa4dca17f3
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_
8 #include <jni.h>
9 #include <map>
11 #include "base/android/jni_weak_ref.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 "components/invalidation/invalidation_util.h"
17 #include "components/sync_driver/sync_prefs.h"
18 #include "google/cacheinvalidation/include/types.h"
19 #include "google_apis/gaia/google_service_auth_error.h"
21 class Profile;
22 class ProfileSyncService;
24 // Android wrapper of the ProfileSyncService which provides access from the Java
25 // layer. Note that on Android, there's only a single profile, and therefore
26 // a single instance of this wrapper. The name of the Java class is
27 // ProfileSyncService.
28 // This class should only be accessed from the UI thread.
29 class ProfileSyncServiceAndroid : public ProfileSyncServiceObserver {
30 public:
32 ProfileSyncServiceAndroid(JNIEnv* env, jobject obj);
34 // This method should be called once right after contructing the object.
35 void Init();
37 // Called from Java when we need to nudge native syncer. The |objectSource|,
38 // |objectId|, |version| and |payload| values should come from an
39 // invalidation.
40 void NudgeSyncer(JNIEnv* env,
41 jobject obj,
42 jint objectSource,
43 jstring objectId,
44 jlong version,
45 jstring payload);
47 // Called from Java when we need to nudge native syncer but have lost state on
48 // which types have changed.
49 void NudgeSyncerForAllTypes(JNIEnv* env, jobject obj);
51 // Called from Java when the user manually enables sync
52 void EnableSync(JNIEnv* env, jobject obj);
54 // Called from Java when the user manually disables sync
55 void DisableSync(JNIEnv* env, jobject obj);
57 // Called from Java when the user signs in to Chrome. Starts up sync.
58 void SignInSync(JNIEnv* env, jobject obj);
60 // Called from Java when the user signs out of Chrome
61 void SignOutSync(JNIEnv* env, jobject obj);
63 // Returns a string version of browser_sync::SyncBackendHost::StatusSummary
64 base::android::ScopedJavaLocalRef<jstring> QuerySyncStatusSummary(
65 JNIEnv* env, jobject obj);
67 // Called from Java early during startup to ensure we use the correct
68 // unique machine tag in session sync. Returns true if the machine tag was
69 // succesfully set.
70 // This must be called before the |SessionModelAssociator| is initialized.
71 jboolean SetSyncSessionsId(JNIEnv* env, jobject obj, jstring tag);
73 // Returns true if the sync backend is initialized.
74 jboolean IsSyncInitialized(JNIEnv* env, jobject obj);
76 // Returns true if the sync is currently being setup for the first time.
77 jboolean IsFirstSetupInProgress(JNIEnv* env, jobject obj);
79 // Returns true if the user is currently encrypting everything.
80 jboolean IsEncryptEverythingEnabled(JNIEnv* env, jobject obj);
82 // Returns true if the sync code needs a passphrase for either encryption or
83 // decryption (can need a passphrase for encryption if the user is turning on
84 // encryption and no passphrase has been set yet).
85 jboolean IsPassphraseRequired(JNIEnv* env, jobject obj);
87 // Returns true if the sync code needs a decryption passphrase for one of the
88 // currently enabled types.
89 jboolean IsPassphraseRequiredForDecryption(JNIEnv* env, jobject obj);
91 // Returns true if the sync code needs a decryption passphrase for *any* type,
92 // even types that aren't supported on this platform (like passwords).
93 jboolean IsPassphraseRequiredForExternalType(JNIEnv* env, jobject obj);
95 // Returns true if the sync code needs a custom decryption passphrase.
96 // Can not be called if the sync backend is not initialized.
97 jboolean IsUsingSecondaryPassphrase(JNIEnv* env, jobject obj);
99 // Returns true if the decryption passphrase works (was able to decrypt the
100 // stored sync data). Should only be called if
101 // IsPassphraseRequiredForDecryption() returns true.
102 jboolean SetDecryptionPassphrase(JNIEnv* env,
103 jobject obj,
104 jstring passphrase);
106 // Encrypts the user's data with the passed passphrase. If |is_gaia| == true
107 // then the passphrase is treated as a google (GAIA) passphrase, otherwise
108 // it's treated like an explicit/custom passphrase.
109 void SetEncryptionPassphrase(JNIEnv* env,
110 jobject obj,
111 jstring passphrase,
112 jboolean is_gaia);
114 // Returns whether the cryptographer is ready (i.e. encrypted types can be
115 // handled).
116 jboolean IsCryptographerReady(JNIEnv* env, jobject);
118 // Returns the actual passphrase type being used for encryption. This is a
119 // value from the enum defined in syncer::PassphraseType and must be matched
120 // in Java.
121 jint GetPassphraseType(JNIEnv* env, jobject obj);
123 // Returns true if the current explicit passphrase time is defined.
124 jboolean HasExplicitPassphraseTime(JNIEnv* env, jobject);
126 base::android::ScopedJavaLocalRef<jstring>
127 GetSyncEnterGooglePassphraseBodyWithDateText(
128 JNIEnv* env, jobject);
130 base::android::ScopedJavaLocalRef<jstring>
131 GetSyncEnterCustomPassphraseBodyWithDateText(
132 JNIEnv* env, jobject);
134 base::android::ScopedJavaLocalRef<jstring>
135 GetCurrentSignedInAccountText(
136 JNIEnv* env, jobject);
138 base::android::ScopedJavaLocalRef<jstring>
139 GetSyncEnterCustomPassphraseBodyText(
140 JNIEnv* env, jobject);
142 // Returns true if sync has been migrated.
143 jboolean IsSyncKeystoreMigrationDone(JNIEnv* env, jobject obj);
145 // Get the set of enabled data types. These are the types currently both
146 // registered and preferred. Note that control types are always included here.
147 // Returns a bit map of the values from
148 // profile_sync_service_model_type_selection_android.h.
149 jlong GetEnabledDataTypes(JNIEnv* env, jobject obj);
151 // Enables the passed data types.
152 // If |sync_everything| is true, then all data types are enabled and the
153 // contents of |model_type_selection| is
154 // ignored.
155 // Otherwise, the values of |model_type_selection| must contain a bit map of
156 // values from profile_sync_service_model_type_selection_android.h.
157 void SetPreferredDataTypes(JNIEnv* env,
158 jobject obj,
159 jboolean sync_everything,
160 jlong model_type_selection);
162 // Tells sync that we're currently configuring so no data types should be
163 // downloaded yet.
164 void SetSetupInProgress(JNIEnv* env, jobject obj, jboolean in_progress);
166 // Tells sync that sync setup is complete so we can start syncing now.
167 void SetSyncSetupCompleted(JNIEnv* env, jobject obj);
169 // Returns true if sync setup has been completed.
170 jboolean HasSyncSetupCompleted(JNIEnv* env, jobject obj);
172 // Returns true if sync startup is currently suppressed.
173 jboolean IsStartSuppressed(JNIEnv* env, jobject obj);
175 // Returns true if sync is configured to "sync everything".
176 jboolean HasKeepEverythingSynced(JNIEnv* env, jobject obj);
178 // Turns on encryption for all data types. This is an asynchronous operation
179 // which happens after the current configuration pass is done, so a call to
180 // this routine must be followed by a call to SetEnabledDataTypes().
181 void EnableEncryptEverything(JNIEnv* env, jobject obj);
183 // Returns true if sync has encountered an unrecoverable error.
184 jboolean HasUnrecoverableError(JNIEnv* env, jobject obj);
186 // Returns sync internals in a JSON-formatted Java string.
187 base::android::ScopedJavaLocalRef<jstring> GetAboutInfoForTest(JNIEnv* env,
188 jobject obj);
190 // Returns the integer value corresponding to the current auth error state
191 // (GoogleServiceAuthError.State).
192 jint GetAuthError(JNIEnv* env, jobject obj);
194 // ProfileSyncServiceObserver:
195 virtual void OnStateChanged() OVERRIDE;
197 // Returns a timestamp for when a sync was last executed. The return value is
198 // the internal value of base::Time.
199 jlong GetLastSyncedTimeForTest(JNIEnv* env, jobject obj);
201 // Overrides ProfileSyncService's NetworkResources object. This is used to
202 // set up the Sync FakeServer for testing.
203 void OverrideNetworkResourcesForTest(JNIEnv* env,
204 jobject obj,
205 jlong network_resources);
207 static ProfileSyncServiceAndroid* GetProfileSyncServiceAndroid();
209 // Registers the ProfileSyncServiceAndroid's native methods through JNI.
210 static bool Register(JNIEnv* env);
212 private:
213 typedef std::map<invalidation::ObjectId,
214 int64,
215 syncer::ObjectIdLessThan> ObjectIdVersionMap;
217 virtual ~ProfileSyncServiceAndroid();
218 // Remove observers to profile sync service.
219 void RemoveObserver();
220 // Called from Java when we need to nudge native syncer. The |object_source|,
221 // |objectId|, |version| and |payload| values should come from an
222 // invalidation.
223 void SendNudgeNotification(int object_source,
224 const std::string& str_object_id,
225 int64 version,
226 const std::string& payload);
228 Profile* profile_;
229 ProfileSyncService* sync_service_;
230 // The class that handles getting, setting, and persisting sync
231 // preferences.
232 scoped_ptr<sync_driver::SyncPrefs> sync_prefs_;
234 // Java-side ProfileSyncService object.
235 JavaObjectWeakGlobalRef weak_java_profile_sync_service_;
237 // The invalidation API spec allows for the possibility of redundant
238 // invalidations, so keep track of the max versions and drop
239 // invalidations with old versions.
240 ObjectIdVersionMap max_invalidation_versions_;
242 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceAndroid);
245 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_ANDROID_H_