OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/cert/internal/trust_store_test_helpers.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" |
| 9 #include "base/location.h" |
| 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" |
| 12 |
| 13 namespace net { |
| 14 |
| 15 namespace { |
| 16 |
| 17 class StaticAsyncRequest : public TrustStore::Request { |
| 18 public: |
| 19 StaticAsyncRequest(const TrustStore::TrustCallback& callback) |
| 20 : callback_(callback), weak_ptr_factory_(this) {} |
| 21 ~StaticAsyncRequest() override = default; |
| 22 |
| 23 void PostTrustCallback(bool trusted) { |
| 24 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 25 FROM_HERE, base::Bind(&StaticAsyncRequest::DoTrustCallback, |
| 26 weak_ptr_factory_.GetWeakPtr(), trusted)); |
| 27 } |
| 28 |
| 29 private: |
| 30 void DoTrustCallback(bool trusted) { |
| 31 base::ResetAndReturn(&callback_).Run(trusted); |
| 32 // |this| may be deleted here. |
| 33 } |
| 34 |
| 35 TrustStore::TrustCallback callback_; |
| 36 base::WeakPtrFactory<StaticAsyncRequest> weak_ptr_factory_; |
| 37 }; |
| 38 |
| 39 } |
| 40 |
| 41 void AsyncTrustStoreStatic::IsTrustedCertificate( |
| 42 scoped_refptr<ParsedCertificate> cert, |
| 43 const TrustCallback& callback, |
| 44 bool* out_trusted, |
| 45 std::unique_ptr<TrustStore::Request>* out_req) const { |
| 46 if (callback.is_null()) { |
| 47 *out_trusted = false; |
| 48 out_req->reset(); |
| 49 return; |
| 50 } |
| 51 std::unique_ptr<StaticAsyncRequest> req(new StaticAsyncRequest(callback)); |
| 52 std::unique_ptr<TrustStore::Request> unused_req; |
| 53 bool is_trusted; |
| 54 trust_store_static_.IsTrustedCertificate(cert, TrustCallback(), &is_trusted, |
| 55 &unused_req); |
| 56 DCHECK(!unused_req); |
| 57 req->PostTrustCallback(is_trusted); |
| 58 *out_req = std::move(req); |
| 59 } |
| 60 |
| 61 // CertIssuerSource implementation: |
| 62 void AsyncTrustStoreStatic::SyncGetIssuersOf(const ParsedCertificate* cert, |
| 63 ParsedCertificateList* issuers) { |
| 64 trust_store_static_.SyncGetIssuersOf(std::move(cert), issuers); |
| 65 } |
| 66 |
| 67 void AsyncTrustStoreStatic::AsyncGetIssuersOf( |
| 68 scoped_refptr<ParsedCertificate> cert, |
| 69 const IssuerCallback& callback, |
| 70 std::unique_ptr<CertIssuerSource::Request>* out_req) { |
| 71 trust_store_static_.AsyncGetIssuersOf(std::move(cert), callback, out_req); |
| 72 } |
| 73 |
| 74 TrustResultRecorder::TrustResultRecorder() = default; |
| 75 TrustResultRecorder::~TrustResultRecorder() = default; |
| 76 |
| 77 TrustStore::TrustCallback TrustResultRecorder::Callback() { |
| 78 return base::Bind(&TrustResultRecorder::HandleResult, base::Unretained(this)); |
| 79 } |
| 80 |
| 81 void TrustRequestDeleter(std::unique_ptr<TrustStore::Request>* req_owner, |
| 82 base::Closure done_callback, |
| 83 bool trusted) { |
| 84 req_owner->reset(); |
| 85 done_callback.Run(); |
| 86 } |
| 87 |
| 88 } // namespace net |
OLD | NEW |