Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / sync / profile_sync_service_android.h
blob1de6e53857f4806f120ca27454ac2d397572797a
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 "components/invalidation/public/invalidation_util.h"
16 #include "components/sync_driver/sync_prefs.h"
17 #include "components/sync_driver/sync_service_observer.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 sync_driver::SyncServiceObserver {
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 the user manually enables sync
38 void RequestStart(JNIEnv* env, jobject obj);
40 // Called from Java when the user manually disables sync
41 void RequestStop(JNIEnv* env, jobject obj);
43 // Called from Java when the user signs out of Chrome
44 void SignOutSync(JNIEnv* env, jobject obj);
46 // Called from Java when we get a signal that the Directory should be saved.
47 void FlushDirectory(JNIEnv* env, jobject obj);
49 // Returns a string version of browser_sync::SyncBackendHost::StatusSummary
50 base::android::ScopedJavaLocalRef<jstring> QuerySyncStatusSummary(
51 JNIEnv* env, jobject obj);
53 // Retrieves all Sync data as JSON. This method is asynchronous; all data is
54 // passed to |callback| upon completion.
55 void GetAllNodes(JNIEnv* env, jobject obj, jobject callback);
57 // Called from Java early during startup to ensure we use the correct
58 // unique machine tag in session sync. Returns true if the machine tag was
59 // succesfully set.
60 // This must be called before the |SessionModelAssociator| is initialized.
61 jboolean SetSyncSessionsId(JNIEnv* env, jobject obj, jstring tag);
63 // Returns true if the sync backend is initialized.
64 jboolean IsSyncInitialized(JNIEnv* env, jobject obj);
66 // Returns true if the sync is currently being setup for the first time.
67 jboolean IsFirstSetupInProgress(JNIEnv* env, jobject obj);
69 // Returns true if encrypting everything is allowed.
70 jboolean IsEncryptEverythingAllowed(JNIEnv* env, jobject obj);
72 // Returns true if the user is currently encrypting everything.
73 jboolean IsEncryptEverythingEnabled(JNIEnv* env, jobject obj);
75 // Returns true if the sync code needs a passphrase for either encryption or
76 // decryption (can need a passphrase for encryption if the user is turning on
77 // encryption and no passphrase has been set yet).
78 jboolean IsPassphraseRequired(JNIEnv* env, jobject obj);
80 // Returns true if the sync code needs a decryption passphrase for one of the
81 // currently enabled types.
82 jboolean IsPassphraseRequiredForDecryption(JNIEnv* env, jobject obj);
84 // Returns true if the sync code needs a decryption passphrase for *any* type,
85 // even types that aren't supported on this platform (like passwords).
86 jboolean IsPassphraseRequiredForExternalType(JNIEnv* env, jobject obj);
88 // Returns true if the sync code needs a custom decryption passphrase.
89 // Can not be called if the sync backend is not initialized.
90 jboolean IsUsingSecondaryPassphrase(JNIEnv* env, jobject obj);
92 // Returns true if the decryption passphrase works (was able to decrypt the
93 // stored sync data). Should only be called if
94 // IsPassphraseRequiredForDecryption() returns true.
95 jboolean SetDecryptionPassphrase(JNIEnv* env,
96 jobject obj,
97 jstring passphrase);
99 // Encrypts the user's data with the passed passphrase. If |is_gaia| == true
100 // then the passphrase is treated as a google (GAIA) passphrase, otherwise
101 // it's treated like an explicit/custom passphrase.
102 void SetEncryptionPassphrase(JNIEnv* env,
103 jobject obj,
104 jstring passphrase,
105 jboolean is_gaia);
107 // Returns whether the cryptographer is ready (i.e. encrypted types can be
108 // handled).
109 jboolean IsCryptographerReady(JNIEnv* env, jobject);
111 // Returns the actual passphrase type being used for encryption. This is a
112 // value from the enum defined in syncer::PassphraseType and must be matched
113 // in Java.
114 jint GetPassphraseType(JNIEnv* env, jobject obj);
116 // Returns true if the current explicit passphrase time is defined.
117 jboolean HasExplicitPassphraseTime(JNIEnv* env, jobject);
119 // Returns the current explicit passphrase time.
120 jlong GetExplicitPassphraseTime(JNIEnv* env, jobject);
122 base::android::ScopedJavaLocalRef<jstring>
123 GetSyncEnterGooglePassphraseBodyWithDateText(
124 JNIEnv* env, jobject);
126 base::android::ScopedJavaLocalRef<jstring>
127 GetSyncEnterCustomPassphraseBodyWithDateText(
128 JNIEnv* env, jobject);
130 base::android::ScopedJavaLocalRef<jstring>
131 GetCurrentSignedInAccountText(
132 JNIEnv* env, jobject);
134 base::android::ScopedJavaLocalRef<jstring>
135 GetSyncEnterCustomPassphraseBodyText(
136 JNIEnv* env, jobject);
138 // Returns true if sync has been migrated.
139 jboolean IsSyncKeystoreMigrationDone(JNIEnv* env, jobject obj);
141 // Get the set of active data types. These are the types currently being
142 // synced. Note that control types are always included here.
143 // Returns a bit map of the values from
144 // profile_sync_service_android.cc.
145 jlong GetActiveDataTypes(JNIEnv* env, jobject obj);
147 // Get the set of preferred data types. These are the types that the user
148 // has requested be synced.
149 // Returns a bit map of the values from
150 // profile_sync_service_android.cc.
151 jlong GetPreferredDataTypes(JNIEnv* env, jobject obj);
153 // Enables the passed data types.
154 // If |sync_everything| is true, then all data types are enabled and the
155 // contents of |model_type_selection| is
156 // ignored.
157 // Otherwise, the values of |model_type_selection| must contain a bit map of
158 // values from profile_sync_service_android.cc.
159 void SetPreferredDataTypes(JNIEnv* env,
160 jobject obj,
161 jboolean sync_everything,
162 jlong model_type_selection);
164 // Tells sync that we're currently configuring so no data types should be
165 // downloaded yet.
166 void SetSetupInProgress(JNIEnv* env, jobject obj, jboolean in_progress);
168 // Tells sync that sync setup is complete so we can start syncing now.
169 void SetSyncSetupCompleted(JNIEnv* env, jobject obj);
171 // Returns true if sync setup has been completed.
172 jboolean HasSyncSetupCompleted(JNIEnv* env, jobject obj);
174 // See ProfileSyncService::IsSyncRequested().
175 jboolean IsSyncRequested(JNIEnv* env, jobject obj);
177 // See ProfileSyncService::IsSyncActive().
178 jboolean IsSyncActive(JNIEnv* env, jobject obj);
180 // Returns true if sync is configured to "sync everything".
181 jboolean HasKeepEverythingSynced(JNIEnv* env, jobject obj);
183 // Turns on encryption for all data types. This is an asynchronous operation
184 // which happens after the current configuration pass is done, so a call to
185 // this routine must be followed by a call to SetEnabledDataTypes().
186 void EnableEncryptEverything(JNIEnv* env, jobject obj);
188 // Returns true if sync has encountered an unrecoverable error.
189 jboolean HasUnrecoverableError(JNIEnv* env, jobject obj);
191 // Returns sync internals in a JSON-formatted Java string.
192 base::android::ScopedJavaLocalRef<jstring> GetAboutInfoForTest(JNIEnv* env,
193 jobject obj);
195 // Returns the integer value corresponding to the current auth error state
196 // (GoogleServiceAuthError.State).
197 jint GetAuthError(JNIEnv* env, jobject obj);
199 // sync_driver::SyncServiceObserver:
200 void OnStateChanged() override;
202 // Getter/setter for out of band (system notification) passphrase prompt.
203 jboolean IsPassphrasePrompted(JNIEnv* env, jobject obj);
204 void SetPassphrasePrompted(JNIEnv* env, jobject obj, jboolean prompted);
206 // Returns a timestamp for when a sync was last executed. The return value is
207 // the internal value of base::Time.
208 jlong GetLastSyncedTimeForTest(JNIEnv* env, jobject obj);
210 // Overrides ProfileSyncService's NetworkResources object. This is used to
211 // set up the Sync FakeServer for testing.
212 void OverrideNetworkResourcesForTest(JNIEnv* env,
213 jobject obj,
214 jlong network_resources);
216 // Public for tests.
217 static jlong ModelTypeSetToSelection(syncer::ModelTypeSet model_types);
219 // Converts a bitmap of model types to a set of Java ModelTypes, and returns
220 // their string descriptions separated by commas.
221 static std::string ModelTypeSelectionToStringForTest(
222 jlong model_type_selection);
224 static ProfileSyncServiceAndroid* GetProfileSyncServiceAndroid();
226 // Registers the ProfileSyncServiceAndroid's native methods through JNI.
227 static bool Register(JNIEnv* env);
229 private:
230 typedef std::map<invalidation::ObjectId,
231 int64,
232 syncer::ObjectIdLessThan> ObjectIdVersionMap;
234 ~ProfileSyncServiceAndroid() override;
235 // Remove observers to profile sync service.
236 void RemoveObserver();
238 Profile* profile_;
239 ProfileSyncService* sync_service_;
240 // The class that handles getting, setting, and persisting sync
241 // preferences.
242 scoped_ptr<sync_driver::SyncPrefs> sync_prefs_;
244 // Java-side ProfileSyncService object.
245 JavaObjectWeakGlobalRef weak_java_profile_sync_service_;
247 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceAndroid);
250 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_ANDROID_H_