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