Home | History | Annotate | Download | only in auth
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROMEOS_LOGIN_AUTH_AUTH_ATTEMPT_STATE_H_
      6 #define CHROMEOS_LOGIN_AUTH_AUTH_ATTEMPT_STATE_H_
      7 
      8 #include <string>
      9 
     10 #include "chromeos/chromeos_export.h"
     11 #include "chromeos/login/auth/auth_status_consumer.h"
     12 #include "chromeos/login/auth/user_context.h"
     13 #include "components/user_manager/user_type.h"
     14 #include "google_apis/gaia/gaia_auth_consumer.h"
     15 #include "google_apis/gaia/gaia_auth_fetcher.h"
     16 #include "third_party/cros_system_api/dbus/service_constants.h"
     17 
     18 namespace chromeos {
     19 
     20 // Tracks the state associated with a single attempt to log in to chromium OS.
     21 // Enforces that methods are only called on the UI thread.
     22 class CHROMEOS_EXPORT AuthAttemptState {
     23  public:
     24   // Used to initialize for a login attempt.
     25   AuthAttemptState(const UserContext& user_context,
     26                    user_manager::UserType user_type,
     27                    bool unlock,
     28                    bool online_complete,
     29                    bool user_is_new);
     30 
     31   virtual ~AuthAttemptState();
     32 
     33   // Copy |user_context| and copy |outcome| into this object, so we can have
     34   // a copy we're sure to own, and can make available on the UI thread.
     35   // Must be called from the UI thread.
     36   void RecordOnlineLoginStatus(const AuthFailure& outcome);
     37 
     38   // Copy |username_hash| into this object, so we can have
     39   // a copy we're sure to own, and can make available on the UI thread.
     40   // Must be called from the UI thread.
     41   void RecordUsernameHash(const std::string& username_hash);
     42 
     43   // Marks that the username hash request attempt has failed.
     44   void RecordUsernameHashFailed();
     45 
     46   // Marks username hash as being requested so that flow will block till both
     47   // requests (Mount/GetUsernameHash) are completed.
     48   void UsernameHashRequested();
     49 
     50   // The next attempt will not allow HOSTED accounts to log in.
     51   void DisableHosted();
     52 
     53   // Copy |cryptohome_code| and |cryptohome_outcome| into this object,
     54   // so we can have a copy we're sure to own, and can make available
     55   // on the UI thread.  Must be called from the UI thread.
     56   void RecordCryptohomeStatus(bool cryptohome_outcome,
     57                               cryptohome::MountError cryptohome_code);
     58 
     59   // Blow away locally stored cryptohome login status.
     60   // Must be called from the UI thread.
     61   void ResetCryptohomeStatus();
     62 
     63   virtual bool online_complete();
     64   virtual const AuthFailure& online_outcome();
     65   virtual bool is_first_time_user();
     66   virtual GaiaAuthFetcher::HostedAccountsSetting hosted_policy();
     67 
     68   virtual bool cryptohome_complete();
     69   virtual bool cryptohome_outcome();
     70   virtual cryptohome::MountError cryptohome_code();
     71 
     72   virtual bool username_hash_obtained();
     73   virtual bool username_hash_valid();
     74 
     75   // Saved so we can retry client login, and also so we know for whom login
     76   // has succeeded, in the event of successful completion.
     77   UserContext user_context;
     78 
     79   // These fields are saved so we can retry client login.
     80   const std::string login_token;
     81   const std::string login_captcha;
     82 
     83   // The type of the user attempting to log in.
     84   const user_manager::UserType user_type;
     85 
     86   const bool unlock;  // True if authenticating to unlock the computer.
     87 
     88  protected:
     89   // Status of our online login attempt.
     90   bool online_complete_;
     91   AuthFailure online_outcome_;
     92 
     93   // Whether or not we're accepting HOSTED accounts during the current
     94   // online auth attempt.
     95   GaiaAuthFetcher::HostedAccountsSetting hosted_policy_;
     96   bool is_first_time_user_;
     97 
     98   // Status of our cryptohome op attempt. Can only have one in flight at a time.
     99   bool cryptohome_complete_;
    100   bool cryptohome_outcome_;
    101   cryptohome::MountError cryptohome_code_;
    102 
    103  private:
    104   // Status of the crypthome GetSanitizedUsername() async call.
    105   // This gets initialized as being completed and those callers
    106   // that would explicitly request username hash would have to reset this.
    107   bool username_hash_obtained_;
    108 
    109   // After the username hash request is completed, this marks whether
    110   // the request was successful.
    111   bool username_hash_valid_;
    112 
    113   DISALLOW_COPY_AND_ASSIGN(AuthAttemptState);
    114 };
    115 
    116 }  // namespace chromeos
    117 
    118 #endif  // CHROMEOS_LOGIN_AUTH_AUTH_ATTEMPT_STATE_H_
    119