| 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_DELEGATE_ANDROID_OAUTH2_TOKEN_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SIGNIN_OAUTH2_TOKEN_SERVICE_DELEGATE_ANDROID_H_ |
| 6 #define CHROME_BROWSER_SIGNIN_DELEGATE_ANDROID_OAUTH2_TOKEN_SERVICE_H_ | 6 #define CHROME_BROWSER_SIGNIN_OAUTH2_TOKEN_SERVICE_DELEGATE_ANDROID_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/account_tracker_service.h" |
| 15 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 16 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 16 #include "google_apis/gaia/google_service_auth_error.h" | 17 #include "google_apis/gaia/google_service_auth_error.h" |
| 17 #include "google_apis/gaia/oauth2_token_service_delegate.h" | 18 #include "google_apis/gaia/oauth2_token_service_delegate.h" |
| 18 | 19 |
| 19 // A specialization of OAuth2TokenServiceDelegate that will be returned by | 20 // A specialization of OAuth2TokenServiceDelegate that will be returned by |
| 20 // OAuth2TokenServiceDelegateFactory for OS_ANDROID. This instance uses | 21 // OAuth2TokenServiceDelegateFactory for OS_ANDROID. This instance uses |
| 21 // native Android features to lookup OAuth2 tokens. | 22 // native Android features to lookup OAuth2 tokens. |
| 22 // | 23 // |
| 23 // See |OAuth2TokenServiceDelegate| for usage details. | 24 // See |OAuth2TokenServiceDelegate| for usage details. |
| 24 // | 25 // |
| (...skipping 11 matching lines...) Expand all Loading... |
| 36 // Returns a reference to the Java instance of this service. | 37 // Returns a reference to the Java instance of this service. |
| 37 static jobject GetForProfile(JNIEnv* env, | 38 static jobject GetForProfile(JNIEnv* env, |
| 38 jclass clazz, | 39 jclass clazz, |
| 39 jobject j_profile_android); | 40 jobject j_profile_android); |
| 40 | 41 |
| 41 // Called by the TestingProfile class to disable account validation in | 42 // Called by the TestingProfile class to disable account validation in |
| 42 // tests. This prevents the token service from trying to look up system | 43 // tests. This prevents the token service from trying to look up system |
| 43 // accounts which requires special permission. | 44 // accounts which requires special permission. |
| 44 static void set_is_testing_profile() { is_testing_profile_ = true; } | 45 static void set_is_testing_profile() { is_testing_profile_ = true; } |
| 45 | 46 |
| 46 void Initialize(); | 47 void Initialize(AccountTrackerService* account_tracker_service); |
| 47 | 48 |
| 48 // OAuth2TokenServiceDelegate overrides: | 49 // OAuth2TokenServiceDelegate overrides: |
| 49 bool RefreshTokenIsAvailable(const std::string& account_id) const override; | 50 bool RefreshTokenIsAvailable(const std::string& account_id) const override; |
| 50 void UpdateAuthError(const std::string& account_id, | 51 void UpdateAuthError(const std::string& account_id, |
| 51 const GoogleServiceAuthError& error) override; | 52 const GoogleServiceAuthError& error) override; |
| 52 std::vector<std::string> GetAccounts() override; | 53 std::vector<std::string> GetAccounts() override; |
| 53 | 54 |
| 54 // Lists account at the OS level. | 55 // Lists account names at the OS level. |
| 55 std::vector<std::string> GetSystemAccounts(); | 56 std::vector<std::string> GetSystemAccountNames(); |
| 56 | 57 |
| 57 void ValidateAccounts(JNIEnv* env, | 58 void ValidateAccounts(JNIEnv* env, |
| 58 jobject obj, | 59 jobject obj, |
| 59 jstring current_account, | 60 jstring current_account, |
| 60 jboolean force_notifications); | 61 jboolean force_notifications); |
| 61 | 62 |
| 62 // Takes a the signed in sync account as well as all the other | 63 // Takes a the signed in sync account as well as all the other |
| 63 // android account ids and check the token status of each. If | 64 // android account ids and check the token status of each. If |
| 64 // |force_notifications| is true, TokenAvailable notifications will | 65 // |force_notifications| is true, TokenAvailable notifications will |
| 65 // be sent anyway, even if the account was already known. | 66 // be sent anyway, even if the account was already known. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 78 jobject obj, | 79 jobject obj, |
| 79 const jstring account_name); | 80 const jstring account_name); |
| 80 // Triggers a notification to all observers of the OAuth2TokenService that all | 81 // Triggers a notification to all observers of the OAuth2TokenService that all |
| 81 // refresh tokens have now been loaded. | 82 // refresh tokens have now been loaded. |
| 82 virtual void FireRefreshTokensLoadedFromJava(JNIEnv* env, jobject obj); | 83 virtual void FireRefreshTokensLoadedFromJava(JNIEnv* env, jobject obj); |
| 83 | 84 |
| 84 // Overridden from OAuth2TokenService to complete signout of all | 85 // Overridden from OAuth2TokenService to complete signout of all |
| 85 // OA2TService aware accounts. | 86 // OA2TService aware accounts. |
| 86 void RevokeAllCredentials() override; | 87 void RevokeAllCredentials() override; |
| 87 | 88 |
| 89 void LoadCredentials(const std::string& primary_account_id) override; |
| 90 |
| 88 protected: | 91 protected: |
| 89 friend class ProfileOAuth2TokenServiceFactory; | 92 friend class ProfileOAuth2TokenServiceFactory; |
| 90 OAuth2TokenServiceDelegateAndroid(); | 93 OAuth2TokenServiceDelegateAndroid(); |
| 91 ~OAuth2TokenServiceDelegateAndroid() override; | 94 ~OAuth2TokenServiceDelegateAndroid() override; |
| 92 | 95 |
| 93 OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( | 96 OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( |
| 94 const std::string& account_id, | 97 const std::string& account_id, |
| 95 net::URLRequestContextGetter* getter, | 98 net::URLRequestContextGetter* getter, |
| 96 OAuth2AccessTokenConsumer* consumer) override; | 99 OAuth2AccessTokenConsumer* consumer) override; |
| 97 | 100 |
| 98 // Overridden from OAuth2TokenService to intercept token fetch requests and | 101 // Overridden from OAuth2TokenService to intercept token fetch requests and |
| 99 // redirect them to the Account Manager. | 102 // redirect them to the Account Manager. |
| 100 void InvalidateAccessToken(const std::string& account_id, | 103 void InvalidateAccessToken(const std::string& account_id, |
| 101 const std::string& client_id, | 104 const std::string& client_id, |
| 102 const OAuth2TokenService::ScopeSet& scopes, | 105 const OAuth2TokenService::ScopeSet& scopes, |
| 103 const std::string& access_token) override; | 106 const std::string& access_token) override; |
| 104 | 107 |
| 105 // Called to notify observers when a refresh token is available. | 108 // Called to notify observers when a refresh token is available. |
| 106 void FireRefreshTokenAvailable(const std::string& account_id) override; | 109 void FireRefreshTokenAvailable(const std::string& account_id) override; |
| 107 // Called to notify observers when a refresh token has been revoked. | 110 // Called to notify observers when a refresh token has been revoked. |
| 108 void FireRefreshTokenRevoked(const std::string& account_id) override; | 111 void FireRefreshTokenRevoked(const std::string& account_id) override; |
| 109 // Called to notify observers when refresh tokans have been loaded. | 112 // Called to notify observers when refresh tokans have been loaded. |
| 110 void FireRefreshTokensLoaded() override; | 113 void FireRefreshTokensLoaded() override; |
| 111 | 114 |
| 112 private: | 115 private: |
| 116 std::string MapAccountIdToAccountName(const std::string& account_id) const; |
| 117 std::string MapAccountNameToAccountId(const std::string& account_name) const; |
| 118 |
| 113 // Return whether |signed_in_account| is valid and we have access | 119 // 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, | 120 // 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 | 121 // TokenAvailable notifications will be sent anyway, even if the account was |
| 116 // already known. | 122 // already known. |
| 117 bool ValidateAccounts(const std::string& signed_in_account, | 123 bool ValidateAccounts(const std::string& signed_in_account, |
| 118 const std::vector<std::string>& prev_account_ids, | 124 const std::vector<std::string>& prev_account_ids, |
| 119 const std::vector<std::string>& curr_account_ids, | 125 const std::vector<std::string>& curr_account_ids, |
| 120 std::vector<std::string>& refreshed_ids, | 126 std::vector<std::string>& refreshed_ids, |
| 121 std::vector<std::string>& revoked_ids, | 127 std::vector<std::string>& revoked_ids, |
| 122 bool force_notifications); | 128 bool force_notifications); |
| 123 | 129 |
| 124 base::android::ScopedJavaGlobalRef<jobject> java_ref_; | 130 base::android::ScopedJavaGlobalRef<jobject> java_ref_; |
| 125 | 131 |
| 132 AccountTrackerService* account_tracker_service_; |
| 133 bool accounts_have_been_validated_; |
| 134 bool should_fire_refresh_token_loaded_; |
| 135 base::Lock lock_; |
| 126 static bool is_testing_profile_; | 136 static bool is_testing_profile_; |
| 127 | 137 |
| 128 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenServiceDelegateAndroid); | 138 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenServiceDelegateAndroid); |
| 129 }; | 139 }; |
| 130 | 140 |
| 131 #endif // CHROME_BROWSER_SIGNIN_DELEGATE_ANDROID_OAUTH2_TOKEN_SERVICE_H_ | 141 #endif // CHROME_BROWSER_SIGNIN_OAUTH2_TOKEN_SERVICE_DELEGATE_ANDROID_H_ |
| OLD | NEW |