Index: tpm_init.cc |
diff --git a/tpm_init.cc b/tpm_init.cc |
index ddd287a51a86c4f63bb25706042aa65d40141bb6..3178790fb89f4e8c0372ef8abed6d4c586eeccd2 100644 |
--- a/tpm_init.cc |
+++ b/tpm_init.cc |
@@ -7,6 +7,7 @@ |
#include "tpm_init.h" |
#include <base/logging.h> |
+#include <base/platform_thread.h> |
#include <base/time.h> |
#include "tpm.h" |
@@ -17,33 +18,47 @@ namespace tpm_init { |
// the TPM. |
class TpmInitTask : public PlatformThread::Delegate { |
public: |
- TpmInitTask(); |
- virtual ~TpmInitTask(); |
+ TpmInitTask() |
+ : default_tpm_(new tpm_init::Tpm()), |
+ tpm_(default_tpm_.get()), |
+ init_(NULL) { |
+ } |
+ |
+ virtual ~TpmInitTask() { |
+ } |
+ |
+ void Init(TpmInit* init) { |
+ init_ = init; |
+ tpm_->Init(); |
+ } |
- void Init(TpmInit::TpmInitCallback* notify_callback); |
+ virtual void ThreadMain() { |
+ if (init_) { |
+ init_->ThreadMain(); |
+ } |
+ } |
- virtual void ThreadMain(); |
+ void set_tpm(tpm_init::Tpm* tpm) { |
+ tpm_ = tpm; |
+ } |
- bool IsTpmReady(); |
- bool IsTpmEnabled(); |
- bool IsTpmOwned(); |
- bool IsTpmBeingOwned(); |
- bool GetTpmPassword(chromeos::Blob* password); |
- long GetInitializationMillis(); |
- bool GetRandomData(int length, chromeos::Blob* data); |
+ tpm_init::Tpm* get_tpm() { |
+ return tpm_; |
+ } |
private: |
scoped_ptr<tpm_init::Tpm> default_tpm_; |
tpm_init::Tpm* tpm_; |
- bool initialize_took_ownership_; |
- bool task_done_; |
- long initialization_time_; |
- TpmInit::TpmInitCallback* notify_callback_; |
+ TpmInit* init_; |
}; |
TpmInit::TpmInit() |
: tpm_init_task_(new TpmInitTask()), |
- notify_callback_(NULL) { |
+ notify_callback_(NULL), |
+ initialize_called_(false), |
+ task_done_(false), |
+ initialize_took_ownership_(false), |
+ initialization_time_(0) { |
} |
TpmInit::~TpmInit() { |
@@ -51,14 +66,15 @@ TpmInit::~TpmInit() { |
void TpmInit::Init(TpmInitCallback* notify_callback) { |
notify_callback_ = notify_callback; |
+ tpm_init_task_->Init(this); |
} |
bool TpmInit::GetRandomData(int length, chromeos::Blob* data) { |
- return tpm_init_task_->GetRandomData(length, data); |
+ return tpm_init_task_->get_tpm()->GetRandomData(length, data); |
} |
bool TpmInit::StartInitializeTpm() { |
- tpm_init_task_->Init(notify_callback_); |
+ initialize_called_ = true; |
if (!PlatformThread::CreateNonJoinable(0, tpm_init_task_.get())) { |
LOG(ERROR) << "Unable to create TPM initialization background thread."; |
return false; |
@@ -67,49 +83,56 @@ bool TpmInit::StartInitializeTpm() { |
} |
bool TpmInit::IsTpmReady() { |
- return tpm_init_task_->IsTpmReady(); |
+ // The TPM is not "ready" if the init call has not completed. It may be in |
+ // the middle of taking ownership. |
+ if (!task_done_) { |
+ return false; |
+ } |
+ // If initialize_took_ownership_ is true, then the TPM went through a full |
+ // succesful ownership cycle in InitializeTpm() |
+ if (initialize_took_ownership_) { |
+ return true; |
+ } |
+ // If we get here, then the call to InitializeTpm() is complete and it |
+ // returned false. That merely means that it did not successfully take |
+ // ownership, which is the common case after ownership is established on OOBE. |
+ // In that case, the TPM is ready if it is enabled and owned. |
+ return (tpm_init_task_->get_tpm()->IsEnabled() && |
+ tpm_init_task_->get_tpm()->IsOwned()); |
} |
bool TpmInit::IsTpmEnabled() { |
- return tpm_init_task_->IsTpmEnabled(); |
+ return tpm_init_task_->get_tpm()->IsEnabled(); |
} |
bool TpmInit::IsTpmOwned() { |
- return tpm_init_task_->IsTpmOwned(); |
+ return tpm_init_task_->get_tpm()->IsOwned(); |
} |
bool TpmInit::IsTpmBeingOwned() { |
- return tpm_init_task_->IsTpmBeingOwned(); |
+ return tpm_init_task_->get_tpm()->IsBeingOwned(); |
} |
-bool TpmInit::GetTpmPassword(chromeos::Blob* password) { |
- return tpm_init_task_->GetTpmPassword(password); |
-} |
- |
-long TpmInit::GetInitializationMillis() { |
- return tpm_init_task_->GetInitializationMillis(); |
+bool TpmInit::HasInitializeBeenCalled() { |
+ return initialize_called_; |
} |
-TpmInitTask::TpmInitTask() |
- : default_tpm_(new tpm_init::Tpm()), |
- tpm_(default_tpm_.get()), |
- initialize_took_ownership_(false), |
- task_done_(false), |
- initialization_time_(-1), |
- notify_callback_(NULL) { |
+bool TpmInit::GetTpmPassword(chromeos::Blob* password) { |
+ return tpm_init_task_->get_tpm()->GetOwnerPassword(password); |
} |
-TpmInitTask::~TpmInitTask() { |
+void TpmInit::ClearStoredTpmPassword() { |
+ tpm_init_task_->get_tpm()->ClearStoredOwnerPassword(); |
} |
-void TpmInitTask::Init(TpmInit::TpmInitCallback* notify_callback) { |
- notify_callback_ = notify_callback; |
- tpm_->Init(); |
+long TpmInit::GetInitializationMillis() { |
+ return initialization_time_; |
} |
-void TpmInitTask::ThreadMain() { |
+void TpmInit::ThreadMain() { |
base::TimeTicks start = base::TimeTicks::Now(); |
- bool initialize_result = tpm_->InitializeTpm(&initialize_took_ownership_); |
+ bool initialize_result = tpm_init_task_->get_tpm()->InitializeTpm( |
+ &initialize_took_ownership_); |
base::TimeDelta delta = (base::TimeTicks::Now() - start); |
initialization_time_ = delta.InMilliseconds(); |
if (initialize_took_ownership_) { |
@@ -122,46 +145,4 @@ void TpmInitTask::ThreadMain() { |
} |
} |
-bool TpmInitTask::IsTpmReady() { |
- // The TPM is not "ready" if the init call has not completed. It may be in |
- // the middle of taking ownership. |
- if (!task_done_) { |
- return false; |
- } |
- // If initialize_took_ownership_ is true, then the TPM went through a full |
- // succesful ownership cycle in InitializeTpm() |
- if (initialize_took_ownership_) { |
- return true; |
- } |
- // If we get here, then the call to InitializeTpm() is complete and it |
- // returned false. That merely means that it did not successfully take |
- // ownership, which is the common case after ownership is established on OOBE. |
- // In that case, the TPM is ready if it is enabled and owned. |
- return (tpm_->IsEnabled() && tpm_->IsOwned()); |
-} |
- |
-bool TpmInitTask::IsTpmEnabled() { |
- return tpm_->IsEnabled(); |
-} |
- |
-bool TpmInitTask::IsTpmOwned() { |
- return tpm_->IsOwned(); |
-} |
- |
-bool TpmInitTask::IsTpmBeingOwned() { |
- return tpm_->IsBeingOwned(); |
-} |
- |
-bool TpmInitTask::GetTpmPassword(chromeos::Blob* password) { |
- return tpm_->GetOwnerPassword(password); |
-} |
- |
-long TpmInitTask::GetInitializationMillis() { |
- return initialization_time_; |
-} |
- |
-bool TpmInitTask::GetRandomData(int length, chromeos::Blob* data) { |
- return tpm_->GetRandomData(length, data); |
-} |
- |
} // namespace tpm_init |