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

Unified Diff: net/cert/cert_net_fetcher.h

Issue 908863004: Initial implementation for CertNetFetcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add a missing header Created 5 years, 10 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
« no previous file with comments | « no previous file | net/cert/cert_net_fetcher.cc » ('j') | net/cert/cert_net_fetcher.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cert/cert_net_fetcher.h
diff --git a/net/cert/cert_net_fetcher.h b/net/cert/cert_net_fetcher.h
new file mode 100644
index 0000000000000000000000000000000000000000..a47caef6e8afcef53f55d84ee6adabe371931530
--- /dev/null
+++ b/net/cert/cert_net_fetcher.h
@@ -0,0 +1,149 @@
+// 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 NET_CERT_CERT_NET_FETCHER_H_
+#define NET_CERT_CERT_NET_FETCHER_H_
+
+#include <set>
+#include <vector>
+
+#include "base/callback.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/time/time.h"
+#include "net/base/net_export.h"
+#include "url/gurl.h"
+
+namespace net {
+
+class URLRequestContext;
+
+// CertNetFetcher is a helper for fetching AIA URLs and CRL URLs.
+//
+// It manages the outstanding requests, and applies policies specific to
+// certificate network fetches. For instance:
+// * Enforces a maximum timeout on responses
+// * Enforces a maximum size on responses
+// * Restricts URLs to http://
+//
+// The CertNetFetcher is initialized by giving it a URLRequestContext for the
+// network dependencies. Note that it does not maintain its own in-memory cache
+// for responses. Instead it is reliant on the URLRequestContext providing an
+// HTTP cache if this is desired.
+//
+// -------------------------
+// Cancellation of requests
+// -------------------------
+//
+// * Network requests started by the CertNetFetcher can be cancelled using
+// CancelRequest(). Cancellation means the callback will not be invoked.
+//
+// * If the CertNetFetcher is deleted then any outstanding
+// requests are automatically cancelled.
+//
+// * Cancelling a request more than once is an error (and may result in a
+// use-after-free).
+//
+// * Cancelling a request within the execution of a callback is allowed.
+//
+// * Deleting the CertNetFetcher from within the execution of a callback is
+// allowed.
+//
+// -------------------------
+// Threading
+// -------------------------
+//
+// The CertNetFetcher is expected to be operated from a single thread, which has
+// an IO message loop. The URLRequestContext will be accessed from this same
+// thread, and callbacks will be posted to this message loop.
+//
+// For more details see the early design document:
+// https://docs.google.com/a/chromium.org/document/d/1CdS9YOnPdAyVZBJqHY7ZJ6tUlU71OCvX8kHnaVhf144/edit
+class NET_EXPORT CertNetFetcher {
mattm 2015/02/10 05:22:14 Maybe inherit NonThreadSafe and add CalledOnValidT
eroman 2015/02/11 03:51:52 Done.
+ private:
+ struct Request;
+
+ public:
+ typedef base::Callback<void(int, const std::vector<uint8_t>&)> FetchCallback;
+
+ enum RequestType {
+ REQUEST_TYPE_CA_ISSUERS,
+ REQUEST_TYPE_OCSP,
+ REQUEST_TYPE_CRL,
+ };
+
+ enum HttpMethod {
+ HTTP_METHOD_GET,
+ HTTP_METHOD_POST,
+ };
+
+ struct RequestParams {
+ RequestParams(const GURL& url, RequestType type);
+
+ bool operator<(const RequestParams& other) const;
+
+ GURL url;
+ HttpMethod http_method;
+ size_t max_response_size_in_bytes;
+
+ // If set to a value <= 0 then means "no timeout".
+ base::TimeDelta timeout;
+
+ // IMPORTANT: When adding fields to this structure, update operator<().
+ };
+
+ typedef Request* RequestId;
+
+ // Initilizes CertNetFetcher using the specified URLRequestContext for issuing
+ // requests. |context| must remain valid for the entire lifetime of the
+ // CertNetFetcher.
+ explicit CertNetFetcher(URLRequestContext* context);
+
+ ~CertNetFetcher();
+
+ // Starts an asynchronous request to fetch the given URL. On completion
+ // |callback| will be invoked.
+ //
+ // Completion of the request will never occur synchronously. In other words it
+ // is guaranteed that |callback| will only be invoked once the Fetch*() method
+ // has returned.
+ RequestId Fetch(scoped_ptr<RequestParams> request_params,
+ FetchCallback callback);
+
+ // Cancels the indicated request. It is an error to call this function on a
+ // request which has already completed (including one that was already
+ // cancelled).
+ void CancelRequest(RequestId request);
+
+ private:
+ class Job;
+ struct JobToRequestParamsComparator;
+
+ struct JobComparator {
+ bool operator()(const scoped_refptr<Job>& job1,
+ const scoped_refptr<Job>& job2) const;
+ };
+
+ typedef std::set<scoped_refptr<Job>, JobComparator> JobSet;
+
+ // Finds a job with a matching RequestPararms or returns NULL if there was no
+ // match.
+ Job* FindJob(const RequestParams& params);
+
+ // Removes |job| from the in progress jobs. This may cause the final reference
+ // to |job| to be released.
+ void RemoveJob(Job* job);
+
+ // The in-progress jobs.
+ JobSet jobs_;
+
+ // Not owned. CertNetFetcher must outlive the URLRequestContext.
+ URLRequestContext* context_;
+
+ DISALLOW_COPY_AND_ASSIGN(CertNetFetcher);
+};
+
+} // namespace net
+
+#endif // NET_CERT_CERT_NET_FETCHER_H_
« no previous file with comments | « no previous file | net/cert/cert_net_fetcher.cc » ('j') | net/cert/cert_net_fetcher.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698