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

Unified Diff: chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api.cc

Issue 1685103003: Copy challenge*Key methods to enterprise.platformKeys. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed nits; now use ArrayBuffer Created 4 years, 10 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
Index: chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api.cc
diff --git a/chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api.cc b/chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api.cc
index 5dcaea9cf2643dc5e168a13a708e7f06c9ea9608..d21e35ebfb4f4e5deb54e05b86a4162c433db2f5 100644
--- a/chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api.cc
+++ b/chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api.cc
@@ -31,6 +31,14 @@ const char kErrorInternal[] = "Internal Error.";
const char kErrorInvalidX509Cert[] =
"Certificate is not a valid X.509 certificate.";
+std::vector<char> VectorFromString(const std::string& s) {
+ return std::vector<char>(s.begin(), s.end());
+}
+
+std::string StringFromVector(const std::vector<char>& v) {
+ return std::string(v.begin(), v.end());
+}
+
} // namespace
EnterprisePlatformKeysInternalGenerateKeyFunction::
@@ -236,4 +244,85 @@ void EnterprisePlatformKeysInternalGetTokensFunction::OnGotTokens(
Respond(ArgumentList(api_epki::GetTokens::Results::Create(token_ids)));
}
+EnterprisePlatformKeysChallengeMachineKeyFunction::
+ EnterprisePlatformKeysChallengeMachineKeyFunction()
+ : default_impl_(new EPKPChallengeMachineKey), impl_(default_impl_.get()) {}
+
+EnterprisePlatformKeysChallengeMachineKeyFunction::
+ EnterprisePlatformKeysChallengeMachineKeyFunction(
+ EPKPChallengeMachineKey* impl_for_testing)
+ : impl_(impl_for_testing) {}
+
+EnterprisePlatformKeysChallengeMachineKeyFunction::
+ ~EnterprisePlatformKeysChallengeMachineKeyFunction() = default;
+
+ExtensionFunction::ResponseAction
+EnterprisePlatformKeysChallengeMachineKeyFunction::Run() {
+ scoped_ptr<api_epk::ChallengeMachineKey::Params> params(
+ api_epk::ChallengeMachineKey::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params);
+ ChallengeKeyCallback callback = base::Bind(
+ &EnterprisePlatformKeysChallengeMachineKeyFunction::OnChallengedKey,
+ this);
+ // base::Unretained is safe on impl_ since its life-cycle matches |this| and
+ // |callback| holds a reference to |this|.
+ base::Closure task = base::Bind(
+ &EPKPChallengeMachineKey::Run, base::Unretained(impl_),
+ scoped_refptr<UIThreadExtensionFunction>(AsUIThreadExtensionFunction()),
+ callback, StringFromVector(params->challenge));
+ content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, task);
+ return RespondLater();
+}
+
+void EnterprisePlatformKeysChallengeMachineKeyFunction::OnChallengedKey(
+ bool success,
+ const std::string& data) {
+ if (success) {
+ Respond(ArgumentList(
+ api_epk::ChallengeMachineKey::Results::Create(VectorFromString(data))));
+ } else {
+ Respond(Error(data));
+ }
+}
+
+EnterprisePlatformKeysChallengeUserKeyFunction::
+ EnterprisePlatformKeysChallengeUserKeyFunction()
+ : default_impl_(new EPKPChallengeUserKey), impl_(default_impl_.get()) {}
+
+EnterprisePlatformKeysChallengeUserKeyFunction::
+ EnterprisePlatformKeysChallengeUserKeyFunction(
+ EPKPChallengeUserKey* impl_for_testing)
+ : impl_(impl_for_testing) {}
+
+EnterprisePlatformKeysChallengeUserKeyFunction::
+ ~EnterprisePlatformKeysChallengeUserKeyFunction() = default;
+
+ExtensionFunction::ResponseAction
+EnterprisePlatformKeysChallengeUserKeyFunction::Run() {
+ scoped_ptr<api_epk::ChallengeUserKey::Params> params(
+ api_epk::ChallengeUserKey::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params);
+ ChallengeKeyCallback callback = base::Bind(
+ &EnterprisePlatformKeysChallengeUserKeyFunction::OnChallengedKey, this);
+ // base::Unretained is safe on impl_ since its life-cycle matches |this| and
+ // |callback| holds a reference to |this|.
+ base::Closure task = base::Bind(
+ &EPKPChallengeUserKey::Run, base::Unretained(impl_),
+ scoped_refptr<UIThreadExtensionFunction>(AsUIThreadExtensionFunction()),
+ callback, StringFromVector(params->challenge), params->register_key);
+ content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, task);
+ return RespondLater();
+}
+
+void EnterprisePlatformKeysChallengeUserKeyFunction::OnChallengedKey(
+ bool success,
+ const std::string& data) {
+ if (success) {
+ Respond(ArgumentList(
+ api_epk::ChallengeUserKey::Results::Create(VectorFromString(data))));
+ } else {
+ Respond(Error(data));
+ }
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698