| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_SIGNIN_IOS_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_H_ | 5 #ifndef COMPONENTS_SIGNIN_IOS_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_H_ |
| 6 #define COMPONENTS_SIGNIN_IOS_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_H_ | 6 #define COMPONENTS_SIGNIN_IOS_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/threading/thread_checker.h" | 10 #include "base/threading/thread_checker.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // ProfileOAuth2TokenServiceFactory for OS_IOS when iOS authentication service | 21 // ProfileOAuth2TokenServiceFactory for OS_IOS when iOS authentication service |
| 22 // is used to lookup OAuth2 tokens. | 22 // is used to lookup OAuth2 tokens. |
| 23 // | 23 // |
| 24 // See |ProfileOAuth2TokenService| for usage details. | 24 // See |ProfileOAuth2TokenService| for usage details. |
| 25 // | 25 // |
| 26 // Note: Requests should be started from the UI thread. To start a | 26 // Note: Requests should be started from the UI thread. To start a |
| 27 // request from aother thread, please use OAuth2TokenServiceRequest. | 27 // request from aother thread, please use OAuth2TokenServiceRequest. |
| 28 class ProfileOAuth2TokenServiceIOS : public ProfileOAuth2TokenService { | 28 class ProfileOAuth2TokenServiceIOS : public ProfileOAuth2TokenService { |
| 29 public: | 29 public: |
| 30 // KeyedService | 30 // KeyedService |
| 31 virtual void Shutdown() override; | 31 void Shutdown() override; |
| 32 | 32 |
| 33 // OAuth2TokenService | 33 // OAuth2TokenService |
| 34 virtual bool RefreshTokenIsAvailable( | 34 bool RefreshTokenIsAvailable(const std::string& account_id) const override; |
| 35 const std::string& account_id) const override; | |
| 36 | 35 |
| 37 virtual void InvalidateOAuth2Token(const std::string& account_id, | 36 void InvalidateOAuth2Token(const std::string& account_id, |
| 38 const std::string& client_id, | 37 const std::string& client_id, |
| 39 const ScopeSet& scopes, | 38 const ScopeSet& scopes, |
| 40 const std::string& access_token) override; | 39 const std::string& access_token) override; |
| 41 | 40 |
| 42 // ProfileOAuth2TokenService | 41 // ProfileOAuth2TokenService |
| 43 virtual void Initialize( | 42 void Initialize(SigninClient* client, |
| 44 SigninClient* client, | 43 SigninErrorController* signin_error_controller) override; |
| 45 SigninErrorController* signin_error_controller) override; | 44 void LoadCredentials(const std::string& primary_account_id) override; |
| 46 virtual void LoadCredentials(const std::string& primary_account_id) override; | 45 std::vector<std::string> GetAccounts() override; |
| 47 virtual std::vector<std::string> GetAccounts() override; | 46 void UpdateAuthError(const std::string& account_id, |
| 48 virtual void UpdateAuthError(const std::string& account_id, | 47 const GoogleServiceAuthError& error) override; |
| 49 const GoogleServiceAuthError& error) override; | |
| 50 | 48 |
| 51 // This method should not be called when using shared authentication. | 49 // This method should not be called when using shared authentication. |
| 52 virtual void UpdateCredentials(const std::string& account_id, | 50 void UpdateCredentials(const std::string& account_id, |
| 53 const std::string& refresh_token) override; | 51 const std::string& refresh_token) override; |
| 54 | 52 |
| 55 // Removes all credentials from this instance of |ProfileOAuth2TokenService|, | 53 // Removes all credentials from this instance of |ProfileOAuth2TokenService|, |
| 56 // however, it does not revoke the identities from the device. | 54 // however, it does not revoke the identities from the device. |
| 57 // Subsequent calls to |RefreshTokenIsAvailable| will return |false|. | 55 // Subsequent calls to |RefreshTokenIsAvailable| will return |false|. |
| 58 virtual void RevokeAllCredentials() override; | 56 void RevokeAllCredentials() override; |
| 59 | 57 |
| 60 // Reloads accounts from the provider. Fires |OnRefreshTokenAvailable| for | 58 // Reloads accounts from the provider. Fires |OnRefreshTokenAvailable| for |
| 61 // each new account. Fires |OnRefreshTokenRevoked| for each account that was | 59 // each new account. Fires |OnRefreshTokenRevoked| for each account that was |
| 62 // removed. | 60 // removed. |
| 63 void ReloadCredentials(); | 61 void ReloadCredentials(); |
| 64 | 62 |
| 65 protected: | 63 protected: |
| 66 friend class ProfileOAuth2TokenServiceFactory; | 64 friend class ProfileOAuth2TokenServiceFactory; |
| 67 friend class ProfileOAuth2TokenServiceIOSTest; | 65 friend class ProfileOAuth2TokenServiceIOSTest; |
| 68 | 66 |
| 69 ProfileOAuth2TokenServiceIOS(); | 67 ProfileOAuth2TokenServiceIOS(); |
| 70 virtual ~ProfileOAuth2TokenServiceIOS(); | 68 ~ProfileOAuth2TokenServiceIOS() override; |
| 71 | 69 |
| 72 virtual OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( | 70 OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( |
| 73 const std::string& account_id, | 71 const std::string& account_id, |
| 74 net::URLRequestContextGetter* getter, | 72 net::URLRequestContextGetter* getter, |
| 75 OAuth2AccessTokenConsumer* consumer) override; | 73 OAuth2AccessTokenConsumer* consumer) override; |
| 76 | 74 |
| 77 // Protected and virtual to be overriden by fake for testing. | 75 // Protected and virtual to be overriden by fake for testing. |
| 78 | 76 |
| 79 // Adds |account_id| to |accounts_| if it does not exist or udpates | 77 // Adds |account_id| to |accounts_| if it does not exist or udpates |
| 80 // the auth error state of |account_id| if it exists. Fires | 78 // the auth error state of |account_id| if it exists. Fires |
| 81 // |OnRefreshTokenAvailable| if the account info is updated. | 79 // |OnRefreshTokenAvailable| if the account info is updated. |
| 82 virtual void AddOrUpdateAccount(const std::string& account_id); | 80 virtual void AddOrUpdateAccount(const std::string& account_id); |
| 83 | 81 |
| 84 // Removes |account_id| from |accounts_|. Fires |OnRefreshTokenRevoked| | 82 // Removes |account_id| from |accounts_|. Fires |OnRefreshTokenRevoked| |
| 85 // if the account info is removed. | 83 // if the account info is removed. |
| 86 virtual void RemoveAccount(const std::string& account_id); | 84 virtual void RemoveAccount(const std::string& account_id); |
| 87 | 85 |
| 88 private: | 86 private: |
| 89 class AccountInfo : public SigninErrorController::AuthStatusProvider { | 87 class AccountInfo : public SigninErrorController::AuthStatusProvider { |
| 90 public: | 88 public: |
| 91 AccountInfo(SigninErrorController* signin_error_controller, | 89 AccountInfo(SigninErrorController* signin_error_controller, |
| 92 const std::string& account_id); | 90 const std::string& account_id); |
| 93 virtual ~AccountInfo(); | 91 ~AccountInfo() override; |
| 94 | 92 |
| 95 void SetLastAuthError(const GoogleServiceAuthError& error); | 93 void SetLastAuthError(const GoogleServiceAuthError& error); |
| 96 | 94 |
| 97 // SigninErrorController::AuthStatusProvider implementation. | 95 // SigninErrorController::AuthStatusProvider implementation. |
| 98 virtual std::string GetAccountId() const override; | 96 std::string GetAccountId() const override; |
| 99 virtual std::string GetUsername() const override; | 97 std::string GetUsername() const override; |
| 100 virtual GoogleServiceAuthError GetAuthStatus() const override; | 98 GoogleServiceAuthError GetAuthStatus() const override; |
| 101 | 99 |
| 102 private: | 100 private: |
| 103 SigninErrorController* signin_error_controller_; | 101 SigninErrorController* signin_error_controller_; |
| 104 std::string account_id_; | 102 std::string account_id_; |
| 105 GoogleServiceAuthError last_auth_error_; | 103 GoogleServiceAuthError last_auth_error_; |
| 106 | 104 |
| 107 DISALLOW_COPY_AND_ASSIGN(AccountInfo); | 105 DISALLOW_COPY_AND_ASSIGN(AccountInfo); |
| 108 }; | 106 }; |
| 109 | 107 |
| 110 // Maps the |account_id| of accounts known to ProfileOAuth2TokenService | 108 // Maps the |account_id| of accounts known to ProfileOAuth2TokenService |
| 111 // to information about the account. | 109 // to information about the account. |
| 112 typedef std::map<std::string, linked_ptr<AccountInfo> > AccountInfoMap; | 110 typedef std::map<std::string, linked_ptr<AccountInfo> > AccountInfoMap; |
| 113 | 111 |
| 114 // Returns the iOS provider; | 112 // Returns the iOS provider; |
| 115 ios::ProfileOAuth2TokenServiceIOSProvider* GetProvider(); | 113 ios::ProfileOAuth2TokenServiceIOSProvider* GetProvider(); |
| 116 | 114 |
| 117 // Info about the existing accounts. | 115 // Info about the existing accounts. |
| 118 AccountInfoMap accounts_; | 116 AccountInfoMap accounts_; |
| 119 | 117 |
| 120 // Calls to this class are expected to be made from the browser UI thread. | 118 // Calls to this class are expected to be made from the browser UI thread. |
| 121 // The purpose of this checker is to detect access to | 119 // The purpose of this checker is to detect access to |
| 122 // ProfileOAuth2TokenService from multiple threads in upstream code. | 120 // ProfileOAuth2TokenService from multiple threads in upstream code. |
| 123 base::ThreadChecker thread_checker_; | 121 base::ThreadChecker thread_checker_; |
| 124 | 122 |
| 125 DISALLOW_COPY_AND_ASSIGN(ProfileOAuth2TokenServiceIOS); | 123 DISALLOW_COPY_AND_ASSIGN(ProfileOAuth2TokenServiceIOS); |
| 126 }; | 124 }; |
| 127 | 125 |
| 128 #endif // COMPONENTS_SIGNIN_IOS_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_H_ | 126 #endif // COMPONENTS_SIGNIN_IOS_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_H_ |
| OLD | NEW |