Chromium Code Reviews| Index: chrome/browser/sync/profile_sync_service_android.h |
| diff --git a/chrome/browser/sync/profile_sync_service_android.h b/chrome/browser/sync/profile_sync_service_android.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..825a092bbd80315945972fb1cf90b4953a51fc0e |
| --- /dev/null |
| +++ b/chrome/browser/sync/profile_sync_service_android.h |
| @@ -0,0 +1,212 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_ANDROID_H_ |
| +#define CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_ANDROID_H_ |
| + |
| +#include <jni.h> |
| +#include <map> |
| + |
| +#include "base/android/jni_helper.h" |
| +#include "base/compiler_specific.h" |
| +#include "chrome/browser/api/sync/profile_sync_service_observer.h" |
| +#include "sync/internal_api/public/base/model_type.h" |
| + |
| +class Profile; |
| +class ProfileSyncService; |
| +// 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.
|
| +// layer. Note that on Android, there's only a single profile, and therefore |
| +// a single instance of this wrapper. The name of the Java class is |
| +// ProfileSyncService. |
| +class ProfileSyncServiceAndroid : public ProfileSyncServiceObserver { |
| + public: |
| + ProfileSyncServiceAndroid(JNIEnv* env, jobject obj); |
| + void Destroy(JNIEnv*env, jobject obj); |
| + |
| + 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
|
| + jobject obj, |
| + jstring objectId, |
| + jlong version, |
| + jstring payload); |
| + |
| + void TokenAvailable(JNIEnv*, jobject, jstring username, jstring auth_token); |
| + |
| + // Called from Java when the user manually enables sync |
| + void EnableSync(JNIEnv* env, jobject obj); |
| + |
| + // Called from Java when the user manually disables sync |
| + void DisableSync(JNIEnv* env, jobject obj); |
| + |
| + // Called from Java when the user signs in to Chrome. Starts up sync, and |
| + // if auth credentials are required, uses the passed |auth_token|. If |
| + // |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
|
| + // via a call to InvalidateAuthToken(). |
| + void SignInSync(JNIEnv* env, jobject obj, jstring username, |
| + jstring auth_token); |
| + |
| + // Called from Java when the user signs out of Chrome |
| + void SignOutSync(JNIEnv* env, jobject obj); |
| + |
| + // Returns a string version of browser_sync::SyncBackendHost::StatusSummary |
| + base::android::ScopedJavaLocalRef<jstring> QuerySyncStatusSummary( |
| + JNIEnv* env, jobject obj); |
| + |
| + // Called from Java early during startup to ensure we use the correct |
| + // unique machine tag in session sync. Returns true if the machine tag was |
| + // succesfully set. |
| + // This must be called before the |SessionModelAssociator| is initialized. |
| + jboolean SetSyncSessionsId(JNIEnv* env, jobject obj, jstring tag); |
| + |
| + // Returns true if the sync backend is initialized. |
| + jboolean IsSyncInitialized(JNIEnv* env, jobject obj); |
| + |
| + // Returns true if the sync is currently being setup for the first time. |
| + jboolean IsFirstSetupInProgress(JNIEnv* env, jobject obj); |
| + |
| + // Returns true if the user is currently encrypting everything. |
| + jboolean IsEncryptEverythingEnabled(JNIEnv* env, jobject obj); |
| + |
| + // Returns true if the sync code needs a passphrase for either encryption or |
| + // decryption (can need a passphrase for encryption if the user is turning on |
| + // encryption and no passphrase has been set yet). |
| + jboolean IsPassphraseRequired(JNIEnv* env, jobject obj); |
| + |
| + // Returns true if the sync code needs a decryption passphrase for one of the |
| + // currently enabled types. |
| + jboolean IsPassphraseRequiredForDecryption(JNIEnv* env, jobject obj); |
| + |
| + // Returns true if the sync code needs a decryption passphrase for *any* type, |
| + // even types that aren't supported on this platform (like passwords). |
| + jboolean IsPassphraseRequiredForExternalType(JNIEnv* env, jobject obj); |
| + |
| + // Returns true if the sync code needs a custom decryption passphrase. |
| + // Can not be called if the sync backend is not initialized. |
| + jboolean IsUsingSecondaryPassphrase(JNIEnv* env, jobject obj); |
| + |
| + // Returns true if the decryption passphrase works (was able to decrypt the |
| + // stored sync data). Should only be called if |
| + // IsPassphraseRequiredForDecryption() returns true. |
| + jboolean SetDecryptionPassphrase(JNIEnv* env, |
| + jobject obj, |
| + jstring passphrase); |
| + |
| + // Encrypts the user's data with the passed passphrase. If |is_gaia| == true |
| + // then the passphrase is treated as a google (GAIA) passphrase, otherwise |
| + // it's treated like an explicit/custom passphrase. |
| + void SetEncryptionPassphrase(JNIEnv* env, |
| + jobject obj, |
| + jstring passphrase, |
| + jboolean is_gaia); |
| + |
| + // Returns whether the cryptographer is ready (i.e. encrypted types can be |
| + // handled). |
| + jboolean IsCryptographerReady(JNIEnv* env, jobject); |
| + |
| + // Returns the actual passphrase type being used for encryption. This is a |
| + // value from the enum defined in syncer::PassphraseType and must be matched |
| + // in Java. |
| + jint GetPassphraseType(JNIEnv* env, jobject obj); |
| + |
| + // Returns true if the current explicit passphrase time is defined. |
| + jboolean HasExplicitPassphraseTime(JNIEnv* env, jobject); |
| + |
| + base::android::ScopedJavaLocalRef<jstring> |
| + GetSyncEnterGooglePassphraseBodyWithDateText( |
| + JNIEnv* env, jobject); |
| + |
| + base::android::ScopedJavaLocalRef<jstring> |
| + GetSyncEnterCustomPassphraseBodyWithDateText( |
| + JNIEnv* env, jobject); |
| + |
| + static base::android::ScopedJavaLocalRef<jstring> |
| + GetSyncEnterCustomPassphraseBodyText( |
| + JNIEnv* env, jclass); |
| + |
| + // Returns true if sync has been migrated. |
| + jboolean IsMigrated(JNIEnv* env, jobject obj); |
| + |
| + // Enables the passed data types. If |sync_everything| is true, then all |
| + // data types are enabled and the value of the other parameters is ignored. |
| + void SetPreferredDataTypes(JNIEnv* env, |
| + jobject obj, |
| + jboolean sync_everything, |
| + jboolean sync_autofill, |
| + jboolean sync_bookmarks, |
| + jboolean sync_passwords, |
| + jboolean sync_sessions, |
| + jboolean sync_typed_urls); |
| + |
| + // Tells sync that we're currently configuring so no data types should be |
| + // downloaded yet. |
| + void SetSetupInProgress(JNIEnv* env, jobject obj, jboolean in_progress); |
| + |
| + // Tells sync that sync setup is complete so we can start syncing now. |
| + void SetSyncSetupCompleted(JNIEnv* env, jobject obj); |
| + |
| + // Returns true if sync setup has been completed. |
| + jboolean HasSyncSetupCompleted(JNIEnv* env, jobject obj); |
| + |
| + // Returns true if sync is configured to "sync everything". |
| + jboolean HasKeepEverythingSynced(JNIEnv* env, jobject obj); |
| + |
| + // Returns true if the user has autofill sync enabled. |
| + jboolean IsAutofillSyncEnabled(JNIEnv* env, jobject obj); |
| + |
| + // Returns true if the user has bookmark sync enabled. |
| + jboolean IsBookmarkSyncEnabled(JNIEnv* env, jobject obj); |
| + |
| + // Returns true if the user has password sync enabled. |
| + jboolean IsPasswordSyncEnabled(JNIEnv* env, jobject obj); |
| + |
| + // Returns true if the user has typed URL sync enabled. |
| + jboolean IsTypedUrlSyncEnabled(JNIEnv* env, jobject obj); |
| + |
| + // Returns true if the user has session sync enabled. |
| + jboolean IsSessionSyncEnabled(JNIEnv* env, jobject obj); |
| + |
| + // Turns on encryption for all data types. This is an asynchronous operation |
| + // which happens after the current configuration pass is done, so a call to |
| + // this routine must be followed by a call to SetEnabledDataTypes(). |
| + void EnableEncryptEverything(JNIEnv* env, jobject obj); |
| + |
| + // Returns true if sync has encountered an unrecoverable error. |
| + jboolean HasUnrecoverableError(JNIEnv* env, jobject obj); |
| + |
| + // Returns sync internals in a JSON-formatted Java string. |
| + base::android::ScopedJavaLocalRef<jstring> GetAboutInfoForTest(JNIEnv* env, |
| + jobject obj); |
| + |
| + // Returns the integer value corresponding to the current auth error state |
| + // (GoogleServiceAuthError.State). |
| + jint GetAuthError(JNIEnv* env, jobject obj); |
| + |
| + // ProfileSyncServiceObserver: |
| + 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.
|
| + private: |
| + 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...
|
| + // Add and remove observers to profile sync service. |
| + void AddObserver(); |
| + void RemoveObserver(); |
| + void InvalidateAuthToken(); |
| + void SendNudgeNotification(const std::string& str_object_id, |
| + int64 version, |
| + const std::string& payload); |
| + |
| + Profile* profile_; |
| + ProfileSyncService* sync_service_; |
| + // Java-side ProfileSyncService object. |
| + JavaObjectWeakGlobalRef weak_java_profile_sync_service_; |
| + |
| + // The invalidation API spec allows for the possibility of redundant |
| + // invalidations, so keep track of the max versions and drop |
| + // invalidations with old versions. |
| + std::map<syncer::ModelType, int64> max_invalidation_versions_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceAndroid); |
| +}; |
| + |
| +// Registers the ProfileSyncServiceAndroid's native methods through JNI. |
| +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.
|
| + |
| +#endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_ANDROID_H_ |