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

Unified Diff: chrome/browser/chromeos/platform_keys/platform_keys_service.cc

Issue 868243004: Small clean up in PlatformKeysService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Dropped 'WithResult' Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/platform_keys/platform_keys_service.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/platform_keys/platform_keys_service.cc
diff --git a/chrome/browser/chromeos/platform_keys/platform_keys_service.cc b/chrome/browser/chromeos/platform_keys/platform_keys_service.cc
index 7ba138c69202d7817d7b3ea4e940fde0b9810338..b4bdd1cb6e1cda98099e76c5b045792e0eede5ee 100644
--- a/chrome/browser/chromeos/platform_keys/platform_keys_service.cc
+++ b/chrome/browser/chromeos/platform_keys/platform_keys_service.cc
@@ -17,7 +17,6 @@ namespace chromeos {
namespace {
-const char kErrorInternal[] = "Internal Error.";
const char kErrorKeyNotAllowedForSigning[] =
"This key is not allowed for signing. Either it was used for signing "
"before or it was not correctly generated.";
@@ -30,16 +29,10 @@ scoped_ptr<base::StringValue> GetPublicKeyValue(
return make_scoped_ptr(new base::StringValue(public_key_spki_der_b64));
}
-// Wraps |callback| into a void(bool) callback which forwards
-// |public_key_spki_der| if |true| is passed to it.
-void WrapGenerateKeyCallback(
+void RunGenerateKeyCallback(
const PlatformKeysService::GenerateKeyCallback& callback,
- const std::string& public_key_spki_der,
- bool success) {
- if (success)
- callback.Run(public_key_spki_der, std::string() /* no error */);
- else
- callback.Run(std::string() /* no public key */, kErrorInternal);
+ const std::string& public_key_spki_der) {
+ callback.Run(public_key_spki_der, std::string() /* no error */);
}
// Callback used by |PlatformKeysService::Sign|.
@@ -118,7 +111,7 @@ void PlatformKeysService::Sign(const std::string& token_id,
void PlatformKeysService::RegisterPublicKey(
const std::string& extension_id,
const std::string& public_key_spki_der,
- const base::Callback<void(bool)>& callback) {
+ const base::Closure& callback) {
GetPlatformKeysOfExtension(
extension_id,
base::Bind(&PlatformKeysService::RegisterPublicKeyGotPlatformKeys,
@@ -144,12 +137,16 @@ void PlatformKeysService::GetPlatformKeysOfExtension(
const std::string& extension_id,
const GetPlatformKeysCallback& callback) {
state_store_->GetExtensionValue(
- extension_id,
- kStateStorePlatformKeys,
+ extension_id, kStateStorePlatformKeys,
base::Bind(&PlatformKeysService::GotPlatformKeysOfExtension,
- weak_factory_.GetWeakPtr(),
- extension_id,
- callback));
+ weak_factory_.GetWeakPtr(), extension_id, callback));
+}
+
+void PlatformKeysService::SetPlatformKeysOfExtension(
+ const std::string& extension_id,
+ scoped_ptr<base::ListValue> platform_keys) {
+ state_store_->SetExtensionValue(extension_id, kStateStorePlatformKeys,
+ platform_keys.Pass());
}
void PlatformKeysService::GenerateRSAKeyCallback(
@@ -161,22 +158,16 @@ void PlatformKeysService::GenerateRSAKeyCallback(
callback.Run(std::string() /* no public key */, error_message);
return;
}
- base::Callback<void(bool)> wrapped_callback(
- base::Bind(&WrapGenerateKeyCallback, callback, public_key_spki_der));
+ base::Closure wrapped_callback(
+ base::Bind(&RunGenerateKeyCallback, callback, public_key_spki_der));
RegisterPublicKey(extension_id, public_key_spki_der, wrapped_callback);
}
void PlatformKeysService::RegisterPublicKeyGotPlatformKeys(
const std::string& extension_id,
const std::string& public_key_spki_der,
- const base::Callback<void(bool)>& callback,
+ const base::Closure& callback,
scoped_ptr<base::ListValue> platform_keys) {
- if (!platform_keys) {
- LOG(ERROR) << "Error while reading the platform keys.";
- callback.Run(false);
- return;
- }
-
scoped_ptr<base::StringValue> key_value(
GetPublicKeyValue(public_key_spki_der));
@@ -184,10 +175,8 @@ void PlatformKeysService::RegisterPublicKeyGotPlatformKeys(
<< "Keys are assumed to be generated and not to be registered multiple "
"times.";
platform_keys->Append(key_value.release());
-
- state_store_->SetExtensionValue(
- extension_id, kStateStorePlatformKeys, platform_keys.Pass());
- callback.Run(true);
+ SetPlatformKeysOfExtension(extension_id, platform_keys.Pass());
+ callback.Run();
}
void PlatformKeysService::InvalidateKey(
@@ -205,8 +194,7 @@ void PlatformKeysService::InvalidateKey(
return;
}
- state_store_->SetExtensionValue(
- extension_id, kStateStorePlatformKeys, platform_keys.Pass());
+ SetPlatformKeysOfExtension(extension_id, platform_keys.Pass());
callback.Run(true);
}
@@ -220,8 +208,11 @@ void PlatformKeysService::GotPlatformKeysOfExtension(
base::ListValue* keys = NULL;
if (!value->GetAsList(&keys)) {
LOG(ERROR) << "Found a value of wrong type.";
- value.reset();
+
+ keys = new base::ListValue;
+ value.reset(keys);
}
+
ignore_result(value.release());
callback.Run(make_scoped_ptr(keys));
}
« no previous file with comments | « chrome/browser/chromeos/platform_keys/platform_keys_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698