Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: chrome/browser/chromeos/login/tpm_password_fetcher.cc

Issue 10703162: chromeos: Remove CryptohomeLibrary::TpmGetPassword and TpmIsReady (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add cryptohome_web_ui_handler.cc/h Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 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 #include "chrome/browser/chromeos/login/tpm_password_fetcher.h" 5 #include "chrome/browser/chromeos/login/tpm_password_fetcher.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "chrome/browser/chromeos/cros/cros_library.h" 10 #include "chromeos/dbus/cryptohome_client.h"
11 #include "chrome/browser/chromeos/cros/cryptohome_library.h" 11 #include "chromeos/dbus/dbus_thread_manager.h"
12 12
13 namespace chromeos { 13 namespace chromeos {
14 14
15 namespace { 15 namespace {
16 16
17 // Interval between TPM password checks. 17 // Interval between TPM password checks.
18 const int kTpmCheckIntervalMs = 500; 18 const int kTpmCheckIntervalMs = 500;
19 19
20 } // namespace 20 } // namespace
21 21
22 TpmPasswordFetcher::TpmPasswordFetcher(TpmPasswordFetcherDelegate* delegate) 22 TpmPasswordFetcher::TpmPasswordFetcher(TpmPasswordFetcherDelegate* delegate)
23 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), 23 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
24 delegate_(delegate) { 24 delegate_(delegate) {
25 DCHECK(delegate_); 25 DCHECK(delegate_);
26 } 26 }
27 27
28 TpmPasswordFetcher::~TpmPasswordFetcher() { 28 TpmPasswordFetcher::~TpmPasswordFetcher() {
29 } 29 }
30 30
31 void TpmPasswordFetcher::Fetch() { 31 void TpmPasswordFetcher::Fetch() {
32 // Since this method is also called directly. 32 // Since this method is also called directly.
33 weak_factory_.InvalidateWeakPtrs(); 33 weak_factory_.InvalidateWeakPtrs();
34 34
35 std::string password; 35 DBusThreadManager::Get()->GetCryptohomeClient()->TpmIsReady(
36 base::Bind(&TpmPasswordFetcher::OnTpmIsReady,
37 weak_factory_.GetWeakPtr()));
38 }
36 39
37 chromeos::CryptohomeLibrary* cryptohome = 40 void TpmPasswordFetcher::OnTpmIsReady(DBusMethodCallStatus call_status,
38 chromeos::CrosLibrary::Get()->GetCryptohomeLibrary(); 41 bool tpm_is_ready) {
42 if (call_status == DBUS_METHOD_CALL_SUCCESS && tpm_is_ready) {
43 DBusThreadManager::Get()->GetCryptohomeClient()->TpmGetPassword(
44 base::Bind(&TpmPasswordFetcher::OnTpmGetPassword,
45 weak_factory_.GetWeakPtr()));
46 } else {
47 // Password hasn't been acquired, reschedule fetch.
48 RescheduleFetch();
49 }
50 }
39 51
40 if (cryptohome->TpmIsReady() && cryptohome->TpmGetPassword(&password)) { 52 void TpmPasswordFetcher::OnTpmGetPassword(DBusMethodCallStatus call_status,
53 const std::string& password) {
54 if (call_status == DBUS_METHOD_CALL_SUCCESS) {
41 if (password.empty()) { 55 if (password.empty()) {
42 // For a fresh OOBE flow TPM is uninitialized, 56 // For a fresh OOBE flow TPM is uninitialized,
43 // ownership process is started at the EULA screen, 57 // ownership process is started at the EULA screen,
44 // password is cleared after EULA is accepted. 58 // password is cleared after EULA is accepted.
45 LOG(ERROR) << "TPM returned an empty password."; 59 LOG(ERROR) << "TPM returned an empty password.";
46 } 60 }
47 delegate_->OnPasswordFetched(password); 61 delegate_->OnPasswordFetched(password);
48 } else { 62 } else {
49 // Password hasn't been acquired, reschedule fetch. 63 // Password hasn't been acquired, reschedule fetch.
50 MessageLoop::current()->PostDelayedTask( 64 RescheduleFetch();
51 FROM_HERE,
52 base::Bind(&TpmPasswordFetcher::Fetch, weak_factory_.GetWeakPtr()),
53 base::TimeDelta::FromMilliseconds(kTpmCheckIntervalMs));
54 } 65 }
55 } 66 }
56 67
68 void TpmPasswordFetcher::RescheduleFetch() {
69 MessageLoop::current()->PostDelayedTask(
70 FROM_HERE,
71 base::Bind(&TpmPasswordFetcher::Fetch, weak_factory_.GetWeakPtr()),
72 base::TimeDelta::FromMilliseconds(kTpmCheckIntervalMs));
73 }
74
57 } // namespace chromeos 75 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698