| Index: net/cert/internal/trust_store_test_helpers.cc
|
| diff --git a/net/cert/internal/trust_store_test_helpers.cc b/net/cert/internal/trust_store_test_helpers.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..df4bd09f1ece9f17347de41c1e1536389442dd85
|
| --- /dev/null
|
| +++ b/net/cert/internal/trust_store_test_helpers.cc
|
| @@ -0,0 +1,88 @@
|
| +// Copyright 2016 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/cert/internal/trust_store_test_helpers.h"
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/callback_helpers.h"
|
| +#include "base/location.h"
|
| +#include "base/memory/weak_ptr.h"
|
| +#include "base/threading/thread_task_runner_handle.h"
|
| +
|
| +namespace net {
|
| +
|
| +namespace {
|
| +
|
| +class StaticAsyncRequest : public TrustStore::Request {
|
| + public:
|
| + StaticAsyncRequest(const TrustStore::TrustCallback& callback)
|
| + : callback_(callback), weak_ptr_factory_(this) {}
|
| + ~StaticAsyncRequest() override = default;
|
| +
|
| + void PostTrustCallback(bool trusted) {
|
| + base::ThreadTaskRunnerHandle::Get()->PostTask(
|
| + FROM_HERE, base::Bind(&StaticAsyncRequest::DoTrustCallback,
|
| + weak_ptr_factory_.GetWeakPtr(), trusted));
|
| + }
|
| +
|
| + private:
|
| + void DoTrustCallback(bool trusted) {
|
| + base::ResetAndReturn(&callback_).Run(trusted);
|
| + // |this| may be deleted here.
|
| + }
|
| +
|
| + TrustStore::TrustCallback callback_;
|
| + base::WeakPtrFactory<StaticAsyncRequest> weak_ptr_factory_;
|
| +};
|
| +
|
| +}
|
| +
|
| +void AsyncTrustStoreStatic::IsTrustedCertificate(
|
| + scoped_refptr<ParsedCertificate> cert,
|
| + const TrustCallback& callback,
|
| + bool* out_trusted,
|
| + std::unique_ptr<TrustStore::Request>* out_req) const {
|
| + if (callback.is_null()) {
|
| + *out_trusted = false;
|
| + out_req->reset();
|
| + return;
|
| + }
|
| + std::unique_ptr<StaticAsyncRequest> req(new StaticAsyncRequest(callback));
|
| + std::unique_ptr<TrustStore::Request> unused_req;
|
| + bool is_trusted;
|
| + trust_store_static_.IsTrustedCertificate(cert, TrustCallback(), &is_trusted,
|
| + &unused_req);
|
| + DCHECK(!unused_req);
|
| + req->PostTrustCallback(is_trusted);
|
| + *out_req = std::move(req);
|
| +}
|
| +
|
| +// CertIssuerSource implementation:
|
| +void AsyncTrustStoreStatic::SyncGetIssuersOf(const ParsedCertificate* cert,
|
| + ParsedCertificateList* issuers) {
|
| + trust_store_static_.SyncGetIssuersOf(std::move(cert), issuers);
|
| +}
|
| +
|
| +void AsyncTrustStoreStatic::AsyncGetIssuersOf(
|
| + scoped_refptr<ParsedCertificate> cert,
|
| + const IssuerCallback& callback,
|
| + std::unique_ptr<CertIssuerSource::Request>* out_req) {
|
| + trust_store_static_.AsyncGetIssuersOf(std::move(cert), callback, out_req);
|
| +}
|
| +
|
| +TrustResultRecorder::TrustResultRecorder() = default;
|
| +TrustResultRecorder::~TrustResultRecorder() = default;
|
| +
|
| +TrustStore::TrustCallback TrustResultRecorder::Callback() {
|
| + return base::Bind(&TrustResultRecorder::HandleResult, base::Unretained(this));
|
| +}
|
| +
|
| +void TrustRequestDeleter(std::unique_ptr<TrustStore::Request>* req_owner,
|
| + base::Closure done_callback,
|
| + bool trusted) {
|
| + req_owner->reset();
|
| + done_callback.Run();
|
| +}
|
| +
|
| +} // namespace net
|
|
|