1 // Copyright (c) 2012 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_AUTHENTICATOR_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_AUTHENTICATOR_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "base/memory/ref_counted.h" 12 #include "chrome/browser/chromeos/login/login_status_consumer.h" 13 #include "google_apis/gaia/gaia_auth_consumer.h" 14 15 class Profile; 16 17 namespace chromeos { 18 19 struct UserContext; 20 21 // An interface for objects that will authenticate a Chromium OS user. 22 // When authentication successfully completes, will call 23 // consumer_->OnLoginSuccess() on the UI thread. 24 // On failure, will call consumer_->OnLoginFailure() on the UI thread. 25 // On password change detected, will call 26 // consumer_->OnPasswordChangeDetected() on the UI thread. 27 class Authenticator : public base::RefCountedThreadSafe<Authenticator> { 28 public: 29 explicit Authenticator(LoginStatusConsumer* consumer); 30 31 // Given externally authenticated username and password (part of 32 // |user_context|), this method attempts to complete authentication process. 33 virtual void CompleteLogin(Profile* profile, 34 const UserContext& user_context) = 0; 35 36 // Given a user credentials in |user_context|, 37 // this method attempts to authenticate to login. 38 // Must be called on the UI thread. 39 virtual void AuthenticateToLogin(Profile* profile, 40 const UserContext& user_context) = 0; 41 42 // Given a user credentials in |user_context|, this method attempts to 43 // authenticate to unlock the computer. 44 // Must be called on the UI thread. 45 virtual void AuthenticateToUnlock( 46 const UserContext& user_context) = 0; 47 48 // Initiates locally managed user login. 49 virtual void LoginAsLocallyManagedUser( 50 const UserContext& user_context) = 0; 51 52 // Initiates retail mode login. 53 virtual void LoginRetailMode() = 0; 54 55 // Initiates incognito ("browse without signing in") login. 56 virtual void LoginOffTheRecord() = 0; 57 58 // Initiates login into the public account identified by |username|. 59 virtual void LoginAsPublicAccount(const std::string& username) = 0; 60 61 // Completes retail mode login. 62 virtual void OnRetailModeLoginSuccess() = 0; 63 64 // Notifies caller that login was successful. 65 // |request_pending| is true if we still plan to call consumer_ with the 66 // results of more requests. 67 // Must be called on the UI thread. 68 virtual void OnLoginSuccess(bool request_pending) = 0; 69 70 // Must be called on the UI thread. 71 virtual void OnLoginFailure(const LoginFailure& error) = 0; 72 73 // Call these methods on the UI thread. 74 // If a password logs the user in online, but cannot be used to 75 // mount his cryptohome, we expect that a password change has 76 // occurred. 77 // Call this method to migrate the user's encrypted data 78 // forward to use his new password. |old_password| is the password 79 // his data was last encrypted with. 80 virtual void RecoverEncryptedData( 81 const std::string& old_password) = 0; 82 83 // Call this method to erase the user's encrypted data 84 // and create a new cryptohome. 85 virtual void ResyncEncryptedData() = 0; 86 87 // Profile (usually off the record ) that was used to perform the last 88 // authentication process. 89 Profile* authentication_profile() { return authentication_profile_; } 90 91 // Sets consumer explicitly. 92 void SetConsumer(LoginStatusConsumer* consumer); 93 94 protected: 95 virtual ~Authenticator(); 96 97 LoginStatusConsumer* consumer_; 98 Profile* authentication_profile_; 99 100 private: 101 friend class base::RefCountedThreadSafe<Authenticator>; 102 103 DISALLOW_COPY_AND_ASSIGN(Authenticator); 104 }; 105 106 } // namespace chromeos 107 108 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_AUTHENTICATOR_H_ 109