Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1248)

Side by Side Diff: chrome/browser/sync/profile_sync_service_android.h

Issue 12880014: Get OAuth2TokenService working on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change args to const refs. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 typedef base::Callback<void(
30 const GoogleServiceAuthError&,const std::string&,const base::Time&)>
31 FetchOAuth2TokenCallback;
Roger Tawa OOO till Jul 10th 2013/03/25 20:47:20 Document args?
Patrick Dubroy 2013/03/25 21:15:49 Done.
32
26 ProfileSyncServiceAndroid(JNIEnv* env, jobject obj); 33 ProfileSyncServiceAndroid(JNIEnv* env, jobject obj);
27 34
28 // This method should be called once right after contructing the object. 35 // This method should be called once right after contructing the object.
29 void Init(); 36 void Init();
30 37
31 // Called from Java when we need to nudge native syncer. The |objectId|, 38 // Called from Java when we need to nudge native syncer. The |objectId|,
32 // |version| and |payload| values should come from an invalidation. 39 // |version| and |payload| values should come from an invalidation.
33 void NudgeSyncer(JNIEnv* env, 40 void NudgeSyncer(JNIEnv* env,
34 jobject obj, 41 jobject obj,
35 jstring objectId, 42 jstring objectId,
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 jboolean HasUnrecoverableError(JNIEnv* env, jobject obj); 187 jboolean HasUnrecoverableError(JNIEnv* env, jobject obj);
181 188
182 // Returns sync internals in a JSON-formatted Java string. 189 // Returns sync internals in a JSON-formatted Java string.
183 base::android::ScopedJavaLocalRef<jstring> GetAboutInfoForTest(JNIEnv* env, 190 base::android::ScopedJavaLocalRef<jstring> GetAboutInfoForTest(JNIEnv* env,
184 jobject obj); 191 jobject obj);
185 192
186 // Returns the integer value corresponding to the current auth error state 193 // Returns the integer value corresponding to the current auth error state
187 // (GoogleServiceAuthError.State). 194 // (GoogleServiceAuthError.State).
188 jint GetAuthError(JNIEnv* env, jobject obj); 195 jint GetAuthError(JNIEnv* env, jobject obj);
189 196
197 // Called by native to invalidate an OAuth2 token, e.g. after a 401 response
198 // from the server. This should be done before fetching a new token.
199 void InvalidateOAuth2Token(const std::string& scope,
200 const std::string& invalid_auth_token);
201
202 // Called by native when an OAuth2 token is required. |invalid_auth_token|
203 // is an old auth token to be invalidated (may be empty). |callback| will be
204 // invoked asynchronously after a new token has been fetched.
205 void FetchOAuth2Token(const std::string& scope,
206 const FetchOAuth2TokenCallback& callback);
207
208 // Called from Java when fetching of an OAuth2 token is finished. The
209 // |authToken| param is only valid when |result| is true.
210 void OAuth2TokenFetched(JNIEnv* env,
211 jobject obj,
212 int callback,
213 jstring auth_token,
214 jboolean result);
215
190 // ProfileSyncServiceObserver: 216 // ProfileSyncServiceObserver:
191 virtual void OnStateChanged() OVERRIDE; 217 virtual void OnStateChanged() OVERRIDE;
192 218
219 static ProfileSyncServiceAndroid* GetProfileSyncServiceAndroid();
220
193 // Registers the ProfileSyncServiceAndroid's native methods through JNI. 221 // Registers the ProfileSyncServiceAndroid's native methods through JNI.
194 static bool Register(JNIEnv* env); 222 static bool Register(JNIEnv* env);
195 223
196 private: 224 private:
197 virtual ~ProfileSyncServiceAndroid(); 225 virtual ~ProfileSyncServiceAndroid();
198 // Remove observers to profile sync service. 226 // Remove observers to profile sync service.
199 void RemoveObserver(); 227 void RemoveObserver();
200 void InvalidateAuthToken(); 228 void InvalidateAuthToken();
201 // Called from Java when we need to nudge native syncer. The |objectId|, 229 // Called from Java when we need to nudge native syncer. The |objectId|,
202 // |version| and |payload| values should come from an invalidation. 230 // |version| and |payload| values should come from an invalidation.
203 void SendNudgeNotification(const std::string& str_object_id, 231 void SendNudgeNotification(const std::string& str_object_id,
204 int64 version, 232 int64 version,
205 const std::string& payload); 233 const std::string& payload);
206 234
207 Profile* profile_; 235 Profile* profile_;
208 ProfileSyncService* sync_service_; 236 ProfileSyncService* sync_service_;
209 // Java-side ProfileSyncService object. 237 // Java-side ProfileSyncService object.
210 JavaObjectWeakGlobalRef weak_java_profile_sync_service_; 238 JavaObjectWeakGlobalRef weak_java_profile_sync_service_;
211 239
212 // The invalidation API spec allows for the possibility of redundant 240 // The invalidation API spec allows for the possibility of redundant
213 // invalidations, so keep track of the max versions and drop 241 // invalidations, so keep track of the max versions and drop
214 // invalidations with old versions. 242 // invalidations with old versions.
215 std::map<syncer::ModelType, int64> max_invalidation_versions_; 243 std::map<syncer::ModelType, int64> max_invalidation_versions_;
216 244
217 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceAndroid); 245 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceAndroid);
218 }; 246 };
219 247
220 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_ANDROID_H_ 248 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698