OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_ANDROID_H_ |
| 6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_ANDROID_H_ |
| 7 |
| 8 #include <jni.h> |
| 9 #include <map> |
| 10 |
| 11 #include "base/android/jni_helper.h" |
| 12 #include "base/compiler_specific.h" |
| 13 #include "chrome/browser/api/sync/profile_sync_service_observer.h" |
| 14 #include "sync/internal_api/public/base/model_type.h" |
| 15 |
| 16 class Profile; |
| 17 class ProfileSyncService; |
| 18 |
| 19 // Android wrapper of the ProfileSyncService which provides access from the Java |
| 20 // layer. Note that on Android, there's only a single profile, and therefore |
| 21 // a single instance of this wrapper. The name of the Java class is |
| 22 // ProfileSyncService. |
| 23 // This class should only be accessed from the UI thread. |
| 24 class ProfileSyncServiceAndroid : public ProfileSyncServiceObserver { |
| 25 public: |
| 26 ProfileSyncServiceAndroid(JNIEnv* env, jobject obj); |
| 27 |
| 28 // This method should be called once right after contructing the object. |
| 29 void Init(); |
| 30 |
| 31 // Called from Java when we need to nudge native syncer. The |objectId|, |
| 32 // |version| and |payload| values should come from an invalidation. |
| 33 void NudgeSyncer(JNIEnv* env, |
| 34 jobject obj, |
| 35 jstring objectId, |
| 36 jlong version, |
| 37 jstring payload); |
| 38 |
| 39 void TokenAvailable(JNIEnv*, jobject, jstring username, jstring auth_token); |
| 40 |
| 41 // Called from Java when the user manually enables sync |
| 42 void EnableSync(JNIEnv* env, jobject obj); |
| 43 |
| 44 // Called from Java when the user manually disables sync |
| 45 void DisableSync(JNIEnv* env, jobject obj); |
| 46 |
| 47 // Called from Java when the user signs in to Chrome. Starts up sync, and |
| 48 // if auth credentials are required, uses the passed |auth_token|. If |
| 49 // |auth_token| is empty, a new |auth_token| is requested from the UI thread |
| 50 // via a call to InvalidateAuthToken(). |
| 51 void SignInSync(JNIEnv* env, jobject obj, jstring username, |
| 52 jstring auth_token); |
| 53 |
| 54 // Called from Java when the user signs out of Chrome |
| 55 void SignOutSync(JNIEnv* env, jobject obj); |
| 56 |
| 57 // Returns a string version of browser_sync::SyncBackendHost::StatusSummary |
| 58 base::android::ScopedJavaLocalRef<jstring> QuerySyncStatusSummary( |
| 59 JNIEnv* env, jobject obj); |
| 60 |
| 61 // Called from Java early during startup to ensure we use the correct |
| 62 // unique machine tag in session sync. Returns true if the machine tag was |
| 63 // succesfully set. |
| 64 // This must be called before the |SessionModelAssociator| is initialized. |
| 65 jboolean SetSyncSessionsId(JNIEnv* env, jobject obj, jstring tag); |
| 66 |
| 67 // Returns true if the sync backend is initialized. |
| 68 jboolean IsSyncInitialized(JNIEnv* env, jobject obj); |
| 69 |
| 70 // Returns true if the sync is currently being setup for the first time. |
| 71 jboolean IsFirstSetupInProgress(JNIEnv* env, jobject obj); |
| 72 |
| 73 // Returns true if the user is currently encrypting everything. |
| 74 jboolean IsEncryptEverythingEnabled(JNIEnv* env, jobject obj); |
| 75 |
| 76 // Returns true if the sync code needs a passphrase for either encryption or |
| 77 // decryption (can need a passphrase for encryption if the user is turning on |
| 78 // encryption and no passphrase has been set yet). |
| 79 jboolean IsPassphraseRequired(JNIEnv* env, jobject obj); |
| 80 |
| 81 // Returns true if the sync code needs a decryption passphrase for one of the |
| 82 // currently enabled types. |
| 83 jboolean IsPassphraseRequiredForDecryption(JNIEnv* env, jobject obj); |
| 84 |
| 85 // Returns true if the sync code needs a decryption passphrase for *any* type, |
| 86 // even types that aren't supported on this platform (like passwords). |
| 87 jboolean IsPassphraseRequiredForExternalType(JNIEnv* env, jobject obj); |
| 88 |
| 89 // Returns true if the sync code needs a custom decryption passphrase. |
| 90 // Can not be called if the sync backend is not initialized. |
| 91 jboolean IsUsingSecondaryPassphrase(JNIEnv* env, jobject obj); |
| 92 |
| 93 // Returns true if the decryption passphrase works (was able to decrypt the |
| 94 // stored sync data). Should only be called if |
| 95 // IsPassphraseRequiredForDecryption() returns true. |
| 96 jboolean SetDecryptionPassphrase(JNIEnv* env, |
| 97 jobject obj, |
| 98 jstring passphrase); |
| 99 |
| 100 // Encrypts the user's data with the passed passphrase. If |is_gaia| == true |
| 101 // then the passphrase is treated as a google (GAIA) passphrase, otherwise |
| 102 // it's treated like an explicit/custom passphrase. |
| 103 void SetEncryptionPassphrase(JNIEnv* env, |
| 104 jobject obj, |
| 105 jstring passphrase, |
| 106 jboolean is_gaia); |
| 107 |
| 108 // Returns whether the cryptographer is ready (i.e. encrypted types can be |
| 109 // handled). |
| 110 jboolean IsCryptographerReady(JNIEnv* env, jobject); |
| 111 |
| 112 // Returns the actual passphrase type being used for encryption. This is a |
| 113 // value from the enum defined in syncer::PassphraseType and must be matched |
| 114 // in Java. |
| 115 jint GetPassphraseType(JNIEnv* env, jobject obj); |
| 116 |
| 117 // Returns true if the current explicit passphrase time is defined. |
| 118 jboolean HasExplicitPassphraseTime(JNIEnv* env, jobject); |
| 119 |
| 120 base::android::ScopedJavaLocalRef<jstring> |
| 121 GetSyncEnterGooglePassphraseBodyWithDateText( |
| 122 JNIEnv* env, jobject); |
| 123 |
| 124 base::android::ScopedJavaLocalRef<jstring> |
| 125 GetSyncEnterCustomPassphraseBodyWithDateText( |
| 126 JNIEnv* env, jobject); |
| 127 |
| 128 base::android::ScopedJavaLocalRef<jstring> |
| 129 GetSyncEnterCustomPassphraseBodyText( |
| 130 JNIEnv* env, jobject); |
| 131 |
| 132 // Returns true if sync has been migrated. |
| 133 jboolean IsSyncKeystoreMigrationDone(JNIEnv* env, jobject obj); |
| 134 |
| 135 // Enables the passed data types. |
| 136 // If |sync_everything| is true, then all data types are enabled and the |
| 137 // contents of |model_type_selection| is |
| 138 // ignored. |
| 139 // Otherwise, the values of |model_type_selection| must contain a bit map of |
| 140 // values from profile_sync_service_model_type_selection_android.h. |
| 141 void SetPreferredDataTypes(JNIEnv* env, |
| 142 jobject obj, |
| 143 jboolean sync_everything, |
| 144 jlong model_type_selection); |
| 145 |
| 146 // Tells sync that we're currently configuring so no data types should be |
| 147 // downloaded yet. |
| 148 void SetSetupInProgress(JNIEnv* env, jobject obj, jboolean in_progress); |
| 149 |
| 150 // Tells sync that sync setup is complete so we can start syncing now. |
| 151 void SetSyncSetupCompleted(JNIEnv* env, jobject obj); |
| 152 |
| 153 // Returns true if sync setup has been completed. |
| 154 jboolean HasSyncSetupCompleted(JNIEnv* env, jobject obj); |
| 155 |
| 156 // Returns true if sync is configured to "sync everything". |
| 157 jboolean HasKeepEverythingSynced(JNIEnv* env, jobject obj); |
| 158 |
| 159 // Returns true if the user has autofill sync enabled. |
| 160 jboolean IsAutofillSyncEnabled(JNIEnv* env, jobject obj); |
| 161 |
| 162 // Returns true if the user has bookmark sync enabled. |
| 163 jboolean IsBookmarkSyncEnabled(JNIEnv* env, jobject obj); |
| 164 |
| 165 // Returns true if the user has password sync enabled. |
| 166 jboolean IsPasswordSyncEnabled(JNIEnv* env, jobject obj); |
| 167 |
| 168 // Returns true if the user has typed URL sync enabled. |
| 169 jboolean IsTypedUrlSyncEnabled(JNIEnv* env, jobject obj); |
| 170 |
| 171 // Returns true if the user has session sync enabled. |
| 172 jboolean IsSessionSyncEnabled(JNIEnv* env, jobject obj); |
| 173 |
| 174 // Turns on encryption for all data types. This is an asynchronous operation |
| 175 // which happens after the current configuration pass is done, so a call to |
| 176 // this routine must be followed by a call to SetEnabledDataTypes(). |
| 177 void EnableEncryptEverything(JNIEnv* env, jobject obj); |
| 178 |
| 179 // Returns true if sync has encountered an unrecoverable error. |
| 180 jboolean HasUnrecoverableError(JNIEnv* env, jobject obj); |
| 181 |
| 182 // Returns sync internals in a JSON-formatted Java string. |
| 183 base::android::ScopedJavaLocalRef<jstring> GetAboutInfoForTest(JNIEnv* env, |
| 184 jobject obj); |
| 185 |
| 186 // Returns the integer value corresponding to the current auth error state |
| 187 // (GoogleServiceAuthError.State). |
| 188 jint GetAuthError(JNIEnv* env, jobject obj); |
| 189 |
| 190 // ProfileSyncServiceObserver: |
| 191 virtual void OnStateChanged() OVERRIDE; |
| 192 |
| 193 // Registers the ProfileSyncServiceAndroid's native methods through JNI. |
| 194 static bool Register(JNIEnv* env); |
| 195 |
| 196 private: |
| 197 virtual ~ProfileSyncServiceAndroid(); |
| 198 // Remove observers to profile sync service. |
| 199 void RemoveObserver(); |
| 200 void InvalidateAuthToken(); |
| 201 // Called from Java when we need to nudge native syncer. The |objectId|, |
| 202 // |version| and |payload| values should come from an invalidation. |
| 203 void SendNudgeNotification(const std::string& str_object_id, |
| 204 int64 version, |
| 205 const std::string& payload); |
| 206 |
| 207 Profile* profile_; |
| 208 ProfileSyncService* sync_service_; |
| 209 // Java-side ProfileSyncService object. |
| 210 JavaObjectWeakGlobalRef weak_java_profile_sync_service_; |
| 211 |
| 212 // The invalidation API spec allows for the possibility of redundant |
| 213 // invalidations, so keep track of the max versions and drop |
| 214 // invalidations with old versions. |
| 215 std::map<syncer::ModelType, int64> max_invalidation_versions_; |
| 216 |
| 217 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceAndroid); |
| 218 }; |
| 219 |
| 220 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_ANDROID_H_ |
OLD | NEW |