| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 CHROME_BROWSER_CHROMEOS_LOGIN_TPM_PASSWORD_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_TPM_PASSWORD_FETCHER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_TPM_PASSWORD_FETCHER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_TPM_PASSWORD_FETCHER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "chromeos/dbus/dbus_method_call_status.h" |
| 12 | 13 |
| 13 namespace chromeos { | 14 namespace chromeos { |
| 14 | 15 |
| 15 // Interface which TpmPasswordFetcher uses to notify that password has been | 16 // Interface which TpmPasswordFetcher uses to notify that password has been |
| 16 // fetched. | 17 // fetched. |
| 17 class TpmPasswordFetcherDelegate { | 18 class TpmPasswordFetcherDelegate { |
| 18 public: | 19 public: |
| 19 virtual ~TpmPasswordFetcherDelegate() {} | 20 virtual ~TpmPasswordFetcherDelegate() {} |
| 20 virtual void OnPasswordFetched(const std::string& tpm_password) = 0; | 21 virtual void OnPasswordFetched(const std::string& tpm_password) = 0; |
| 21 }; | 22 }; |
| 22 | 23 |
| 23 // Class for fetching TPM password from the Cryptohome. | 24 // Class for fetching TPM password from the Cryptohome. |
| 24 class TpmPasswordFetcher { | 25 class TpmPasswordFetcher { |
| 25 public: | 26 public: |
| 26 // Creates fetcher with the given delegate to be notified every time fetching | 27 // Creates fetcher with the given delegate to be notified every time fetching |
| 27 // is done. | 28 // is done. |
| 28 explicit TpmPasswordFetcher(TpmPasswordFetcherDelegate* delegate); | 29 explicit TpmPasswordFetcher(TpmPasswordFetcherDelegate* delegate); |
| 29 ~TpmPasswordFetcher(); | 30 ~TpmPasswordFetcher(); |
| 30 | 31 |
| 31 // Fetches TPM password and stores the result. Also notifies |delegate_| with | 32 // Fetches TPM password and stores the result. Also notifies |delegate_| with |
| 32 // OnPasswordFetched() call. | 33 // OnPasswordFetched() call. |
| 33 void Fetch(); | 34 void Fetch(); |
| 34 | 35 |
| 35 private: | 36 private: |
| 37 // Used to implement Fetch(). |
| 38 void OnTpmIsReady(DBusMethodCallStatus call_status, bool tpm_is_ready); |
| 39 |
| 40 // Used to implement Fetch(). |
| 41 void OnTpmGetPassword(DBusMethodCallStatus call_status, |
| 42 const std::string& password); |
| 43 |
| 44 // Posts a task to call Fetch() later. |
| 45 void RescheduleFetch(); |
| 46 |
| 36 base::WeakPtrFactory<TpmPasswordFetcher> weak_factory_; | 47 base::WeakPtrFactory<TpmPasswordFetcher> weak_factory_; |
| 37 TpmPasswordFetcherDelegate* delegate_; | 48 TpmPasswordFetcherDelegate* delegate_; |
| 38 | 49 |
| 39 DISALLOW_COPY_AND_ASSIGN(TpmPasswordFetcher); | 50 DISALLOW_COPY_AND_ASSIGN(TpmPasswordFetcher); |
| 40 }; | 51 }; |
| 41 | 52 |
| 42 } // namespace chromeos | 53 } // namespace chromeos |
| 43 | 54 |
| 44 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_TPM_PASSWORD_FETCHER_H_ | 55 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_TPM_PASSWORD_FETCHER_H_ |
| OLD | NEW |