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" |
12 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/time.h" |
13 #include "chrome/browser/sync/profile_sync_service_observer.h" | 15 #include "chrome/browser/sync/profile_sync_service_observer.h" |
| 16 #include "google_apis/gaia/google_service_auth_error.h" |
14 #include "sync/internal_api/public/base/model_type.h" | 17 #include "sync/internal_api/public/base/model_type.h" |
15 | 18 |
16 class Profile; | 19 class Profile; |
17 class ProfileSyncService; | 20 class ProfileSyncService; |
18 | 21 |
19 // Android wrapper of the ProfileSyncService which provides access from the Java | 22 // 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 | 23 // 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 | 24 // a single instance of this wrapper. The name of the Java class is |
22 // ProfileSyncService. | 25 // ProfileSyncService. |
23 // This class should only be accessed from the UI thread. | 26 // This class should only be accessed from the UI thread. |
24 class ProfileSyncServiceAndroid : public ProfileSyncServiceObserver { | 27 class ProfileSyncServiceAndroid : public ProfileSyncServiceObserver { |
25 public: | 28 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 |
26 ProfileSyncServiceAndroid(JNIEnv* env, jobject obj); | 39 ProfileSyncServiceAndroid(JNIEnv* env, jobject obj); |
27 | 40 |
28 // This method should be called once right after contructing the object. | 41 // This method should be called once right after contructing the object. |
29 void Init(); | 42 void Init(); |
30 | 43 |
31 // Called from Java when we need to nudge native syncer. The |objectId|, | 44 // Called from Java when we need to nudge native syncer. The |objectId|, |
32 // |version| and |payload| values should come from an invalidation. | 45 // |version| and |payload| values should come from an invalidation. |
33 void NudgeSyncer(JNIEnv* env, | 46 void NudgeSyncer(JNIEnv* env, |
34 jobject obj, | 47 jobject obj, |
35 jstring objectId, | 48 jstring objectId, |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 jboolean HasUnrecoverableError(JNIEnv* env, jobject obj); | 193 jboolean HasUnrecoverableError(JNIEnv* env, jobject obj); |
181 | 194 |
182 // Returns sync internals in a JSON-formatted Java string. | 195 // Returns sync internals in a JSON-formatted Java string. |
183 base::android::ScopedJavaLocalRef<jstring> GetAboutInfoForTest(JNIEnv* env, | 196 base::android::ScopedJavaLocalRef<jstring> GetAboutInfoForTest(JNIEnv* env, |
184 jobject obj); | 197 jobject obj); |
185 | 198 |
186 // Returns the integer value corresponding to the current auth error state | 199 // Returns the integer value corresponding to the current auth error state |
187 // (GoogleServiceAuthError.State). | 200 // (GoogleServiceAuthError.State). |
188 jint GetAuthError(JNIEnv* env, jobject obj); | 201 jint GetAuthError(JNIEnv* env, jobject obj); |
189 | 202 |
| 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 |
190 // ProfileSyncServiceObserver: | 222 // ProfileSyncServiceObserver: |
191 virtual void OnStateChanged() OVERRIDE; | 223 virtual void OnStateChanged() OVERRIDE; |
192 | 224 |
| 225 static ProfileSyncServiceAndroid* GetProfileSyncServiceAndroid(); |
| 226 |
193 // Registers the ProfileSyncServiceAndroid's native methods through JNI. | 227 // Registers the ProfileSyncServiceAndroid's native methods through JNI. |
194 static bool Register(JNIEnv* env); | 228 static bool Register(JNIEnv* env); |
195 | 229 |
196 private: | 230 private: |
197 virtual ~ProfileSyncServiceAndroid(); | 231 virtual ~ProfileSyncServiceAndroid(); |
198 // Remove observers to profile sync service. | 232 // Remove observers to profile sync service. |
199 void RemoveObserver(); | 233 void RemoveObserver(); |
200 void InvalidateAuthToken(); | 234 void InvalidateAuthToken(); |
201 // Called from Java when we need to nudge native syncer. The |objectId|, | 235 // Called from Java when we need to nudge native syncer. The |objectId|, |
202 // |version| and |payload| values should come from an invalidation. | 236 // |version| and |payload| values should come from an invalidation. |
203 void SendNudgeNotification(const std::string& str_object_id, | 237 void SendNudgeNotification(const std::string& str_object_id, |
204 int64 version, | 238 int64 version, |
205 const std::string& payload); | 239 const std::string& payload); |
206 | 240 |
207 Profile* profile_; | 241 Profile* profile_; |
208 ProfileSyncService* sync_service_; | 242 ProfileSyncService* sync_service_; |
209 // Java-side ProfileSyncService object. | 243 // Java-side ProfileSyncService object. |
210 JavaObjectWeakGlobalRef weak_java_profile_sync_service_; | 244 JavaObjectWeakGlobalRef weak_java_profile_sync_service_; |
211 | 245 |
212 // The invalidation API spec allows for the possibility of redundant | 246 // The invalidation API spec allows for the possibility of redundant |
213 // invalidations, so keep track of the max versions and drop | 247 // invalidations, so keep track of the max versions and drop |
214 // invalidations with old versions. | 248 // invalidations with old versions. |
215 std::map<syncer::ModelType, int64> max_invalidation_versions_; | 249 std::map<syncer::ModelType, int64> max_invalidation_versions_; |
216 | 250 |
217 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceAndroid); | 251 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceAndroid); |
218 }; | 252 }; |
219 | 253 |
220 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_ANDROID_H_ | 254 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_ANDROID_H_ |
OLD | NEW |