OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 #ifndef COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_PROOF_FETCHER_H_ | |
6 #define COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_PROOF_FETCHER_H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "net/url_request/url_request.h" | |
14 #include "url/gurl.h" | |
15 | |
16 namespace base { | |
17 class Value; | |
18 } // namespace base | |
19 | |
20 namespace net { | |
21 class URLRequestContext; | |
22 | |
23 namespace ct { | |
24 struct SignedTreeHead; | |
25 } // namespace ct | |
26 | |
27 } // namespace net | |
28 | |
29 namespace certificate_transparency { | |
30 | |
31 // Fetches STHs and consistency proofs from Certificate Transparency logs | |
32 // using the URLRequestContext provided during the instance construction. | |
33 class LogProofFetcher : public net::URLRequest::Delegate { | |
34 public: | |
35 typedef base::Callback<void(const std::string&, | |
36 const net::ct::SignedTreeHead&)> FetchSTHCallback; | |
37 explicit LogProofFetcher(net::URLRequestContext* request_context); | |
Ryan Sleevi
2015/06/29 11:58:13
Document the lifetime requirements re: |request_co
| |
38 ~LogProofFetcher() override; | |
39 | |
40 // Fetch the latest Signed Tree Head from the log identified by |verifier| | |
41 void FetchSTH(const GURL& log_url, | |
42 const std::string& log_id, | |
43 FetchSTHCallback fetched_cb); | |
44 | |
45 // net::URLRequest::Delegate | |
46 void OnResponseStarted(net::URLRequest* request) override; | |
47 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; | |
48 | |
49 private: | |
50 struct FetchParams; | |
51 | |
52 scoped_ptr<net::URLRequest> CreateURLRequest(const GURL& fetch_sth_url); | |
53 | |
54 // Performs post-report cleanup. | |
55 void RequestComplete(net::URLRequest* request, int bytes_read); | |
56 void CleanupRequest(net::URLRequest* request); | |
57 | |
58 // Callbacks for parsing the STH's JSON by the SafeJsonParser | |
59 void OnSTHJsonParseSuccess(FetchParams params, | |
60 scoped_ptr<base::Value> parsed_json); | |
61 void OnSTHJsonParseError(FetchParams params, const std::string& error); | |
62 | |
63 net::URLRequestContext* const request_context_; | |
64 | |
65 // Owns the contained requests. | |
66 std::map<net::URLRequest*, FetchParams*> inflight_requests_; | |
67 | |
68 base::WeakPtrFactory<LogProofFetcher> weak_factory_; | |
69 | |
70 DISALLOW_COPY_AND_ASSIGN(LogProofFetcher); | |
71 }; | |
72 | |
73 } // namespace certificate_transparency | |
74 | |
75 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_PROOF_FETCHER_H_ | |
OLD | NEW |