Chromium Code Reviews| 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_SIGNIN_ANDROID_PROFILE_OAUTH2_TOKEN_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SIGNIN_DELEGATE_ANDROID_OAUTH2_TOKEN_SERVICE_H_ |
| 6 #define CHROME_BROWSER_SIGNIN_ANDROID_PROFILE_OAUTH2_TOKEN_SERVICE_H_ | 6 #define CHROME_BROWSER_SIGNIN_DELEGATE_ANDROID_OAUTH2_TOKEN_SERVICE_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/android/jni_weak_ref.h" | 11 #include "base/android/jni_weak_ref.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 15 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 16 #include "google_apis/gaia/google_service_auth_error.h" | 16 #include "google_apis/gaia/google_service_auth_error.h" |
| 17 #include "google_apis/gaia/oauth2_token_service_delegate.h" | |
| 17 | 18 |
| 18 // A specialization of ProfileOAuth2TokenService that will be returned by | 19 // A specialization of OAuth2TokenServiceDelegate that will be returned by |
| 19 // ProfileOAuth2TokenServiceFactory for OS_ANDROID. This instance uses | 20 // OAuth2TokenServiceDelegateFactory for OS_ANDROID. This instance uses |
| 20 // native Android features to lookup OAuth2 tokens. | 21 // native Android features to lookup OAuth2 tokens. |
| 21 // | 22 // |
| 22 // See |ProfileOAuth2TokenService| for usage details. | 23 // See |OAuth2TokenServiceDelegate| for usage details. |
| 23 // | 24 // |
| 24 // Note: requests should be started from the UI thread. To start a | 25 // Note: requests should be started from the UI thread. To start a |
| 25 // request from other thread, please use OAuth2TokenServiceRequest. | 26 // request from other thread, please use OAuth2TokenServiceRequest. |
| 26 class AndroidProfileOAuth2TokenService : public ProfileOAuth2TokenService { | 27 class OAuth2TokenServiceDelegateAndroid : public OAuth2TokenServiceDelegate { |
| 27 public: | 28 public: |
| 28 // Registers the AndroidProfileOAuth2TokenService's native methods through | 29 // Registers the OAuth2TokenServiceDelegateAndroid's native methods through |
| 29 // JNI. | 30 // JNI. |
| 30 static bool Register(JNIEnv* env); | 31 static bool Register(JNIEnv* env); |
| 31 | 32 |
| 32 // Creates a new instance of the AndroidProfileOAuth2TokenService. | 33 // Creates a new instance of the OAuth2TokenServiceDelegateAndroid. |
| 33 static AndroidProfileOAuth2TokenService* Create(); | 34 static OAuth2TokenServiceDelegateAndroid* Create(); |
| 34 | 35 |
| 35 // Returns a reference to the Java instance of this service. | 36 // Returns a reference to the Java instance of this service. |
| 36 static jobject GetForProfile( | 37 static jobject GetForProfile(JNIEnv* env, |
| 37 JNIEnv* env, jclass clazz, jobject j_profile_android); | 38 jclass clazz, |
| 39 jobject j_profile_android); | |
| 38 | 40 |
| 39 // Called by the TestingProfile class to disable account validation in | 41 // Called by the TestingProfile class to disable account validation in |
| 40 // tests. This prevents the token service from trying to look up system | 42 // tests. This prevents the token service from trying to look up system |
| 41 // accounts which requires special permission. | 43 // accounts which requires special permission. |
| 42 static void set_is_testing_profile() { | 44 static void set_is_testing_profile() { is_testing_profile_ = true; } |
| 43 is_testing_profile_ = true; | |
| 44 } | |
| 45 | 45 |
| 46 // ProfileOAuth2TokenService overrides: | |
| 47 void Initialize(SigninClient* client, | 46 void Initialize(SigninClient* client, |
| 48 SigninErrorController* signin_error_controller) override; | 47 SigninErrorController* signin_error_controller) override; |
| 49 bool RefreshTokenIsAvailable(const std::string& account_id) const override; | 48 |
| 50 void UpdateAuthError(const std::string& account_id, | 49 // OAuth2TokenServiceDelegate overrides: |
| 51 const GoogleServiceAuthError& error) override; | 50 virtual bool RefreshTokenIsAvailable( |
| 52 std::vector<std::string> GetAccounts() override; | 51 const std::string& account_id) const override; |
| 52 virtual void UpdateAuthError(const std::string& account_id, | |
| 53 const GoogleServiceAuthError& error) override; | |
| 54 virtual std::vector<std::string> GetAccounts() override; | |
| 53 | 55 |
| 54 // Lists account at the OS level. | 56 // Lists account at the OS level. |
| 55 std::vector<std::string> GetSystemAccounts(); | 57 std::vector<std::string> GetSystemAccounts(); |
| 56 | 58 |
| 57 void ValidateAccounts(JNIEnv* env, | 59 void ValidateAccounts(JNIEnv* env, |
| 58 jobject obj, | 60 jobject obj, |
| 59 jstring current_account, | 61 jstring current_account, |
| 60 jboolean force_notifications); | 62 jboolean force_notifications); |
| 61 | 63 |
| 62 // Takes a the signed in sync account as well as all the other | 64 // Takes a the signed in sync account as well as all the other |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 80 // Triggers a notification to all observers of the OAuth2TokenService that all | 82 // Triggers a notification to all observers of the OAuth2TokenService that all |
| 81 // refresh tokens have now been loaded. | 83 // refresh tokens have now been loaded. |
| 82 virtual void FireRefreshTokensLoadedFromJava(JNIEnv* env, jobject obj); | 84 virtual void FireRefreshTokensLoadedFromJava(JNIEnv* env, jobject obj); |
| 83 | 85 |
| 84 // Overridden from OAuth2TokenService to complete signout of all | 86 // Overridden from OAuth2TokenService to complete signout of all |
| 85 // OA2TService aware accounts. | 87 // OA2TService aware accounts. |
| 86 void RevokeAllCredentials() override; | 88 void RevokeAllCredentials() override; |
| 87 | 89 |
| 88 protected: | 90 protected: |
| 89 friend class ProfileOAuth2TokenServiceFactory; | 91 friend class ProfileOAuth2TokenServiceFactory; |
| 90 AndroidProfileOAuth2TokenService(); | 92 OAuth2TokenServiceDelegateAndroid(); |
| 91 ~AndroidProfileOAuth2TokenService() override; | 93 ~OAuth2TokenServiceDelegateAndroid() override; |
| 92 | 94 |
| 93 OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( | 95 OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( |
| 94 const std::string& account_id, | 96 const std::string& account_id, |
| 95 net::URLRequestContextGetter* getter, | 97 net::URLRequestContextGetter* getter, |
| 96 OAuth2AccessTokenConsumer* consumer) override; | 98 OAuth2AccessTokenConsumer* consumer) override; |
| 97 | 99 |
| 98 // Overridden from OAuth2TokenService to intercept token fetch requests and | 100 // Overridden from OAuth2TokenService to intercept token fetch requests and |
| 99 // redirect them to the Account Manager. | 101 // redirect them to the Account Manager. |
| 100 void InvalidateOAuth2Token(const std::string& account_id, | 102 virtual void InvalidateOAuth2Token(const std::string& account_id, |
| 101 const std::string& client_id, | 103 const std::string& client_id, |
| 102 const ScopeSet& scopes, | 104 const OAuth2TokenService::ScopeSet& scopes, |
| 103 const std::string& access_token) override; | 105 const std::string& access_token) override; |
|
Roger Tawa OOO till Jul 10th
2015/05/24 21:13:18
Nit: don't use virtual and override. Use only the
gogerald1
2015/05/25 21:10:57
Something wrong here. It overrides the interface d
gogerald1
2015/05/25 21:10:57
Done.
| |
| 104 | 106 |
| 105 // Called to notify observers when a refresh token is available. | 107 // Called to notify observers when a refresh token is available. |
| 106 void FireRefreshTokenAvailable(const std::string& account_id) override; | 108 void FireRefreshTokenAvailable(const std::string& account_id) override; |
| 107 // Called to notify observers when a refresh token has been revoked. | 109 // Called to notify observers when a refresh token has been revoked. |
| 108 void FireRefreshTokenRevoked(const std::string& account_id) override; | 110 void FireRefreshTokenRevoked(const std::string& account_id) override; |
| 109 // Called to notify observers when refresh tokans have been loaded. | 111 // Called to notify observers when refresh tokans have been loaded. |
| 110 void FireRefreshTokensLoaded() override; | 112 void FireRefreshTokensLoaded() override; |
| 111 | 113 |
| 112 private: | 114 private: |
| 113 // Return whether |signed_in_account| is valid and we have access | 115 // Return whether |signed_in_account| is valid and we have access |
| 114 // to all the tokens in |curr_account_ids|. If |force_notifications| is true, | 116 // to all the tokens in |curr_account_ids|. If |force_notifications| is true, |
| 115 // TokenAvailable notifications will be sent anyway, even if the account was | 117 // TokenAvailable notifications will be sent anyway, even if the account was |
| 116 // already known. | 118 // already known. |
| 117 bool ValidateAccounts(const std::string& signed_in_account, | 119 bool ValidateAccounts(const std::string& signed_in_account, |
| 118 const std::vector<std::string>& prev_account_ids, | 120 const std::vector<std::string>& prev_account_ids, |
| 119 const std::vector<std::string>& curr_account_ids, | 121 const std::vector<std::string>& curr_account_ids, |
| 120 std::vector<std::string>& refreshed_ids, | 122 std::vector<std::string>& refreshed_ids, |
| 121 std::vector<std::string>& revoked_ids, | 123 std::vector<std::string>& revoked_ids, |
| 122 bool force_notifications); | 124 bool force_notifications); |
| 123 | 125 |
| 124 base::android::ScopedJavaGlobalRef<jobject> java_ref_; | 126 base::android::ScopedJavaGlobalRef<jobject> java_ref_; |
| 125 | 127 |
| 126 static bool is_testing_profile_; | 128 static bool is_testing_profile_; |
| 127 | 129 |
| 128 DISALLOW_COPY_AND_ASSIGN(AndroidProfileOAuth2TokenService); | 130 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenServiceDelegateAndroid); |
| 129 }; | 131 }; |
| 130 | 132 |
| 131 #endif // CHROME_BROWSER_SIGNIN_ANDROID_PROFILE_OAUTH2_TOKEN_SERVICE_H_ | 133 #endif // CHROME_BROWSER_SIGNIN_DELEGATE_ANDROID_OAUTH2_TOKEN_SERVICE_H_ |
| OLD | NEW |