| OLD | NEW | 
|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CRYPTO_NSS_CRYPTO_MODULE_DELEGATE_H_ | 5 #ifndef CRYPTO_NSS_CRYPTO_MODULE_DELEGATE_H_ | 
| 6 #define CRYPTO_NSS_CRYPTO_MODULE_DELEGATE_H_ | 6 #define CRYPTO_NSS_CRYPTO_MODULE_DELEGATE_H_ | 
| 7 | 7 | 
| 8 #include <string> | 8 #include <string> | 
| 9 | 9 | 
|  | 10 #include "base/memory/ref_counted.h" | 
|  | 11 | 
| 10 namespace crypto { | 12 namespace crypto { | 
| 11 | 13 | 
| 12 // PK11_SetPasswordFunc is a global setting.  An implementation of | 14 // PK11_SetPasswordFunc is a global setting.  An implementation of | 
| 13 // CryptoModuleBlockingPasswordDelegate should be passed using wincx() as the | 15 // CryptoModuleBlockingPasswordDelegate should be passed using wincx() as the | 
| 14 // user data argument (|wincx|) to relevant NSS functions, which the global | 16 // user data argument (|wincx|) to relevant NSS functions, which the global | 
| 15 // password handler will call to do the actual work. This delegate should only | 17 // password handler will call to do the actual work. This delegate should only | 
| 16 // be used in NSS calls on worker threads due to the blocking nature. | 18 // be used in NSS calls on worker threads due to the blocking nature. | 
| 17 class CryptoModuleBlockingPasswordDelegate { | 19 class CryptoModuleBlockingPasswordDelegate | 
|  | 20     : public base::RefCountedThreadSafe<CryptoModuleBlockingPasswordDelegate> { | 
| 18  public: | 21  public: | 
| 19   virtual ~CryptoModuleBlockingPasswordDelegate() {} |  | 
| 20 | 22 | 
| 21   // Return a value suitable for passing to the |wincx| argument of relevant NSS | 23   // Return a value suitable for passing to the |wincx| argument of relevant NSS | 
| 22   // functions. This should be used instead of passing the object pointer | 24   // functions. This should be used instead of passing the object pointer | 
| 23   // directly to avoid accidentally casting a pointer to a subclass to void* and | 25   // directly to avoid accidentally casting a pointer to a subclass to void* and | 
| 24   // then casting back to a pointer of the base class | 26   // then casting back to a pointer of the base class | 
| 25   void* wincx() { return this; } | 27   void* wincx() { return this; } | 
| 26 | 28 | 
| 27   // Requests a password to unlock |slot_name|. The interface is synchronous | 29   // Requests a password to unlock |slot_name|. The interface is synchronous | 
| 28   // because NSS cannot issue an asynchronous request. |retry| is true if this | 30   // because NSS cannot issue an asynchronous request. |retry| is true if this | 
| 29   // is a request for the retry and we previously returned the wrong password. | 31   // is a request for the retry and we previously returned the wrong password. | 
| 30   // The implementation should set |*cancelled| to true if the user cancelled | 32   // The implementation should set |*cancelled| to true if the user cancelled | 
| 31   // instead of entering a password, otherwise it should return the password the | 33   // instead of entering a password, otherwise it should return the password the | 
| 32   // user entered. | 34   // user entered. | 
| 33   virtual std::string RequestPassword(const std::string& slot_name, bool retry, | 35   virtual std::string RequestPassword(const std::string& slot_name, bool retry, | 
| 34                                       bool* cancelled) = 0; | 36                                       bool* cancelled) = 0; | 
|  | 37 | 
|  | 38  protected: | 
|  | 39   friend class base::RefCountedThreadSafe<CryptoModuleBlockingPasswordDelegate>; | 
|  | 40 | 
|  | 41   virtual ~CryptoModuleBlockingPasswordDelegate() {} | 
| 35 }; | 42 }; | 
| 36 | 43 | 
| 37 }  // namespace crypto | 44 }  // namespace crypto | 
| 38 | 45 | 
| 39 #endif  // CRYPTO_NSS_CRYPTO_MODULE_DELEGATE_H_ | 46 #endif  // CRYPTO_NSS_CRYPTO_MODULE_DELEGATE_H_ | 
| OLD | NEW | 
|---|