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..e027da9107a54bc533532a5d867a953ededd02e5 |
--- /dev/null |
+++ b/components/certificate_transparency/log_proof_fetcher.h |
@@ -0,0 +1,100 @@ |
+// 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/callback.h" |
+#include "base/macros.h" |
+#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.
|
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
+#include "net/url_request/url_request.h" |
+#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.
|
+ |
+namespace base { |
+class Value; |
+} // namespace base |
+ |
+namespace net { |
+ |
+class URLRequestContext; |
+ |
+namespace ct { |
+struct SignedTreeHead; |
+} // namespace ct |
+ |
+} // namespace net |
+ |
+namespace certificate_transparency { |
+ |
+// Fetches Signed Tree Heads (STHs) and consistency proofs from Certificate |
+// Transparency logs using the URLRequestContext provided during the instance |
+// construction. |
+class LogProofFetcher : public net::URLRequest::Delegate { |
+ public: |
+ // Callback for successful retrieval of Signed Tree Heads. Called |
+ // with the log_id of the log the STH belogs to and the STH itself. |
+ using SignedTreeHeadFetchedCallback = |
+ 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
|
+ 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.
|
+ // Callback for failure of Signed Tree Head retrieval. Called with the log_id |
+ // 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.
|
+ using FetchFailedCallback = base::Callback< |
+ void(const std::string& log_id, int net_error, int http_response_code)>; |
+ |
+ explicit LogProofFetcher(net::URLRequestContext* request_context); |
+ ~LogProofFetcher() override; |
+ |
+ // Fetch the latest Signed Tree Head from the log identified by |log_id| |
+ // from |base_log_url|. |
+ void FetchSignedTreeHead( |
+ const GURL& base_log_url, |
+ const std::string& log_id, |
+ const SignedTreeHeadFetchedCallback& fetched_callback, |
+ const FetchFailedCallback& failed_callback); |
+ |
+ // net::URLRequest::Delegate |
+ void OnResponseStarted(net::URLRequest* request) override; |
+ void OnReadCompleted(net::URLRequest* request, int bytes_read) override; |
+ |
+ private: |
+ struct FetchState; |
+ |
+ bool HandleReadResult(net::URLRequest* request, |
+ FetchState* params, |
+ const int bytes_read); |
+ 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.
|
+ FetchState* params, |
+ 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.
|
+ |
+ // Performs post-report cleanup. |
+ void RequestComplete(net::URLRequest* request); |
+ // Deletes the request and associated FetchState from the internal map. |
+ void 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(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.
|
+ scoped_ptr<base::Value> parsed_json); |
+ void OnSTHJsonParseError(FetchState params, const std::string& error); |
+ |
+ net::URLRequestContext* const request_context_; |
+ |
+ // Owns the contained requests, as well as FetchState. |
+ std::map<net::URLRequest*, FetchState*> inflight_requests_; |
+ |
+ base::WeakPtrFactory<LogProofFetcher> weak_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(LogProofFetcher); |
+}; |
+ |
+} // namespace certificate_transparency |
+ |
+#endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_PROOF_FETCHER_H_ |