Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / signin / android_profile_oauth2_token_service.h
blob44876b2cfe95193960c7cf6a3f4c60f465a1eede
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.
5 #ifndef CHROME_BROWSER_SIGNIN_ANDROID_PROFILE_OAUTH2_TOKEN_SERVICE_H_
6 #define CHROME_BROWSER_SIGNIN_ANDROID_PROFILE_OAUTH2_TOKEN_SERVICE_H_
8 #include <jni.h>
9 #include <string>
11 #include "base/android/jni_helper.h"
12 #include "base/callback.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/time/time.h"
15 #include "chrome/browser/signin/profile_oauth2_token_service.h"
16 #include "google_apis/gaia/google_service_auth_error.h"
18 // A specialization of ProfileOAuth2TokenService that will be returned by
19 // ProfileOAuth2TokenServiceFactory for OS_ANDROID. This instance uses
20 // native Android features to lookup OAuth2 tokens.
22 // See |ProfileOAuth2TokenService| for usage details.
24 // Note: requests should be started from the UI thread. To start a
25 // request from other thread, please use ProfileOAuth2TokenServiceRequest.
26 class AndroidProfileOAuth2TokenService : public ProfileOAuth2TokenService {
27 public:
28 // Registers the AndroidProfileOAuth2TokenService's native methods through
29 // JNI.
30 static bool Register(JNIEnv* env);
32 // Creates a new instance of the AndroidProfileOAuth2TokenService.
33 static AndroidProfileOAuth2TokenService* Create();
35 // Returns a reference to the Java instance of this service.
36 static jobject GetForProfile(
37 JNIEnv* env, jclass clazz, jobject j_profile_android);
39 virtual bool RefreshTokenIsAvailable(
40 const std::string& account_id) OVERRIDE;
42 // Lists account IDs of all accounts with a refresh token.
43 virtual std::vector<std::string> GetAccounts() OVERRIDE;
45 void ValidateAccounts(JNIEnv* env,
46 jobject obj,
47 jobjectArray accounts,
48 jstring current_account);
50 // Takes a the signed in sync account as well as all the other
51 // android account ids and check the token status of each.
52 void ValidateAccounts(const std::string& signed_in_account,
53 const std::vector<std::string>& account_ids);
55 // Triggers a notification to all observers of the OAuth2TokenService that a
56 // refresh token is now available. This may cause observers to retry
57 // operations that require authentication.
58 virtual void FireRefreshTokenAvailableFromJava(JNIEnv* env,
59 jobject obj,
60 const jstring account_name);
61 // Triggers a notification to all observers of the OAuth2TokenService that a
62 // refresh token is now available.
63 virtual void FireRefreshTokenRevokedFromJava(JNIEnv* env,
64 jobject obj,
65 const jstring account_name);
66 // Triggers a notification to all observers of the OAuth2TokenService that all
67 // refresh tokens have now been loaded.
68 virtual void FireRefreshTokensLoadedFromJava(JNIEnv* env, jobject obj);
70 protected:
71 friend class ProfileOAuth2TokenServiceFactory;
72 AndroidProfileOAuth2TokenService();
73 virtual ~AndroidProfileOAuth2TokenService();
75 // Overridden from OAuth2TokenService to intercept token fetch requests and
76 // redirect them to the Account Manager.
77 virtual void FetchOAuth2Token(RequestImpl* request,
78 const std::string& account_id,
79 net::URLRequestContextGetter* getter,
80 const std::string& client_id,
81 const std::string& client_secret,
82 const ScopeSet& scopes) OVERRIDE;
84 // Overridden from OAuth2TokenService to intercept token fetch requests and
85 // redirect them to the Account Manager.
86 virtual void InvalidateOAuth2Token(const std::string& account_id,
87 const std::string& client_id,
88 const ScopeSet& scopes,
89 const std::string& access_token) OVERRIDE;
91 // Called to notify observers when a refresh token is available.
92 virtual void FireRefreshTokenAvailable(
93 const std::string& account_id) OVERRIDE;
94 // Called to notify observers when a refresh token has been revoked.
95 virtual void FireRefreshTokenRevoked(const std::string& account_id) OVERRIDE;
96 // Called to notify observers when refresh tokans have been loaded.
97 virtual void FireRefreshTokensLoaded() OVERRIDE;
99 private:
100 base::android::ScopedJavaGlobalRef<jobject> java_ref_;
102 DISALLOW_COPY_AND_ASSIGN(AndroidProfileOAuth2TokenService);
105 #endif // CHROME_BROWSER_SIGNIN_ANDROID_PROFILE_OAUTH2_TOKEN_SERVICE_H_