Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Unified Diff: components/certificate_transparency/log_proof_fetcher.h

Issue 1222953002: Certificate Transparency: Add STH Fetching capability. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing review comments Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..f3be4a4c4ade13b64ef60a0d807c8ad0bc754b78
--- /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 {
+
+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:
+ using FetchSTHCallback =
mmenke 2015/07/17 17:57:47 Google style discourages use of uncommon abbreviat
Eran Messeri 2015/07/29 15:16:59 Done, renamed to SignedTreeHeadFetchedCallback. Al
+ base::Callback<void(const std::string&, const net::ct::SignedTreeHead&)>;
+ using FetchFailedCallback = base::Callback<void(const std::string&, int)>;
mmenke 2015/07/17 17:57:47 I believe the callback arguments should be named
mmenke 2015/07/17 17:57:48 Callbacks should be documented.
mmenke 2015/07/17 17:57:48 Need to include callback header.
Eran Messeri 2015/07/29 15:16:59 Done.
Eran Messeri 2015/07/29 15:16:59 Done.
Eran Messeri 2015/07/29 15:16:59 Done.
+ explicit LogProofFetcher(net::URLRequestContext* request_context);
mmenke 2015/07/17 17:57:48 nit: Add blank line above constructor.
Eran Messeri 2015/07/29 15:16:59 Done.
+ ~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);
mmenke 2015/07/17 17:57:47 Write out callback.
mmenke 2015/07/17 17:57:47 Callbacks are generally passed via const ref (Even
Eran Messeri 2015/07/29 15:16:59 Done.
Eran Messeri 2015/07/29 15:16:59 Done.
+
+ // net::URLRequest::Delegate
+ void OnResponseStarted(net::URLRequest* request) override;
+ void OnReadCompleted(net::URLRequest* request, int bytes_read) override;
+
+ private:
+ struct FetchState;
+
+ bool CheckReadStatus(net::URLRequest* request, FetchState* params);
+ void KickOffARead(net::URLRequest* request, FetchState* params);
+
+ // Performs post-report cleanup.
+ void RequestComplete(net::URLRequest* request);
+ // Returns the FetchState associated with the request. The caller takes
+ // ownership of the returned value in case the params should be used before
+ // being deleted.
+ scoped_ptr<FetchState> 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,
+ 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_;
mmenke 2015/07/17 17:57:47 Include weak_ptr.h
Eran Messeri 2015/07/29 15:16:59 Done.
+
+ DISALLOW_COPY_AND_ASSIGN(LogProofFetcher);
mmenke 2015/07/17 17:57:47 Include base/macros.h for DISALLOW_COPY_AND_ASSIGN
Eran Messeri 2015/07/29 15:16:59 Done.
+};
+
+} // namespace certificate_transparency
+
+#endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_PROOF_FETCHER_H_

Powered by Google App Engine
This is Rietveld 408576698