Chromium Code Reviews| 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..eca57f0acf367d69f54bfbfb29db78c8024fd81b |
| --- /dev/null |
| +++ b/net/cert/cert_net_fetcher.h |
| @@ -0,0 +1,151 @@ |
| +// 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/threading/non_thread_safe.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 |
| + : NON_EXPORTED_BASE(public base::NonThreadSafe) { |
|
Ryan Sleevi
2015/02/11 08:41:54
I'm not a fan of inheriting from base::NonThreadSa
eroman
2015/02/11 23:18:08
NonThreadSafe was based on a recommendation by Mat
eroman
2015/02/13 22:11:38
Done -- switched to ThreadChecker.
|
| + private: |
| + struct Request; |
|
Ryan Sleevi
2015/02/11 08:41:53
Is it truly necessary for this to appear first? Th
eroman
2015/02/11 23:18:08
I get a compile error when moving it down.
|
| + |
| + 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 { |
|
Ryan Sleevi
2015/02/11 08:41:54
I just dinged another reviewer for using a struct
eroman
2015/02/11 20:15:16
I will switch this over to using explicit methods,
eroman
2015/02/11 23:18:08
Done. In the latest patchset there are separate me
|
| + 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, |
|
Ryan Sleevi
2015/02/11 08:41:54
See comments re: implicit overloads being created
eroman
2015/02/11 23:18:08
Acknowledged.
|
| + FetchCallback callback); |
|
Ryan Sleevi
2015/02/11 08:41:53
Pass by const-ref
eroman
2015/02/11 23:18:08
Done.
|
| + |
| + // 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); |
|
Ryan Sleevi
2015/02/11 08:41:54
DANGER: This API pattern generally results in "doo
eroman
2015/02/11 23:18:08
No longer relevant as Job is not refcounted.
|
| + |
| + // 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_ |