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 CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_OAUTH2_LOGIN_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_OAUTH2_LOGIN_MANAGER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_OAUTH2_LOGIN_MANAGER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_OAUTH2_LOGIN_MANAGER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 // Session restore strategy. | 52 // Session restore strategy. |
53 enum SessionRestoreStrategy { | 53 enum SessionRestoreStrategy { |
54 // Generate OAuth2 refresh token from authentication profile's cookie jar. | 54 // Generate OAuth2 refresh token from authentication profile's cookie jar. |
55 // Restore session from generated OAuth2 refresh token. | 55 // Restore session from generated OAuth2 refresh token. |
56 RESTORE_FROM_COOKIE_JAR, | 56 RESTORE_FROM_COOKIE_JAR, |
57 // Restore session from saved OAuth2 refresh token from TokenServices. | 57 // Restore session from saved OAuth2 refresh token from TokenServices. |
58 RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN, | 58 RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN, |
59 // Restore session from OAuth2 refresh token passed via command line. | 59 // Restore session from OAuth2 refresh token passed via command line. |
60 RESTORE_FROM_PASSED_OAUTH2_REFRESH_TOKEN, | 60 RESTORE_FROM_PASSED_OAUTH2_REFRESH_TOKEN, |
61 // Restore session from authentication code passed via command line. | |
62 RESTORE_FROM_AUTH_CODE, | |
63 }; | 61 }; |
64 | 62 |
65 class Observer { | 63 class Observer { |
66 public: | 64 public: |
67 virtual ~Observer() {} | 65 virtual ~Observer() {} |
68 | 66 |
69 // Raised when merge session state changes. | 67 // Raised when merge session state changes. |
70 virtual void OnSessionRestoreStateChanged(Profile* user_profile, | 68 virtual void OnSessionRestoreStateChanged(Profile* user_profile, |
71 SessionRestoreState state) {} | 69 SessionRestoreState state) {} |
72 | 70 |
73 // Raised when a new OAuth2 refresh token is avaialble. | 71 // Raised when a new OAuth2 refresh token is avaialble. |
74 virtual void OnNewRefreshTokenAvaiable(Profile* user_profile) {} | 72 virtual void OnNewRefreshTokenAvaiable(Profile* user_profile) {} |
75 | 73 |
76 // Raised when session's GAIA credentials (SID+LSID) are available to | 74 // Raised when session's GAIA credentials (SID+LSID) are available to |
77 // other signed in services. | 75 // other signed in services. |
78 virtual void OnSessionAuthenticated(Profile* user_profile) {} | 76 virtual void OnSessionAuthenticated(Profile* user_profile) {} |
79 }; | 77 }; |
80 | 78 |
81 explicit OAuth2LoginManager(Profile* user_profile); | 79 explicit OAuth2LoginManager(Profile* user_profile); |
82 ~OAuth2LoginManager() override; | 80 ~OAuth2LoginManager() override; |
83 | 81 |
84 void AddObserver(OAuth2LoginManager::Observer* observer); | 82 void AddObserver(OAuth2LoginManager::Observer* observer); |
85 void RemoveObserver(OAuth2LoginManager::Observer* observer); | 83 void RemoveObserver(OAuth2LoginManager::Observer* observer); |
86 | 84 |
87 // Restores and verifies OAuth tokens either following specified | 85 // Restores and verifies OAuth tokens following specified |restore_strategy|. |
88 // |restore_strategy|. For |restore_strategy| with values | 86 // For |restore_strategy| RESTORE_FROM_PASSED_OAUTH2_REFRESH_TOKEN, parameter |
89 // RESTORE_FROM_PASSED_OAUTH2_REFRESH_TOKEN or | 87 // |oauth2_refresh_token| needs to have a non-empty value. |
90 // RESTORE_FROM_AUTH_CODE, respectively | 88 // For |restore_strategy| RESTORE_FROM_COOKIE_JAR |auth_request_context| must |
91 // parameters |oauth2_refresh_token| or |auth_code| need to have non-empty | 89 // be initialized. |
92 // value. | 90 void RestoreSession(net::URLRequestContextGetter* auth_request_context, |
93 // For |restore_strategy| with values RESTORE_FROM_COOKIE_JAR or | 91 SessionRestoreStrategy restore_strategy, |
94 // RESTORE_FROM_AUTH_CODE |auth_request_context| must be initialized. | 92 const std::string& oauth2_refresh_token, |
95 void RestoreSession( | 93 const std::string& oauth2_access_token); |
96 net::URLRequestContextGetter* auth_request_context, | |
97 SessionRestoreStrategy restore_strategy, | |
98 const std::string& oauth2_refresh_token, | |
99 const std::string& auth_code); | |
100 | 94 |
101 // Continues session restore after transient network errors. | 95 // Continues session restore after transient network errors. |
102 void ContinueSessionRestore(); | 96 void ContinueSessionRestore(); |
103 | 97 |
104 // Start resporting session from saved OAuth2 refresh token. | 98 // Start restoring session from saved OAuth2 refresh token. |
105 void RestoreSessionFromSavedTokens(); | 99 void RestoreSessionFromSavedTokens(); |
106 | 100 |
107 // Stops all background authentication requests. | 101 // Stops all background authentication requests. |
108 void Stop(); | 102 void Stop(); |
109 | 103 |
110 // Returns session restore state. | 104 // Returns session restore state. |
111 SessionRestoreState state() { return state_; } | 105 SessionRestoreState state() { return state_; } |
112 | 106 |
113 const base::Time& session_restore_start() { return session_restore_start_; } | 107 const base::Time& session_restore_start() { return session_restore_start_; } |
114 | 108 |
(...skipping 30 matching lines...) Expand all Loading... |
145 POST_MERGE_VERIFICATION_FAILED = 5, | 139 POST_MERGE_VERIFICATION_FAILED = 5, |
146 POST_MERGE_CONNECTION_FAILED = 6, | 140 POST_MERGE_CONNECTION_FAILED = 6, |
147 POST_MERGE_COUNT = 7, | 141 POST_MERGE_COUNT = 7, |
148 }; | 142 }; |
149 | 143 |
150 // KeyedService implementation. | 144 // KeyedService implementation. |
151 void Shutdown() override; | 145 void Shutdown() override; |
152 | 146 |
153 // gaia::GaiaOAuthClient::Delegate overrides. | 147 // gaia::GaiaOAuthClient::Delegate overrides. |
154 void OnRefreshTokenResponse(const std::string& access_token, | 148 void OnRefreshTokenResponse(const std::string& access_token, |
155 int expires_in_seconds) override; | 149 int expires_in_seconds) override; |
156 void OnGetUserInfoResponse( | 150 void OnGetUserInfoResponse( |
157 scoped_ptr<base::DictionaryValue> user_info) override; | 151 scoped_ptr<base::DictionaryValue> user_info) override; |
158 void OnOAuthError() override; | 152 void OnOAuthError() override; |
159 void OnNetworkError(int response_code) override; | 153 void OnNetworkError(int response_code) override; |
160 | 154 |
161 // OAuth2LoginVerifier::Delegate overrides. | 155 // OAuth2LoginVerifier::Delegate overrides. |
162 void OnSessionMergeSuccess() override; | 156 void OnSessionMergeSuccess() override; |
163 void OnSessionMergeFailure(bool connection_error) override; | 157 void OnSessionMergeFailure(bool connection_error) override; |
164 void OnListAccountsSuccess(const std::string& data) override; | 158 void OnListAccountsSuccess(const std::string& data) override; |
165 void OnListAccountsFailure(bool connection_error) override; | 159 void OnListAccountsFailure(bool connection_error) override; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 scoped_ptr<OAuth2LoginVerifier> login_verifier_; | 237 scoped_ptr<OAuth2LoginVerifier> login_verifier_; |
244 scoped_ptr<gaia::GaiaOAuthClient> account_info_fetcher_; | 238 scoped_ptr<gaia::GaiaOAuthClient> account_info_fetcher_; |
245 scoped_ptr<TokenHandleUtil> token_handle_util_; | 239 scoped_ptr<TokenHandleUtil> token_handle_util_; |
246 | 240 |
247 // OAuth2 refresh token. | 241 // OAuth2 refresh token. |
248 std::string refresh_token_; | 242 std::string refresh_token_; |
249 | 243 |
250 // OAuthLogin scoped access token. | 244 // OAuthLogin scoped access token. |
251 std::string oauthlogin_access_token_; | 245 std::string oauthlogin_access_token_; |
252 | 246 |
253 // Authorization code for fetching OAuth2 tokens. | |
254 std::string auth_code_; | |
255 | |
256 // Session restore start time. | 247 // Session restore start time. |
257 base::Time session_restore_start_; | 248 base::Time session_restore_start_; |
258 | 249 |
259 // List of observers to notify when token availability changes. | 250 // List of observers to notify when token availability changes. |
260 // Makes sure list is empty on destruction. | 251 // Makes sure list is empty on destruction. |
261 // TODO(zelidrag|gspencer): Figure out how to get rid of ProfileHelper so we | 252 // TODO(zelidrag|gspencer): Figure out how to get rid of ProfileHelper so we |
262 // can change the line below to ObserverList<Observer, true>. | 253 // can change the line below to ObserverList<Observer, true>. |
263 ObserverList<Observer, false> observer_list_; | 254 ObserverList<Observer, false> observer_list_; |
264 | 255 |
265 base::WeakPtrFactory<OAuth2LoginManager> weak_factory_; | 256 base::WeakPtrFactory<OAuth2LoginManager> weak_factory_; |
266 | 257 |
267 DISALLOW_COPY_AND_ASSIGN(OAuth2LoginManager); | 258 DISALLOW_COPY_AND_ASSIGN(OAuth2LoginManager); |
268 }; | 259 }; |
269 | 260 |
270 } // namespace chromeos | 261 } // namespace chromeos |
271 | 262 |
272 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_OAUTH2_LOGIN_MANAGER_H_ | 263 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_OAUTH2_LOGIN_MANAGER_H_ |
OLD | NEW |