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" |
11 #include "components/signin/core/browser/mutable_profile_oauth2_token_service.h" | 11 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
12 | 12 |
13 class OAuth2AccessTokenFetcher; | 13 class OAuth2AccessTokenFetcher; |
14 | 14 |
15 namespace ios{ | 15 namespace ios{ |
16 class ProfileOAuth2TokenServiceIOSProvider; | 16 class ProfileOAuth2TokenServiceIOSProvider; |
17 } | 17 } |
18 | 18 |
19 // A specialization of ProfileOAuth2TokenService that will be returned by | 19 // A specialization of ProfileOAuth2TokenService that will be returned by |
20 // ProfileOAuth2TokenServiceFactory for OS_IOS when iOS authentication service | 20 // ProfileOAuth2TokenServiceFactory for OS_IOS when iOS authentication service |
21 // is used to lookup OAuth2 tokens. | 21 // is used to lookup OAuth2 tokens. |
22 // | 22 // |
23 // See |ProfileOAuth2TokenService| for usage details. | 23 // See |ProfileOAuth2TokenService| for usage details. |
24 // | 24 // |
25 // 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 |
26 // request from aother thread, please use OAuth2TokenServiceRequest. | 26 // request from aother thread, please use OAuth2TokenServiceRequest. |
27 class ProfileOAuth2TokenServiceIOS : public MutableProfileOAuth2TokenService { | 27 class ProfileOAuth2TokenServiceIOS : public ProfileOAuth2TokenService { |
28 public: | 28 public: |
29 ProfileOAuth2TokenServiceIOS(); | |
30 virtual ~ProfileOAuth2TokenServiceIOS(); | |
31 | |
32 // KeyedService | 29 // KeyedService |
33 virtual void Shutdown() OVERRIDE; | 30 virtual void Shutdown() OVERRIDE; |
34 | 31 |
35 // OAuth2TokenService | 32 // OAuth2TokenService |
36 virtual bool RefreshTokenIsAvailable( | 33 virtual bool RefreshTokenIsAvailable( |
37 const std::string& account_id) const OVERRIDE; | 34 const std::string& account_id) const OVERRIDE; |
38 | 35 |
39 virtual void InvalidateOAuth2Token(const std::string& account_id, | 36 virtual void InvalidateOAuth2Token(const std::string& account_id, |
40 const std::string& client_id, | 37 const std::string& client_id, |
41 const ScopeSet& scopes, | 38 const ScopeSet& scopes, |
42 const std::string& access_token) OVERRIDE; | 39 const std::string& access_token) OVERRIDE; |
43 | 40 |
44 // ProfileOAuth2TokenService | 41 // ProfileOAuth2TokenService |
45 virtual void Initialize(SigninClient* client) OVERRIDE; | 42 virtual void Initialize(SigninClient* client) OVERRIDE; |
46 virtual void LoadCredentials(const std::string& primary_account_id) OVERRIDE; | 43 virtual void LoadCredentials(const std::string& primary_account_id) OVERRIDE; |
47 virtual std::vector<std::string> GetAccounts() OVERRIDE; | 44 virtual std::vector<std::string> GetAccounts() OVERRIDE; |
48 virtual void UpdateAuthError(const std::string& account_id, | 45 virtual void UpdateAuthError(const std::string& account_id, |
49 const GoogleServiceAuthError& error) OVERRIDE; | 46 const GoogleServiceAuthError& error) OVERRIDE; |
50 | 47 |
51 // This method should not be called when using shared authentication. | 48 // This method should not be called when using shared authentication. |
52 virtual void UpdateCredentials(const std::string& account_id, | 49 virtual void UpdateCredentials(const std::string& account_id, |
53 const std::string& refresh_token) OVERRIDE; | 50 const std::string& refresh_token) OVERRIDE; |
54 | 51 |
55 // Removes all credentials from this instance of |ProfileOAuth2TokenService|, | 52 // Removes all credentials from this instance of |ProfileOAuth2TokenService|, |
56 // however, it does not revoke the identities from the device. | 53 // however, it does not revoke the identities from the device. |
57 // Subsequent calls to |RefreshTokenIsAvailable| will return |false|. | 54 // Subsequent calls to |RefreshTokenIsAvailable| will return |false|. |
58 virtual void RevokeAllCredentials() OVERRIDE; | 55 virtual void RevokeAllCredentials() OVERRIDE; |
59 | 56 |
60 // Returns the refresh token for |account_id| . | |
61 // Must only be called when |ShouldUseIOSSharedAuthentication| returns false. | |
62 std::string GetRefreshTokenWhenNotUsingSharedAuthentication( | |
63 const std::string& account_id); | |
64 | |
65 // Reloads accounts from the provider. Fires |OnRefreshTokenAvailable| for | 57 // Reloads accounts from the provider. Fires |OnRefreshTokenAvailable| for |
66 // each new account. Fires |OnRefreshTokenRevoked| for each account that was | 58 // each new account. Fires |OnRefreshTokenRevoked| for each account that was |
67 // removed. | 59 // removed. |
68 void ReloadCredentials(); | 60 void ReloadCredentials(); |
69 | 61 |
70 // Upgrades to using shared authentication token service. | 62 protected: |
71 // | 63 friend class ProfileOAuth2TokenServiceFactory; |
72 // Note: If this |ProfileOAuth2TokenServiceIOS| was using the legacy token | 64 friend class ProfileOAuth2TokenServiceIOSTest; |
73 // service, then this call also revokes all tokens from the parent | |
74 // |MutableProfileOAuth2TokenService|. | |
75 void StartUsingSharedAuthentication(); | |
76 | 65 |
77 // Sets |use_legacy_token_service_| to |use_legacy_token_service|. | 66 ProfileOAuth2TokenServiceIOS(); |
78 // | 67 virtual ~ProfileOAuth2TokenServiceIOS(); |
79 // Should only be called for testing. | |
80 void SetUseLegacyTokenServiceForTesting(bool use_legacy_token_service); | |
81 | 68 |
82 // Revokes the OAuth2 refresh tokens for all accounts from the parent | |
83 // |MutableProfileOAuth2TokenService|. | |
84 // | |
85 // Note: This method should only be called if the legacy pre-SSOAuth token | |
86 // service is used. | |
87 void ForceInvalidGrantResponses(); | |
88 | |
89 protected: | |
90 virtual OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( | 69 virtual OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( |
91 const std::string& account_id, | 70 const std::string& account_id, |
92 net::URLRequestContextGetter* getter, | 71 net::URLRequestContextGetter* getter, |
93 OAuth2AccessTokenConsumer* consumer) OVERRIDE; | 72 OAuth2AccessTokenConsumer* consumer) OVERRIDE; |
94 | 73 |
95 // Protected and virtual to be overriden by fake for testing. | 74 // Protected and virtual to be overriden by fake for testing. |
96 | 75 |
97 // Adds |account_id| to |accounts_| if it does not exist or udpates | 76 // Adds |account_id| to |accounts_| if it does not exist or udpates |
98 // the auth error state of |account_id| if it exists. Fires | 77 // the auth error state of |account_id| if it exists. Fires |
99 // |OnRefreshTokenAvailable| if the account info is updated. | 78 // |OnRefreshTokenAvailable| if the account info is updated. |
(...skipping 22 matching lines...) Expand all Loading... |
122 std::string account_id_; | 101 std::string account_id_; |
123 GoogleServiceAuthError last_auth_error_; | 102 GoogleServiceAuthError last_auth_error_; |
124 | 103 |
125 DISALLOW_COPY_AND_ASSIGN(AccountInfo); | 104 DISALLOW_COPY_AND_ASSIGN(AccountInfo); |
126 }; | 105 }; |
127 | 106 |
128 // Maps the |account_id| of accounts known to ProfileOAuth2TokenService | 107 // Maps the |account_id| of accounts known to ProfileOAuth2TokenService |
129 // to information about the account. | 108 // to information about the account. |
130 typedef std::map<std::string, linked_ptr<AccountInfo> > AccountInfoMap; | 109 typedef std::map<std::string, linked_ptr<AccountInfo> > AccountInfoMap; |
131 | 110 |
132 // MutableProfileOAuth2TokenService | |
133 virtual std::string GetRefreshToken( | |
134 const std::string& account_id) const OVERRIDE; | |
135 | |
136 // Returns the iOS provider; | 111 // Returns the iOS provider; |
137 ios::ProfileOAuth2TokenServiceIOSProvider* GetProvider(); | 112 ios::ProfileOAuth2TokenServiceIOSProvider* GetProvider(); |
138 | 113 |
139 // Info about the existing accounts. | 114 // Info about the existing accounts. |
140 AccountInfoMap accounts_; | 115 AccountInfoMap accounts_; |
141 | 116 |
142 // Calls to this class are expected to be made from the browser UI thread. | 117 // Calls to this class are expected to be made from the browser UI thread. |
143 // The purpose of this this checker is to warn us if the upstream usage of | 118 // The purpose of this checker is to detect access to |
144 // ProfileOAuth2TokenService ever gets changed to have it be used across | 119 // ProfileOAuth2TokenService from multiple threads in upstream code. |
145 // multiple threads. | |
146 base::ThreadChecker thread_checker_; | 120 base::ThreadChecker thread_checker_; |
147 | 121 |
148 // Whether to use the legacy pre-SSOAuth token service. | |
149 // | |
150 // |use_legacy_token_service_| is true iff the provider is not using shared | |
151 // authentication during |LoadCredentials|. Note that |LoadCredentials| is | |
152 // called exactly once after the PO2TS initialization iff the user is signed | |
153 // in. | |
154 // | |
155 // If |use_legacy_token_service_| is true, then this | |
156 // |ProfileOAuth2TokenServiceIOS| delegates all calls to the parent | |
157 // |MutableProfileOAuth2TokenService|. | |
158 bool use_legacy_token_service_; | |
159 | |
160 DISALLOW_COPY_AND_ASSIGN(ProfileOAuth2TokenServiceIOS); | 122 DISALLOW_COPY_AND_ASSIGN(ProfileOAuth2TokenServiceIOS); |
161 }; | 123 }; |
162 | 124 |
163 #endif // COMPONENTS_SIGNIN_IOS_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_H_ | 125 #endif // COMPONENTS_SIGNIN_IOS_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_H_ |
OLD | NEW |