Chromium Code Reviews| Index: net/ssl/threaded_ssl_private_key.h |
| diff --git a/net/ssl/threaded_ssl_private_key.h b/net/ssl/threaded_ssl_private_key.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ccce40607820d95161f2dcdb650e569fea661e8f |
| --- /dev/null |
| +++ b/net/ssl/threaded_ssl_private_key.h |
| @@ -0,0 +1,78 @@ |
| +// 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. |
| + |
| +#ifndef NET_SSL_THREADED_SSL_PRIVATE_KEY_H_ |
| +#define NET_SSL_THREADED_SSL_PRIVATE_KEY_H_ |
| + |
| +#include <stdint.h> |
| + |
| +#include <vector> |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/strings/string_piece.h" |
| +#include "net/ssl/ssl_private_key.h" |
| + |
| +namespace base { |
| +class TaskRunner; |
| +} |
| + |
| +namespace net { |
| + |
| +// An SSLPrivateKey implementation which offloads key operations to a background |
| +// thread. |
| +class ThreadedSSLPrivateKey : public SSLPrivateKey { |
| + public: |
| + // Interface for consumers to implement to perform the actual signing |
| + // operation. All methods must be callable on any thread. |
| + class Core : public base::RefCountedThreadSafe<Core> { |
|
Ryan Sleevi
2015/06/12 23:37:20
The naming of Core is a little weird here. Aren't
davidben
2015/06/15 21:28:25
Done.
|
| + public: |
| + Core() {} |
| + |
| + virtual Type GetType() = 0; |
| + virtual bool SupportsHash(Hash hash) = 0; |
| + virtual size_t GetMaxSignatureLength() = 0; |
| + virtual Error SignDigest(Hash hash, |
| + const base::StringPiece& input, |
| + std::vector<uint8_t>* signature) = 0; |
| + |
| + protected: |
| + virtual ~Core() {} |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<Core>; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(Core); |
| + }; |
| + |
| + ThreadedSSLPrivateKey(const scoped_refptr<Core>& core, |
| + const scoped_refptr<base::TaskRunner>& task_runner); |
| + ~ThreadedSSLPrivateKey() override; |
| + |
| + // SSLPrivateKey implementation. |
| + Type GetType() override; |
| + bool SupportsHash(Hash hash) override; |
| + size_t GetMaxSignatureLength() override; |
| + void SignDigest(Hash hash, |
| + const base::StringPiece& input, |
| + const SignCallback& callback) override; |
| + |
| + private: |
| + // A wrapper over SignCallback to ensure the callback isn't called if the key |
| + // is destroyed. |
| + void DoCallback(const SignCallback& callback, |
| + Error error, |
| + const std::vector<uint8_t>& signature); |
|
Ryan Sleevi
2015/06/12 23:37:20
There's no need to make this a private class membe
davidben
2015/06/15 21:28:25
Now it needs to be. If we split up Delegate and Co
|
| + |
| + scoped_refptr<Core> core_; |
| + scoped_refptr<base::TaskRunner> task_runner_; |
| + base::WeakPtrFactory<ThreadedSSLPrivateKey> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ThreadedSSLPrivateKey); |
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_SSL_THREADED_SSL_PRIVATE_KEY_H_ |