| Index: chrome/browser/ui/webui/about_ui.cc
|
| diff --git a/chrome/browser/ui/webui/about_ui.cc b/chrome/browser/ui/webui/about_ui.cc
|
| index e441804ad160ba0b4dee194399ab414e4394c489..553b2041ee971240581ccdc587fbc1bc580db7f7 100644
|
| --- a/chrome/browser/ui/webui/about_ui.cc
|
| +++ b/chrome/browser/ui/webui/about_ui.cc
|
| @@ -519,58 +519,121 @@ std::string AddStringRow(const std::string& name, const std::string& value) {
|
| return WrapWithTR(row);
|
| }
|
|
|
| -void FinishCryptohomeDataRequestInternal(
|
| - scoped_refptr<AboutUIHTMLSource> source,
|
| - int refresh,
|
| - int request_id,
|
| - chromeos::DBusMethodCallStatus call_status,
|
| - bool is_tpm_token_ready) {
|
| - if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS)
|
| - is_tpm_token_ready = false;
|
| -
|
| - chromeos::CryptohomeLibrary* cryptohome =
|
| - chromeos::CrosLibrary::Get()->GetCryptohomeLibrary();
|
| - std::string output;
|
| - AppendHeader(&output, refresh, "About Cryptohome");
|
| - AppendBody(&output);
|
| - AppendRefresh(&output, refresh, "cryptohome");
|
| +class CryptohomeDataRequest : public base::RefCounted<CryptohomeDataRequest> {
|
| + public:
|
| + CryptohomeDataRequest(scoped_refptr<AboutUIHTMLSource> source,
|
| + const std::string& query,
|
| + int request_id)
|
| + : source_(source),
|
| + query_(query),
|
| + request_id_(request_id),
|
| + num_pending_values_(0),
|
| + is_mounted_(false),
|
| + tpm_is_ready_(false),
|
| + tpm_is_enabled_(false),
|
| + tpm_is_owned_(false),
|
| + tpm_is_being_owned_(false),
|
| + is_tpm_token_ready_(false) {
|
| + }
|
|
|
| - output.append("<h3>CryptohomeLibrary:</h3>");
|
| - output.append("<table>");
|
| - output.append(AddBoolRow("IsMounted", cryptohome->IsMounted()));
|
| - output.append(AddBoolRow("TpmIsReady", cryptohome->TpmIsReady()));
|
| - output.append(AddBoolRow("TpmIsEnabled", cryptohome->TpmIsEnabled()));
|
| - output.append(AddBoolRow("TpmIsOwned", cryptohome->TpmIsOwned()));
|
| - output.append(AddBoolRow("TpmIsBeingOwned", cryptohome->TpmIsBeingOwned()));
|
| - output.append(AddBoolRow("Pkcs11IsTpmTokenReady", is_tpm_token_ready));
|
| - output.append("</table>");
|
| + // Starts asynchronous value fetching to finish data request.
|
| + void Start() {
|
| + // Request bool values asynchronously.
|
| + RequestBoolProperty(&chromeos::CryptohomeClient::TpmIsReady,
|
| + &tpm_is_ready_);
|
| + RequestBoolProperty(&chromeos::CryptohomeClient::Pkcs11IsTpmTokenReady,
|
| + &is_tpm_token_ready_);
|
| +
|
| + // TODO(hashimoto): Get these values asynchronously. crbug.com/126674
|
| + chromeos::CryptohomeLibrary* cryptohome_library =
|
| + chromeos::CrosLibrary::Get()->GetCryptohomeLibrary();
|
| + is_mounted_ = cryptohome_library->IsMounted();
|
| + tpm_is_enabled_ = cryptohome_library->TpmIsEnabled();
|
| + tpm_is_owned_ = cryptohome_library->TpmIsOwned();
|
| + tpm_is_being_owned_ = cryptohome_library->TpmIsBeingOwned();
|
| + }
|
|
|
| - output.append("<h3>crypto:</h3>");
|
| - output.append("<table>");
|
| - output.append(AddBoolRow("IsTPMTokenReady", crypto::IsTPMTokenReady()));
|
| - std::string token_name, user_pin;
|
| - if (crypto::IsTPMTokenReady())
|
| - crypto::GetTPMTokenInfo(&token_name, &user_pin);
|
| - output.append(AddStringRow("token_name", token_name));
|
| - output.append(AddStringRow("user_pin", std::string(user_pin.length(), '*')));
|
| - output.append("</table>");
|
| - AppendFooter(&output);
|
| + private:
|
| + // Member function pointer to CryptohomeClient's bool value getter.
|
| + typedef void (chromeos::CryptohomeClient::*CryptohomeBoolGetterMethod)(
|
| + const chromeos::CryptohomeClient::BoolMethodCallback&);
|
| +
|
| + ~CryptohomeDataRequest() {}
|
| +
|
| + // Requests Cryptohome's bool property. OnBoolValueReceived will be called.
|
| + void RequestBoolProperty(CryptohomeBoolGetterMethod getter,
|
| + bool* destination) {
|
| + ++num_pending_values_;
|
| + (chromeos::DBusThreadManager::Get()->GetCryptohomeClient()->*getter)(
|
| + base::Bind(&CryptohomeDataRequest::OnBoolValueReceived,
|
| + this,
|
| + destination));
|
| + }
|
|
|
| - source->FinishDataRequest(output, request_id);
|
| -}
|
| + // Called when a bool property is received. This method finishes data request
|
| + // when there is no pending values to be received.
|
| + void OnBoolValueReceived(bool* destination,
|
| + chromeos::DBusMethodCallStatus call_status,
|
| + bool value) {
|
| + if (call_status == chromeos::DBUS_METHOD_CALL_SUCCESS)
|
| + *destination = value;
|
| + if (--num_pending_values_ == 0)
|
| + Finish();
|
| + }
|
|
|
| -void FinishCryptohomeDataRequest(scoped_refptr<AboutUIHTMLSource> source,
|
| - const std::string& query,
|
| - int request_id) {
|
| - int refresh;
|
| - base::StringToInt(query, &refresh);
|
| + // Finishes data request.
|
| + void Finish() {
|
| + int refresh = 0;
|
| + base::StringToInt(query_, &refresh);
|
| +
|
| + std::string output;
|
| + AppendHeader(&output, refresh, "About Cryptohome");
|
| + AppendBody(&output);
|
| + AppendRefresh(&output, refresh, "cryptohome");
|
| +
|
| + output.append("<h3>CryptohomeLibrary:</h3>");
|
| + output.append("<table>");
|
| + output.append(AddBoolRow("IsMounted", is_mounted_));
|
| + output.append(AddBoolRow("TpmIsReady", tpm_is_ready_));
|
| + output.append(AddBoolRow("TpmIsEnabled", tpm_is_enabled_));
|
| + output.append(AddBoolRow("TpmIsOwned", tpm_is_owned_));
|
| + output.append(AddBoolRow("TpmIsBeingOwned", tpm_is_being_owned_));
|
| + output.append(AddBoolRow("Pkcs11IsTpmTokenReady", is_tpm_token_ready_));
|
| + output.append("</table>");
|
| +
|
| + output.append("<h3>crypto:</h3>");
|
| + output.append("<table>");
|
| + output.append(AddBoolRow("IsTPMTokenReady", crypto::IsTPMTokenReady()));
|
| + std::string token_name, user_pin;
|
| + if (crypto::IsTPMTokenReady())
|
| + crypto::GetTPMTokenInfo(&token_name, &user_pin);
|
| + output.append(AddStringRow("token_name", token_name));
|
| + output.append(
|
| + AddStringRow("user_pin", std::string(user_pin.length(), '*')));
|
| + output.append("</table>");
|
| + AppendFooter(&output);
|
|
|
| - chromeos::DBusThreadManager::Get()->GetCryptohomeClient()->
|
| - Pkcs11IsTpmTokenReady(base::Bind(&FinishCryptohomeDataRequestInternal,
|
| - source,
|
| - refresh,
|
| - request_id));
|
| -}
|
| + source_->FinishDataRequest(output, request_id_);
|
| + }
|
| +
|
| + // Data request parameters.
|
| + scoped_refptr<AboutUIHTMLSource> source_;
|
| + std::string query_;
|
| + int request_id_;
|
| +
|
| + // Number of pending values to be received.
|
| + int num_pending_values_;
|
| +
|
| + // Bool values to be appended to the output.
|
| + bool is_mounted_;
|
| + bool tpm_is_ready_;
|
| + bool tpm_is_enabled_;
|
| + bool tpm_is_owned_;
|
| + bool tpm_is_being_owned_;
|
| + bool is_tpm_token_ready_;
|
| +
|
| + friend class base::RefCounted<CryptohomeDataRequest>;
|
| +};
|
|
|
| std::string AboutDiscardsRun() {
|
| std::string output;
|
| @@ -1364,7 +1427,9 @@ void AboutUIHTMLSource::StartDataRequest(const std::string& path,
|
| idr, ui::SCALE_FACTOR_NONE).as_string();
|
| #if defined(OS_CHROMEOS)
|
| } else if (host == chrome::kChromeUICryptohomeHost) {
|
| - FinishCryptohomeDataRequest(this, path, request_id);
|
| + scoped_refptr<CryptohomeDataRequest> request(
|
| + new CryptohomeDataRequest(this, path, request_id));
|
| + request->Start();
|
| return;
|
| } else if (host == chrome::kChromeUIDiscardsHost) {
|
| response = AboutDiscards(path);
|
|
|