| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH_LOGIN_MANAGER_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH_LOGIN_MANAGER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "net/url_request/url_request_context_getter.h" | |
| 12 | |
| 13 class Profile; | |
| 14 | |
| 15 namespace chromeos { | |
| 16 | |
| 17 // This class is responsible for restoring authenticated web sessions out of | |
| 18 // OAuth tokens or vice versa. | |
| 19 class OAuthLoginManager { | |
| 20 public: | |
| 21 enum SessionRestoreState { | |
| 22 // Session restore is not started. | |
| 23 SESSION_RESTORE_NOT_STARTED, | |
| 24 // Session restore is in progress. We are currently issuing calls to verify | |
| 25 // stored OAuth tokens and populate cookie jar with GAIA credentials. | |
| 26 SESSION_RESTORE_IN_PROGRESS, | |
| 27 // Session restore is completed. | |
| 28 SESSION_RESTORE_DONE, | |
| 29 }; | |
| 30 | |
| 31 // Session restore strategy. | |
| 32 enum SessionRestoreStrategy { | |
| 33 // Generate OAuth2 refresh token from authentication profile's cookie jar. | |
| 34 // Restore session from generated OAuth2 refresh token. | |
| 35 RESTORE_FROM_COOKIE_JAR, | |
| 36 // Restore session from saved OAuth2 refresh token from TokenServices. | |
| 37 RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN, | |
| 38 // Restore session from OAuth2 refresh token passed via command line. | |
| 39 RESTORE_FROM_PASSED_OAUTH2_REFRESH_TOKEN, | |
| 40 // Restore session from authentication code passed via command line. | |
| 41 RESTORE_FROM_AUTH_CODE, | |
| 42 }; | |
| 43 | |
| 44 class Delegate { | |
| 45 public: | |
| 46 virtual ~Delegate() {} | |
| 47 | |
| 48 // Raised when merge session is completed. | |
| 49 virtual void OnCompletedMergeSession() = 0; | |
| 50 | |
| 51 // Raised when cookie jar authentication is successfully completed. | |
| 52 virtual void OnCompletedAuthentication(Profile* user_profile) = 0; | |
| 53 | |
| 54 // Raised when stored OAuth(1|2) tokens are found and authentication | |
| 55 // profile is no longer needed. | |
| 56 virtual void OnFoundStoredTokens() = 0; | |
| 57 }; | |
| 58 | |
| 59 // Factory method. | |
| 60 static OAuthLoginManager* Create(OAuthLoginManager::Delegate* delegate); | |
| 61 | |
| 62 explicit OAuthLoginManager(OAuthLoginManager::Delegate* delegate); | |
| 63 virtual ~OAuthLoginManager(); | |
| 64 | |
| 65 // Restores and verifies OAuth tokens either following specified | |
| 66 // |restore_strategy|. For |restore_strategy| with values | |
| 67 // RESTORE_FROM_PASSED_OAUTH2_REFRESH_TOKEN or | |
| 68 // RESTORE_FROM_AUTH_CODE, respectively | |
| 69 // parameters |oauth2_refresh_token| or |auth_code| need to have non-empty | |
| 70 // value. | |
| 71 virtual void RestoreSession( | |
| 72 Profile* user_profile, | |
| 73 net::URLRequestContextGetter* auth_request_context, | |
| 74 SessionRestoreStrategy restore_strategy, | |
| 75 const std::string& oauth2_refresh_token, | |
| 76 const std::string& auth_code) = 0; | |
| 77 | |
| 78 // Continues session restore after transient network errors. | |
| 79 virtual void ContinueSessionRestore() = 0; | |
| 80 | |
| 81 // Stops all background authentication requests. | |
| 82 virtual void Stop() = 0; | |
| 83 | |
| 84 // Returns session restore state. | |
| 85 SessionRestoreState state() { return state_; } | |
| 86 | |
| 87 protected: | |
| 88 // Signals delegate that authentication is completed, kicks off token fetching | |
| 89 // process in TokenService. | |
| 90 void CompleteAuthentication(); | |
| 91 | |
| 92 OAuthLoginManager::Delegate* delegate_; | |
| 93 Profile* user_profile_; | |
| 94 scoped_refptr<net::URLRequestContextGetter> auth_request_context_; | |
| 95 SessionRestoreStrategy restore_strategy_; | |
| 96 SessionRestoreState state_; | |
| 97 | |
| 98 DISALLOW_COPY_AND_ASSIGN(OAuthLoginManager); | |
| 99 }; | |
| 100 | |
| 101 } // namespace chromeos | |
| 102 | |
| 103 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH_LOGIN_MANAGER_H_ | |
| OLD | NEW |