Home | History | Annotate | Download | only in login
      1 // Copyright (c) 2011 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_CRYPTOHOME_OP_H_
      6 #define CHROME_BROWSER_CHROMEOS_LOGIN_CRYPTOHOME_OP_H_
      7 #pragma once
      8 
      9 #include <string>
     10 
     11 #include "base/memory/ref_counted.h"
     12 #include "chrome/browser/chromeos/cros/cryptohome_library.h"
     13 
     14 namespace chromeos {
     15 class AuthAttemptState;
     16 class AuthAttemptStateResolver;
     17 
     18 class CryptohomeOp
     19     : public base::RefCountedThreadSafe<CryptohomeOp>,
     20       public CryptohomeLibrary::Delegate {
     21  public:
     22   static CryptohomeOp* CreateMountAttempt(AuthAttemptState* current_attempt,
     23                                           AuthAttemptStateResolver* callback,
     24                                           bool create_if_missing);
     25 
     26   static CryptohomeOp* CreateMountGuestAttempt(
     27       AuthAttemptState* current_attempt,
     28       AuthAttemptStateResolver* callback);
     29 
     30   static CryptohomeOp* CreateMigrateAttempt(AuthAttemptState* current_attempt,
     31                                             AuthAttemptStateResolver* callback,
     32                                             bool passing_old_hash,
     33                                             const std::string& hash);
     34 
     35   static CryptohomeOp* CreateRemoveAttempt(AuthAttemptState* current_attempt,
     36                                            AuthAttemptStateResolver* callback);
     37 
     38   static CryptohomeOp* CreateCheckKeyAttempt(
     39       AuthAttemptState* current_attempt,
     40       AuthAttemptStateResolver* callback);
     41 
     42   virtual bool Initiate() = 0;
     43 
     44   // Implementation of CryptohomeLibrary::Delegate.
     45   virtual void OnComplete(bool success, int return_code);
     46 
     47  protected:
     48   CryptohomeOp(AuthAttemptState* current_attempt,
     49                AuthAttemptStateResolver* callback);
     50 
     51   virtual ~CryptohomeOp();
     52 
     53   virtual void TriggerResolve(bool offline_outcome, int offline_code);
     54 
     55   AuthAttemptState* const attempt_;
     56   AuthAttemptStateResolver* const resolver_;
     57 
     58  private:
     59   friend class base::RefCountedThreadSafe<CryptohomeOp>;
     60   DISALLOW_COPY_AND_ASSIGN(CryptohomeOp);
     61 };
     62 
     63 }  // namespace chromeos
     64 
     65 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_CRYPTOHOME_OP_H_
     66