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 NET_CERT_CERT_NET_FETCHER_H_ | |
6 #define NET_CERT_CERT_NET_FETCHER_H_ | |
7 | |
8 #include <set> | |
9 #include <vector> | |
10 | |
11 #include "base/callback.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/threading/thread_checker.h" | |
14 #include "base/time/time.h" | |
Ryan Sleevi
2015/02/23 20:25:22
This appears to be unused now?
eroman
2015/02/23 23:36:58
Done.
| |
15 #include "net/base/net_export.h" | |
16 #include "url/gurl.h" | |
17 | |
18 namespace net { | |
19 | |
20 class URLRequestContext; | |
Ryan Sleevi
2015/02/23 20:25:22
Hrm. From the perspective of //net/cert, this is a
eroman
2015/02/23 23:36:58
I can certainly split up as Interface/Impl if need
| |
21 | |
22 // CertNetFetcher is a helper for fetching AIA URLs and CRL URLs. | |
23 // | |
24 // It manages the outstanding requests, and applies policies specific to | |
25 // certificate network fetches. For instance: | |
26 // * Enforces a maximum timeout on responses | |
27 // * Enforces a maximum size on responses | |
28 // * Restricts URLs to http:// | |
Ryan Sleevi
2015/02/23 20:25:22
A thought occurred to me - how will we handle HSTS
eroman
2015/02/23 23:36:58
Good point I hadn't considered HSTS. I responded o
| |
29 // | |
30 // The CertNetFetcher is initialized by giving it a URLRequestContext for the | |
31 // network dependencies. Note that it does not maintain its own in-memory cache | |
32 // for responses. Instead it is reliant on the URLRequestContext providing an | |
33 // HTTP cache if this is desired. | |
34 // | |
35 // ------------------------- | |
36 // Cancellation of requests | |
37 // ------------------------- | |
38 // | |
39 // * Network requests started by the CertNetFetcher can be cancelled using | |
40 // CancelRequest(). Cancellation means the callback will not be invoked. | |
41 // | |
42 // * If the CertNetFetcher is deleted then any outstanding | |
43 // requests are automatically cancelled. | |
44 // | |
45 // * Cancelling a request more than once is an error (and may result in a | |
46 // use-after-free). | |
47 // | |
48 // * Cancelling a request within the execution of a callback is allowed. | |
49 // | |
50 // * Deleting the CertNetFetcher from within the execution of a callback is | |
51 // allowed. | |
52 // | |
53 // ------------------------- | |
54 // Threading | |
55 // ------------------------- | |
56 // | |
57 // The CertNetFetcher is expected to be operated from a single thread, which has | |
58 // an IO message loop. The URLRequestContext will be accessed from this same | |
59 // thread, and callbacks will be posted to this message loop. | |
60 // | |
61 // For more details see the early design document: | |
62 // https://docs.google.com/a/chromium.org/document/d/1CdS9YOnPdAyVZBJqHY7ZJ6tU lU71OCvX8kHnaVhf144/edit | |
63 class NET_EXPORT CertNetFetcher { | |
64 private: | |
65 struct Request; | |
66 | |
67 public: | |
68 typedef base::Callback<void(int, const std::vector<uint8_t>&)> FetchCallback; | |
69 | |
70 typedef Request* RequestId; | |
71 | |
72 // This value can be used in place of timeout or max size limits. | |
73 static const int DEFAULT = -1; | |
74 | |
75 // Initializes CertNetFetcher using the specified URLRequestContext for | |
76 // issuing requests. |context| must remain valid for the entire lifetime of | |
77 // the CertNetFetcher. | |
78 explicit CertNetFetcher(URLRequestContext* context); | |
79 | |
80 // Deletion implicitly cancels any outstanding requests. | |
81 ~CertNetFetcher(); | |
82 | |
83 // Cancels the indicated request. It is an error to call this function on a | |
84 // request which has already completed (including one that was already | |
85 // cancelled). | |
86 void CancelRequest(RequestId request); | |
87 | |
88 // The Fetch*() methods start an asynchronous request which can be cancelled | |
89 // using RequestId. Here is the meaning of the common parameters: | |
90 // | |
91 // * url -- The http:// URL to fetch. | |
92 // * timeout_seconds -- The maximum allowed duration for the fetch job. If | |
93 // this delay is exceeded then the request will fail. To use a default | |
94 // timeout pass DEFAULT. | |
95 // * max_response_bytes -- The maximum size of the response body. If this | |
96 // size is exceeded then the request will fail. To use a default timeout | |
97 // pass DEFAULT. | |
98 // * callback -- The callback that will be invoked on completion of the job. | |
99 | |
100 RequestId FetchCaIssuers(const GURL& url, | |
101 int timeout_milliseconds, | |
102 int max_response_bytes, | |
103 const FetchCallback& callback); | |
104 | |
105 RequestId FetchCrl(const GURL& url, | |
106 int timeout_milliseconds, | |
107 int max_response_bytes, | |
108 const FetchCallback& callback); | |
109 | |
110 RequestId FetchOcsp(const GURL& url, | |
111 int timeout_milliseconds, | |
112 int max_response_bytes, | |
113 const FetchCallback& callback); | |
114 | |
115 private: | |
116 class Job; | |
117 struct JobToRequestParamsComparator; | |
118 struct RequestParams; | |
119 | |
120 struct JobComparator { | |
121 bool operator()(const Job* job1, const Job* job2) const; | |
122 }; | |
123 | |
124 typedef std::set<Job*, JobComparator> JobSet; | |
Ryan Sleevi
2015/02/23 20:25:22
Per https://chromium-cpp.appspot.com/ , prefer "us
eroman
2015/02/23 23:36:58
Done. Changed all the typedefs to using=
| |
125 | |
126 // Starts an asynchronous request to fetch the given URL. On completion | |
127 // |callback| will be invoked. | |
128 // | |
129 // Completion of the request will never occur synchronously. In other words it | |
130 // is guaranteed that |callback| will only be invoked once the Fetch*() method | |
131 // has returned. | |
132 RequestId Fetch(scoped_ptr<RequestParams> request_params, | |
133 const FetchCallback& callback); | |
134 | |
135 // Finds a job with a matching RequestPararms or returns NULL if there was no | |
136 // match. | |
137 Job* FindJob(const RequestParams& params); | |
138 | |
139 // Removes |job| from the in progress jobs and transfers ownership to the | |
140 // caller. | |
141 scoped_ptr<Job> RemoveJob(Job* job); | |
142 | |
143 // Indicates which Job is currently executing inside of OnJobCompleted(). | |
144 void SetCurrentlyCompletingJob(Job* job); | |
145 | |
146 // The in-progress jobs. This set does not contain the job which is actively | |
147 // invoking callbacks (OnJobCompleted). Instead that is tracked by | |
148 // |currently_completing_job_|. | |
149 JobSet jobs_; | |
150 | |
151 // The Job that is currently executing OnJobCompleted(). There can be at most | |
152 // one such job. This pointer is not owned. | |
153 Job* currently_completing_job_; | |
154 | |
155 // Not owned. CertNetFetcher must outlive the URLRequestContext. | |
156 URLRequestContext* context_; | |
157 | |
158 base::ThreadChecker thread_checker_; | |
159 | |
160 DISALLOW_COPY_AND_ASSIGN(CertNetFetcher); | |
161 }; | |
162 | |
163 } // namespace net | |
164 | |
165 #endif // NET_CERT_CERT_NET_FETCHER_H_ | |
OLD | NEW |