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 { | |
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.
| |
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 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.
| |
38 FetchFailedCallback; | |
39 explicit LogProofFetcher(net::URLRequestContext* request_context); | |
40 ~LogProofFetcher() override; | |
41 | |
42 // Fetch the latest Signed Tree Head from the log identified by |log_id| | |
43 // from |log_url|. | |
44 void FetchSTH(const GURL& log_url, | |
45 const std::string& log_id, | |
46 FetchSTHCallback fetched_cb, | |
47 FetchFailedCallback failed_cb); | |
48 | |
49 // net::URLRequest::Delegate | |
50 void OnResponseStarted(net::URLRequest* request) override; | |
51 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; | |
52 | |
53 private: | |
54 struct FetchParams; | |
55 | |
56 bool CheckReadStatus(net::URLRequest* request, FetchParams* params); | |
57 void KickOffARead(net::URLRequest* request, FetchParams* params); | |
58 | |
59 // Performs post-report cleanup. | |
60 void RequestComplete(net::URLRequest* request); | |
61 // Returns the FetchParams associated with the request. The caller takes | |
62 // ownership of the returned value in case the params should be used before | |
63 // being deleted. | |
64 scoped_ptr<FetchParams> CleanupRequest(net::URLRequest* request); | |
65 | |
66 // Actually create the request | |
67 scoped_ptr<net::URLRequest> CreateURLRequest(const GURL& fetch_sth_url); | |
68 | |
69 // Callbacks for parsing the STH's JSON by the SafeJsonParser | |
70 void OnSTHJsonParseSuccess(FetchParams params, | |
71 scoped_ptr<base::Value> parsed_json); | |
72 void OnSTHJsonParseError(FetchParams params, const std::string& error); | |
73 | |
74 net::URLRequestContext* const request_context_; | |
75 | |
76 // 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.
| |
77 std::map<net::URLRequest*, FetchParams*> inflight_requests_; | |
78 | |
79 base::WeakPtrFactory<LogProofFetcher> weak_factory_; | |
80 | |
81 DISALLOW_COPY_AND_ASSIGN(LogProofFetcher); | |
82 }; | |
83 | |
84 } // namespace certificate_transparency | |
85 | |
86 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_PROOF_FETCHER_H_ | |
OLD | NEW |