Chromium Code Reviews| Index: net/ssl/threaded_ssl_private_key.cc |
| diff --git a/net/ssl/threaded_ssl_private_key.cc b/net/ssl/threaded_ssl_private_key.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..040662ae8b526e418c46ce5325dc8652ed862314 |
| --- /dev/null |
| +++ b/net/ssl/threaded_ssl_private_key.cc |
| @@ -0,0 +1,69 @@ |
| +// Copyright 2015 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 "net/ssl/threaded_ssl_private_key.h" |
| + |
| +#include <string> |
| + |
| +#include "base/bind.h" |
| +#include "base/location.h" |
| +#include "base/task_runner.h" |
| +#include "base/thread_task_runner_handle.h" |
| + |
| +namespace net { |
| + |
| +namespace { |
| + |
| +void DoSign(const scoped_refptr<ThreadedSSLPrivateKey::Core>& core, |
| + SSLPrivateKey::Hash hash, |
| + const std::string& input, |
| + const SSLPrivateKey::SignCallback& callback, |
| + const scoped_refptr<base::TaskRunner>& task_runner) { |
| + std::vector<uint8_t> signature; |
| + Error error = core->SignDigest(hash, input, &signature); |
| + task_runner->PostTask(FROM_HERE, base::Bind(callback, error, signature)); |
| +} |
| + |
| +} // namespace |
| + |
| +ThreadedSSLPrivateKey::ThreadedSSLPrivateKey( |
| + const scoped_refptr<Core>& core, |
| + const scoped_refptr<base::TaskRunner>& task_runner) |
| + : core_(core), task_runner_(task_runner), weak_factory_(this) { |
| +} |
| + |
| +ThreadedSSLPrivateKey::~ThreadedSSLPrivateKey() { |
| +} |
| + |
| +SSLPrivateKey::Type ThreadedSSLPrivateKey::GetType() { |
| + return core_->GetType(); |
| +} |
| + |
| +bool ThreadedSSLPrivateKey::SupportsHash(SSLPrivateKey::Hash hash) { |
| + return core_->SupportsHash(hash); |
| +} |
| + |
| +size_t ThreadedSSLPrivateKey::GetMaxSignatureLength() { |
| + return core_->GetMaxSignatureLength(); |
| +} |
| + |
| +void ThreadedSSLPrivateKey::SignDigest( |
| + SSLPrivateKey::Hash hash, |
| + const base::StringPiece& input, |
| + const SSLPrivateKey::SignCallback& callback) { |
| + task_runner_->PostTask( |
| + FROM_HERE, base::Bind(&DoSign, core_, hash, input.as_string(), |
| + base::Bind(&ThreadedSSLPrivateKey::DoCallback, |
| + weak_factory_.GetWeakPtr(), callback), |
| + base::ThreadTaskRunnerHandle::Get())); |
|
Ryan Sleevi
2015/06/12 23:37:20
An alternative way to do this
namespace {
void D
davidben
2015/06/15 21:28:25
I don't believe it quite avoids the need for DoCal
|
| +} |
| + |
| +void ThreadedSSLPrivateKey::DoCallback( |
| + const SSLPrivateKey::SignCallback& callback, |
| + Error error, |
| + const std::vector<uint8_t>& signature) { |
| + callback.Run(error, signature); |
| +} |
| + |
| +} // namespace net |