Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c779deabc3f905fb7836367912cccd5b8982be84 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api.cc |
| @@ -0,0 +1,164 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api.h" |
| + |
| +#include "chrome/browser/extensions/api/enterprise_platform_keys/token_method.h" |
| +#include "chrome/common/extensions/api/enterprise_platform_keys.h" |
| +#include "chrome/common/extensions/api/enterprise_platform_keys_internal.h" |
| + |
| +namespace { |
| +const char kErrorInvalidToken[] = "Token is invalid."; |
| +} |
| + |
| +namespace extensions { |
| + |
| +namespace api_epk = api::enterprise_platform_keys; |
| +namespace api_epki = api::enterprise_platform_keys_internal; |
| + |
| +const char kTokenIdUser[] = "user"; |
| + |
| +EnterprisePlatformKeysTokenMethodExtensionFunction:: |
| + EnterprisePlatformKeysTokenMethodExtensionFunction() { |
| +} |
| + |
| +EnterprisePlatformKeysTokenMethodExtensionFunction:: |
| + ~EnterprisePlatformKeysTokenMethodExtensionFunction() { |
| +} |
| + |
| +void EnterprisePlatformKeysTokenMethodExtensionFunction::OnError( |
| + const std::string& error_message) { |
| + Respond(Error(error_message)); |
| + Release(); |
| +} |
| + |
| +bool EnterprisePlatformKeysTokenMethodExtensionFunction::ValidateToken( |
| + const std::string& token_id) { |
| + // For now, the user token is the only valid one. |
| + if (token_id != kTokenIdUser) { |
| + SetError(kErrorInvalidToken); |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| +EnterprisePlatformKeysInternalGenerateKeyFunction:: |
| + EnterprisePlatformKeysInternalGenerateKeyFunction() { |
| +} |
| + |
| +EnterprisePlatformKeysInternalGenerateKeyFunction:: |
| + ~EnterprisePlatformKeysInternalGenerateKeyFunction() { |
| +} |
| + |
| +ExtensionFunction::ResponseAction |
| +EnterprisePlatformKeysInternalGenerateKeyFunction::Run() { |
| + scoped_ptr<api_epki::GenerateKey::Params> params( |
| + api_epki::GenerateKey::Params::Create(*args_)); |
| + EXTENSION_FUNCTION_VALIDATE_TYPESAFE(params && |
| + ValidateToken(params->token_id)); |
| + AddRef(); |
| + token_method_ = enterprise_platform_keys_details::CreateGenerateKey( |
| + params.Pass(), |
| + base::Bind( |
| + &EnterprisePlatformKeysInternalGenerateKeyFunction::OnGeneratedKey, |
| + base::Unretained(this)), |
| + base::Bind(&EnterprisePlatformKeysTokenMethodExtensionFunction::OnError, |
| + base::Unretained(this)), |
| + GetProfile()); |
| + token_method_->Run(); |
| + return RespondLater(); |
| +} |
| + |
| +void EnterprisePlatformKeysInternalGenerateKeyFunction::OnGeneratedKey( |
| + const std::string& public_key_der) { |
| + Respond(MultipleArguments( |
| + api_epki::GenerateKey::Results::Create(public_key_der).release())); |
| + Release(); |
| +} |
| + |
| +/* |
|
Ryan Sleevi
2014/05/08 20:52:04
Why is this commented out?
Note: #if 0 / #endif i
pneubeck (no reviews)
2014/05/14 15:01:49
the last patchset was intended to show a variation
|
| +EnterprisePlatformKeysInternalSignFunction:: |
| + ~EnterprisePlatformKeysInternalSignFunction() { |
| +} |
| + |
| +ExtensionFunction::ResponseAction |
| +EnterprisePlatformKeysInternalSignFunction::Run() { |
| + scoped_ptr<api_epki::Sign::Params> params( |
| + api_epki::Sign::Params::Create(*args_)); |
| + EXTENSION_FUNCTION_VALIDATE_TYPESAFE(params && |
| + ValidateToken(params->token_id)); |
| + AddRef(); |
| + token_method_ = |
| + enterprise_platform_keys_details::CreateSign(params.Pass(), this); |
| + token_method_->Run(); |
| + return RespondLater(); |
| +} |
| + |
| +EnterprisePlatformKeysGetCertificatesFunction:: |
| + ~EnterprisePlatformKeysGetCertificatesFunction() { |
| +} |
| + |
| +ExtensionFunction::ResponseAction |
| +EnterprisePlatformKeysGetCertificatesFunction::Run() { |
| + scoped_ptr<api_epk::GetCertificates::Params> params( |
| + api_epk::GetCertificates::Params::Create(*args_)); |
| + EXTENSION_FUNCTION_VALIDATE_TYPESAFE(params && |
| + ValidateToken(params->token_id)); |
| + AddRef(); |
| + token_method_ = enterprise_platform_keys_details::CreateGetCertificates( |
| + params.Pass(), this); |
| + token_method_->Run(); |
| + return RespondLater(); |
| +} |
| + |
| +EnterprisePlatformKeysImportCertificateFunction:: |
| + ~EnterprisePlatformKeysImportCertificateFunction() { |
| +} |
| + |
| +ExtensionFunction::ResponseAction |
| +EnterprisePlatformKeysImportCertificateFunction::Run() { |
| + scoped_ptr<api_epk::ImportCertificate::Params> params( |
| + api_epk::ImportCertificate::Params::Create(*args_)); |
| + EXTENSION_FUNCTION_VALIDATE_TYPESAFE(params && |
| + ValidateToken(params->token_id)); |
| + AddRef(); |
| + token_method_ = enterprise_platform_keys_details::CreateImportCertificate( |
| + params.Pass(), this); |
| + token_method_->Run(); |
| + return RespondLater(); |
| +} |
| + |
| +EnterprisePlatformKeysRemoveCertificateFunction:: |
| + ~EnterprisePlatformKeysRemoveCertificateFunction() { |
| +} |
| + |
| +ExtensionFunction::ResponseAction |
| +EnterprisePlatformKeysRemoveCertificateFunction::Run() { |
| + scoped_ptr<api_epk::RemoveCertificate::Params> params( |
| + api_epk::RemoveCertificate::Params::Create(*args_)); |
| + EXTENSION_FUNCTION_VALIDATE_TYPESAFE(params && |
| + ValidateToken(params->token_id)); |
| + AddRef(); |
| + token_method_ = enterprise_platform_keys_details::CreateRemoveCertificate( |
| + params.Pass(), this); |
| + token_method_->Run(); |
| + return RespondLater(); |
| +} |
| +*/ |
| + |
| +EnterprisePlatformKeysInternalGetTokensFunction:: |
| + ~EnterprisePlatformKeysInternalGetTokensFunction() { |
| +} |
| + |
| +ExtensionFunction::ResponseAction |
| +EnterprisePlatformKeysInternalGetTokensFunction::Run() { |
| + EXTENSION_FUNCTION_VALIDATE_TYPESAFE(args_->empty()); |
| + |
| + std::vector<std::string> token_ids; |
| + token_ids.push_back(kTokenIdUser); |
| + return RespondNow(MultipleArguments( |
| + api_epki::GetTokens::Results::Create(token_ids).release())); |
| +} |
| + |
| +} // namespace extensions |