| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_ANDROID_H_ | 5 #ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_ANDROID_H_ |
| 6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_ANDROID_H_ | 6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_ANDROID_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "base/android/jni_helper.h" | 11 #include "base/android/jni_helper.h" |
| 12 #include "base/callback.h" | |
| 13 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 14 #include "base/time.h" | |
| 15 #include "chrome/browser/sync/profile_sync_service_observer.h" | 13 #include "chrome/browser/sync/profile_sync_service_observer.h" |
| 16 #include "google_apis/gaia/google_service_auth_error.h" | |
| 17 #include "sync/internal_api/public/base/model_type.h" | 14 #include "sync/internal_api/public/base/model_type.h" |
| 18 | 15 |
| 19 class Profile; | 16 class Profile; |
| 20 class ProfileSyncService; | 17 class ProfileSyncService; |
| 21 | 18 |
| 22 // Android wrapper of the ProfileSyncService which provides access from the Java | 19 // Android wrapper of the ProfileSyncService which provides access from the Java |
| 23 // layer. Note that on Android, there's only a single profile, and therefore | 20 // layer. Note that on Android, there's only a single profile, and therefore |
| 24 // a single instance of this wrapper. The name of the Java class is | 21 // a single instance of this wrapper. The name of the Java class is |
| 25 // ProfileSyncService. | 22 // ProfileSyncService. |
| 26 // This class should only be accessed from the UI thread. | 23 // This class should only be accessed from the UI thread. |
| 27 class ProfileSyncServiceAndroid : public ProfileSyncServiceObserver { | 24 class ProfileSyncServiceAndroid : public ProfileSyncServiceObserver { |
| 28 public: | 25 public: |
| 29 // Callback from FetchOAuth2Token. | |
| 30 // Arguments: | |
| 31 // - the error, or NONE if the token fetch was successful. | |
| 32 // - the OAuth2 access token. | |
| 33 // - the expiry time of the token (may be null, indicating that the expiry | |
| 34 // time is unknown. | |
| 35 typedef base::Callback<void( | |
| 36 const GoogleServiceAuthError&,const std::string&,const base::Time&)> | |
| 37 FetchOAuth2TokenCallback; | |
| 38 | |
| 39 ProfileSyncServiceAndroid(JNIEnv* env, jobject obj); | 26 ProfileSyncServiceAndroid(JNIEnv* env, jobject obj); |
| 40 | 27 |
| 41 // This method should be called once right after contructing the object. | 28 // This method should be called once right after contructing the object. |
| 42 void Init(); | 29 void Init(); |
| 43 | 30 |
| 44 // Called from Java when we need to nudge native syncer. The |objectId|, | 31 // Called from Java when we need to nudge native syncer. The |objectId|, |
| 45 // |version| and |payload| values should come from an invalidation. | 32 // |version| and |payload| values should come from an invalidation. |
| 46 void NudgeSyncer(JNIEnv* env, | 33 void NudgeSyncer(JNIEnv* env, |
| 47 jobject obj, | 34 jobject obj, |
| 48 jstring objectId, | 35 jstring objectId, |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 jboolean HasUnrecoverableError(JNIEnv* env, jobject obj); | 180 jboolean HasUnrecoverableError(JNIEnv* env, jobject obj); |
| 194 | 181 |
| 195 // Returns sync internals in a JSON-formatted Java string. | 182 // Returns sync internals in a JSON-formatted Java string. |
| 196 base::android::ScopedJavaLocalRef<jstring> GetAboutInfoForTest(JNIEnv* env, | 183 base::android::ScopedJavaLocalRef<jstring> GetAboutInfoForTest(JNIEnv* env, |
| 197 jobject obj); | 184 jobject obj); |
| 198 | 185 |
| 199 // Returns the integer value corresponding to the current auth error state | 186 // Returns the integer value corresponding to the current auth error state |
| 200 // (GoogleServiceAuthError.State). | 187 // (GoogleServiceAuthError.State). |
| 201 jint GetAuthError(JNIEnv* env, jobject obj); | 188 jint GetAuthError(JNIEnv* env, jobject obj); |
| 202 | 189 |
| 203 // Called by native to invalidate an OAuth2 token, e.g. after a 401 response | |
| 204 // from the server. This should be done before fetching a new token. | |
| 205 void InvalidateOAuth2Token(const std::string& scope, | |
| 206 const std::string& invalid_auth_token); | |
| 207 | |
| 208 // Called by native when an OAuth2 token is required. |invalid_auth_token| | |
| 209 // is an old auth token to be invalidated (may be empty). |callback| will be | |
| 210 // invoked asynchronously after a new token has been fetched. | |
| 211 void FetchOAuth2Token(const std::string& scope, | |
| 212 const FetchOAuth2TokenCallback& callback); | |
| 213 | |
| 214 // Called from Java when fetching of an OAuth2 token is finished. The | |
| 215 // |authToken| param is only valid when |result| is true. | |
| 216 void OAuth2TokenFetched(JNIEnv* env, | |
| 217 jobject obj, | |
| 218 int callback, | |
| 219 jstring auth_token, | |
| 220 jboolean result); | |
| 221 | |
| 222 // ProfileSyncServiceObserver: | 190 // ProfileSyncServiceObserver: |
| 223 virtual void OnStateChanged() OVERRIDE; | 191 virtual void OnStateChanged() OVERRIDE; |
| 224 | 192 |
| 225 static ProfileSyncServiceAndroid* GetProfileSyncServiceAndroid(); | |
| 226 | |
| 227 // Registers the ProfileSyncServiceAndroid's native methods through JNI. | 193 // Registers the ProfileSyncServiceAndroid's native methods through JNI. |
| 228 static bool Register(JNIEnv* env); | 194 static bool Register(JNIEnv* env); |
| 229 | 195 |
| 230 private: | 196 private: |
| 231 virtual ~ProfileSyncServiceAndroid(); | 197 virtual ~ProfileSyncServiceAndroid(); |
| 232 // Remove observers to profile sync service. | 198 // Remove observers to profile sync service. |
| 233 void RemoveObserver(); | 199 void RemoveObserver(); |
| 234 void InvalidateAuthToken(); | 200 void InvalidateAuthToken(); |
| 235 // Called from Java when we need to nudge native syncer. The |objectId|, | 201 // Called from Java when we need to nudge native syncer. The |objectId|, |
| 236 // |version| and |payload| values should come from an invalidation. | 202 // |version| and |payload| values should come from an invalidation. |
| 237 void SendNudgeNotification(const std::string& str_object_id, | 203 void SendNudgeNotification(const std::string& str_object_id, |
| 238 int64 version, | 204 int64 version, |
| 239 const std::string& payload); | 205 const std::string& payload); |
| 240 | 206 |
| 241 Profile* profile_; | 207 Profile* profile_; |
| 242 ProfileSyncService* sync_service_; | 208 ProfileSyncService* sync_service_; |
| 243 // Java-side ProfileSyncService object. | 209 // Java-side ProfileSyncService object. |
| 244 JavaObjectWeakGlobalRef weak_java_profile_sync_service_; | 210 JavaObjectWeakGlobalRef weak_java_profile_sync_service_; |
| 245 | 211 |
| 246 // The invalidation API spec allows for the possibility of redundant | 212 // The invalidation API spec allows for the possibility of redundant |
| 247 // invalidations, so keep track of the max versions and drop | 213 // invalidations, so keep track of the max versions and drop |
| 248 // invalidations with old versions. | 214 // invalidations with old versions. |
| 249 std::map<syncer::ModelType, int64> max_invalidation_versions_; | 215 std::map<syncer::ModelType, int64> max_invalidation_versions_; |
| 250 | 216 |
| 251 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceAndroid); | 217 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceAndroid); |
| 252 }; | 218 }; |
| 253 | 219 |
| 254 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_ANDROID_H_ | 220 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_ANDROID_H_ |
| OLD | NEW |