Chromium Code Reviews| Index: components/certificate_transparency/log_proof_fetcher.h |
| diff --git a/components/certificate_transparency/log_proof_fetcher.h b/components/certificate_transparency/log_proof_fetcher.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8603b31aec388531d2879073f622edff9d460d0a |
| --- /dev/null |
| +++ b/components/certificate_transparency/log_proof_fetcher.h |
| @@ -0,0 +1,86 @@ |
| +// 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 COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_PROOF_FETCHER_H_ |
| +#define COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_PROOF_FETCHER_H_ |
| + |
| +#include <map> |
| +#include <string> |
| + |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "net/url_request/url_request.h" |
| +#include "url/gurl.h" |
| + |
| +namespace base { |
| +class Value; |
| +} // namespace base |
| + |
| +namespace net { |
|
davidben
2015/07/16 21:53:39
Nit: Probably put a newline after this to mirror l
Eran Messeri
2015/07/17 15:40:23
Done.
|
| +class URLRequestContext; |
| + |
| +namespace ct { |
| +struct SignedTreeHead; |
| +} // namespace ct |
| + |
| +} // namespace net |
| + |
| +namespace certificate_transparency { |
| + |
| +// Fetches STHs and consistency proofs from Certificate Transparency logs |
| +// using the URLRequestContext provided during the instance construction. |
| +class LogProofFetcher : public net::URLRequest::Delegate { |
| + public: |
| + typedef base::Callback<void(const std::string&, |
| + const net::ct::SignedTreeHead&)> FetchSTHCallback; |
| + typedef base::Callback<void(const std::string&, const std::string&)> |
|
davidben
2015/07/16 21:53:39
Nit:
using FetchSTHCallback = base::Callback<..>
Eran Messeri
2015/07/17 15:40:23
Done.
|
| + FetchFailedCallback; |
| + explicit LogProofFetcher(net::URLRequestContext* request_context); |
| + ~LogProofFetcher() override; |
| + |
| + // Fetch the latest Signed Tree Head from the log identified by |log_id| |
| + // from |log_url|. |
| + void FetchSTH(const GURL& log_url, |
| + const std::string& log_id, |
| + FetchSTHCallback fetched_cb, |
| + FetchFailedCallback failed_cb); |
| + |
| + // net::URLRequest::Delegate |
| + void OnResponseStarted(net::URLRequest* request) override; |
| + void OnReadCompleted(net::URLRequest* request, int bytes_read) override; |
| + |
| + private: |
| + struct FetchParams; |
| + |
| + bool CheckReadStatus(net::URLRequest* request, FetchParams* params); |
| + void KickOffARead(net::URLRequest* request, FetchParams* params); |
| + |
| + // Performs post-report cleanup. |
| + void RequestComplete(net::URLRequest* request); |
| + // Returns the FetchParams associated with the request. The caller takes |
| + // ownership of the returned value in case the params should be used before |
| + // being deleted. |
| + scoped_ptr<FetchParams> CleanupRequest(net::URLRequest* request); |
| + |
| + // Actually create the request |
| + scoped_ptr<net::URLRequest> CreateURLRequest(const GURL& fetch_sth_url); |
| + |
| + // Callbacks for parsing the STH's JSON by the SafeJsonParser |
| + void OnSTHJsonParseSuccess(FetchParams params, |
| + scoped_ptr<base::Value> parsed_json); |
| + void OnSTHJsonParseError(FetchParams params, const std::string& error); |
| + |
| + net::URLRequestContext* const request_context_; |
| + |
| + // Owns the contained requests. |
|
davidben
2015/07/16 21:53:39
This also owns the FetchParams, right? So probably
Eran Messeri
2015/07/17 15:40:23
Done.
|
| + std::map<net::URLRequest*, FetchParams*> inflight_requests_; |
| + |
| + base::WeakPtrFactory<LogProofFetcher> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(LogProofFetcher); |
| +}; |
| + |
| +} // namespace certificate_transparency |
| + |
| +#endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_PROOF_FETCHER_H_ |