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/callback.h" | |
12 #include "base/macros.h" | |
13 #include "base/memory/ref_counted.h" | |
mmenke
2015/07/29 18:51:51
Only used in the CC file.
Eran Messeri
2015/07/31 12:55:53
Done.
| |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/memory/weak_ptr.h" | |
16 #include "net/url_request/url_request.h" | |
17 #include "url/gurl.h" | |
mmenke
2015/07/29 18:51:51
Can forward declare GURL, and move the include int
Eran Messeri
2015/07/31 12:55:53
Done.
| |
18 | |
19 namespace base { | |
20 class Value; | |
21 } // namespace base | |
22 | |
23 namespace net { | |
24 | |
25 class URLRequestContext; | |
26 | |
27 namespace ct { | |
28 struct SignedTreeHead; | |
29 } // namespace ct | |
30 | |
31 } // namespace net | |
32 | |
33 namespace certificate_transparency { | |
34 | |
35 // Fetches Signed Tree Heads (STHs) and consistency proofs from Certificate | |
36 // Transparency logs using the URLRequestContext provided during the instance | |
37 // construction. | |
38 class LogProofFetcher : public net::URLRequest::Delegate { | |
39 public: | |
40 // Callback for successful retrieval of Signed Tree Heads. Called | |
41 // with the log_id of the log the STH belogs to and the STH itself. | |
42 using SignedTreeHeadFetchedCallback = | |
43 base::Callback<void(const std::string& log_id, | |
mmenke
2015/07/29 18:51:51
This log ID is an STH thing, right, as opposed to
Eran Messeri
2015/07/31 12:55:53
It only makes sense to have one FetchSignedTreeHea
| |
44 const net::ct::SignedTreeHead& signed_tree_head)>; | |
mmenke
2015/07/29 18:51:51
nit: Suggest a blank line here.
Eran Messeri
2015/07/31 12:55:53
Done.
| |
45 // Callback for failure of Signed Tree Head retrieval. Called with the log_id | |
46 // of the log fetching was requested for and a net error code of the failure. | |
mmenke
2015/07/29 18:51:51
"of the log fetching" -> "that the log fetching"
Eran Messeri
2015/07/31 12:55:53
Done.
| |
47 using FetchFailedCallback = base::Callback< | |
48 void(const std::string& log_id, int net_error, int http_response_code)>; | |
49 | |
50 explicit LogProofFetcher(net::URLRequestContext* request_context); | |
51 ~LogProofFetcher() override; | |
52 | |
53 // Fetch the latest Signed Tree Head from the log identified by |log_id| | |
54 // from |base_log_url|. | |
55 void FetchSignedTreeHead( | |
56 const GURL& base_log_url, | |
57 const std::string& log_id, | |
58 const SignedTreeHeadFetchedCallback& fetched_callback, | |
59 const FetchFailedCallback& failed_callback); | |
60 | |
61 // net::URLRequest::Delegate | |
62 void OnResponseStarted(net::URLRequest* request) override; | |
63 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; | |
64 | |
65 private: | |
66 struct FetchState; | |
67 | |
68 bool HandleReadResult(net::URLRequest* request, | |
69 FetchState* params, | |
70 const int bytes_read); | |
71 void KickOffARead(net::URLRequest* request, | |
mmenke
2015/07/29 18:51:51
Suggest renaming this to something like ReadBody,
Eran Messeri
2015/07/31 12:55:53
Done.
| |
72 FetchState* params, | |
73 bool should_read); | |
mmenke
2015/07/29 18:51:51
Should document these two methods, and their retur
Eran Messeri
2015/07/31 12:55:52
Done.
| |
74 | |
75 // Performs post-report cleanup. | |
76 void RequestComplete(net::URLRequest* request); | |
77 // Deletes the request and associated FetchState from the internal map. | |
78 void CleanupRequest(net::URLRequest* request); | |
79 | |
80 // Actually create the request | |
81 scoped_ptr<net::URLRequest> CreateURLRequest(const GURL& fetch_sth_url); | |
82 | |
83 // Callbacks for parsing the STH's JSON by the SafeJsonParser | |
84 void OnSTHJsonParseSuccess(FetchState params, | |
mmenke
2015/07/29 18:51:51
FetchState isn't only forward declared at this poi
Eran Messeri
2015/07/31 12:55:53
Moved FetchState to be declared in the header.
| |
85 scoped_ptr<base::Value> parsed_json); | |
86 void OnSTHJsonParseError(FetchState params, const std::string& error); | |
87 | |
88 net::URLRequestContext* const request_context_; | |
89 | |
90 // Owns the contained requests, as well as FetchState. | |
91 std::map<net::URLRequest*, FetchState*> inflight_requests_; | |
92 | |
93 base::WeakPtrFactory<LogProofFetcher> weak_factory_; | |
94 | |
95 DISALLOW_COPY_AND_ASSIGN(LogProofFetcher); | |
96 }; | |
97 | |
98 } // namespace certificate_transparency | |
99 | |
100 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_PROOF_FETCHER_H_ | |
OLD | NEW |