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

Side by Side Diff: net/cert/multi_threaded_cert_verifier.cc

Issue 2315613002: Extracted NetLog class's inner enum types into their own enum classes and (Closed)
Patch Set: Ran "git cl format" on code. Much formatting ensued. Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « net/cert/multi_log_ct_verifier_unittest.cc ('k') | net/disk_cache/blockfile/entry_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/cert/multi_threaded_cert_verifier.h" 5 #include "net/cert/multi_threaded_cert_verifier.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 13 matching lines...) Expand all
24 #include "base/trace_event/trace_event.h" 24 #include "base/trace_event/trace_event.h"
25 #include "base/values.h" 25 #include "base/values.h"
26 #include "net/base/hash_value.h" 26 #include "net/base/hash_value.h"
27 #include "net/base/net_errors.h" 27 #include "net/base/net_errors.h"
28 #include "net/cert/cert_verify_proc.h" 28 #include "net/cert/cert_verify_proc.h"
29 #include "net/cert/cert_verify_result.h" 29 #include "net/cert/cert_verify_result.h"
30 #include "net/cert/crl_set.h" 30 #include "net/cert/crl_set.h"
31 #include "net/cert/x509_certificate.h" 31 #include "net/cert/x509_certificate.h"
32 #include "net/cert/x509_certificate_net_log_param.h" 32 #include "net/cert/x509_certificate_net_log_param.h"
33 #include "net/log/net_log.h" 33 #include "net/log/net_log.h"
34 #include "net/log/net_log_event_type.h"
35 #include "net/log/net_log_source_type.h"
34 36
35 #if defined(USE_NSS_CERTS) 37 #if defined(USE_NSS_CERTS)
36 #include <private/pprthred.h> // PR_DetachThread 38 #include <private/pprthred.h> // PR_DetachThread
37 #endif 39 #endif
38 40
39 namespace net { 41 namespace net {
40 42
41 //////////////////////////////////////////////////////////////////////////// 43 ////////////////////////////////////////////////////////////////////////////
42 // 44 //
43 // MultiThreadedCertVerifier is a thread-unsafe object which lives, dies, and is 45 // MultiThreadedCertVerifier is a thread-unsafe object which lives, dies, and is
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 public CertVerifier::Request { 125 public CertVerifier::Request {
124 public: 126 public:
125 CertVerifierRequest(CertVerifierJob* job, 127 CertVerifierRequest(CertVerifierJob* job,
126 const CompletionCallback& callback, 128 const CompletionCallback& callback,
127 CertVerifyResult* verify_result, 129 CertVerifyResult* verify_result,
128 const BoundNetLog& net_log) 130 const BoundNetLog& net_log)
129 : job_(job), 131 : job_(job),
130 callback_(callback), 132 callback_(callback),
131 verify_result_(verify_result), 133 verify_result_(verify_result),
132 net_log_(net_log) { 134 net_log_(net_log) {
133 net_log_.BeginEvent(NetLog::TYPE_CERT_VERIFIER_REQUEST); 135 net_log_.BeginEvent(NetLogEventType::CERT_VERIFIER_REQUEST);
134 } 136 }
135 137
136 // Cancels the request. 138 // Cancels the request.
137 ~CertVerifierRequest() override { 139 ~CertVerifierRequest() override {
138 if (job_) { 140 if (job_) {
139 // Cancel the outstanding request. 141 // Cancel the outstanding request.
140 net_log_.AddEvent(NetLog::TYPE_CANCELLED); 142 net_log_.AddEvent(NetLogEventType::CANCELLED);
141 net_log_.EndEvent(NetLog::TYPE_CERT_VERIFIER_REQUEST); 143 net_log_.EndEvent(NetLogEventType::CERT_VERIFIER_REQUEST);
142 144
143 // Remove the request from the Job. No attempt is made to cancel the job 145 // Remove the request from the Job. No attempt is made to cancel the job
144 // even though it may no longer have any requests attached to it. Because 146 // even though it may no longer have any requests attached to it. Because
145 // it is running on a worker thread aborting it isn't feasible. 147 // it is running on a worker thread aborting it isn't feasible.
146 RemoveFromList(); 148 RemoveFromList();
147 } 149 }
148 } 150 }
149 151
150 // Copies the contents of |verify_result| to the caller's 152 // Copies the contents of |verify_result| to the caller's
151 // CertVerifyResult and calls the callback. 153 // CertVerifyResult and calls the callback.
152 void Post(const ResultHelper& verify_result) { 154 void Post(const ResultHelper& verify_result) {
153 DCHECK(job_); 155 DCHECK(job_);
154 job_ = nullptr; 156 job_ = nullptr;
155 157
156 net_log_.EndEvent(NetLog::TYPE_CERT_VERIFIER_REQUEST); 158 net_log_.EndEvent(NetLogEventType::CERT_VERIFIER_REQUEST);
157 *verify_result_ = verify_result.result; 159 *verify_result_ = verify_result.result;
158 160
159 base::ResetAndReturn(&callback_).Run(verify_result.error); 161 base::ResetAndReturn(&callback_).Run(verify_result.error);
160 } 162 }
161 163
162 void OnJobCancelled() { 164 void OnJobCancelled() {
163 job_ = nullptr; 165 job_ = nullptr;
164 callback_.Reset(); 166 callback_.Reset();
165 } 167 }
166 168
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 } 203 }
202 204
203 // CertVerifierJob lives only on the verifier's origin message loop. 205 // CertVerifierJob lives only on the verifier's origin message loop.
204 class CertVerifierJob { 206 class CertVerifierJob {
205 public: 207 public:
206 CertVerifierJob(const CertVerifier::RequestParams& key, 208 CertVerifierJob(const CertVerifier::RequestParams& key,
207 NetLog* net_log, 209 NetLog* net_log,
208 MultiThreadedCertVerifier* cert_verifier) 210 MultiThreadedCertVerifier* cert_verifier)
209 : key_(key), 211 : key_(key),
210 start_time_(base::TimeTicks::Now()), 212 start_time_(base::TimeTicks::Now()),
211 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_CERT_VERIFIER_JOB)), 213 net_log_(
214 BoundNetLog::Make(net_log, NetLogSourceType::CERT_VERIFIER_JOB)),
212 cert_verifier_(cert_verifier), 215 cert_verifier_(cert_verifier),
213 is_first_job_(false), 216 is_first_job_(false),
214 weak_ptr_factory_(this) { 217 weak_ptr_factory_(this) {
215 net_log_.BeginEvent(NetLog::TYPE_CERT_VERIFIER_JOB, 218 net_log_.BeginEvent(NetLogEventType::CERT_VERIFIER_JOB,
216 base::Bind(&NetLogX509CertificateCallback, 219 base::Bind(&NetLogX509CertificateCallback,
217 base::Unretained(key.certificate().get()))); 220 base::Unretained(key.certificate().get())));
218 } 221 }
219 222
220 // Indicates whether this was the first job started by the CertVerifier. This 223 // Indicates whether this was the first job started by the CertVerifier. This
221 // is only used for logging certain UMA stats. 224 // is only used for logging certain UMA stats.
222 void set_is_first_job(bool is_first_job) { is_first_job_ = is_first_job; } 225 void set_is_first_job(bool is_first_job) { is_first_job_ = is_first_job; }
223 226
224 const CertVerifier::RequestParams& key() const { return key_; } 227 const CertVerifier::RequestParams& key() const { return key_; }
225 228
(...skipping 18 matching lines...) Expand all
244 base::Bind(&CertVerifierJob::OnJobCompleted, 247 base::Bind(&CertVerifierJob::OnJobCompleted,
245 weak_ptr_factory_.GetWeakPtr(), base::Passed(&owned_result)), 248 weak_ptr_factory_.GetWeakPtr(), base::Passed(&owned_result)),
246 true /* task is slow */); 249 true /* task is slow */);
247 } 250 }
248 251
249 ~CertVerifierJob() { 252 ~CertVerifierJob() {
250 // If the job is in progress, cancel it. 253 // If the job is in progress, cancel it.
251 if (cert_verifier_) { 254 if (cert_verifier_) {
252 cert_verifier_ = nullptr; 255 cert_verifier_ = nullptr;
253 256
254 net_log_.AddEvent(NetLog::TYPE_CANCELLED); 257 net_log_.AddEvent(NetLogEventType::CANCELLED);
255 net_log_.EndEvent(NetLog::TYPE_CERT_VERIFIER_JOB); 258 net_log_.EndEvent(NetLogEventType::CERT_VERIFIER_JOB);
256 259
257 // Notify each request of the cancellation. 260 // Notify each request of the cancellation.
258 for (base::LinkNode<CertVerifierRequest>* it = requests_.head(); 261 for (base::LinkNode<CertVerifierRequest>* it = requests_.head();
259 it != requests_.end(); it = it->next()) { 262 it != requests_.end(); it = it->next()) {
260 it->value()->OnJobCancelled(); 263 it->value()->OnJobCancelled();
261 } 264 }
262 } 265 }
263 } 266 }
264 267
265 // Creates and attaches a request to the Job. 268 // Creates and attaches a request to the Job.
266 std::unique_ptr<CertVerifierRequest> CreateRequest( 269 std::unique_ptr<CertVerifierRequest> CreateRequest(
267 const CompletionCallback& callback, 270 const CompletionCallback& callback,
268 CertVerifyResult* verify_result, 271 CertVerifyResult* verify_result,
269 const BoundNetLog& net_log) { 272 const BoundNetLog& net_log) {
270 std::unique_ptr<CertVerifierRequest> request( 273 std::unique_ptr<CertVerifierRequest> request(
271 new CertVerifierRequest(this, callback, verify_result, net_log)); 274 new CertVerifierRequest(this, callback, verify_result, net_log));
272 275
273 request->net_log().AddEvent( 276 request->net_log().AddEvent(
274 NetLog::TYPE_CERT_VERIFIER_REQUEST_BOUND_TO_JOB, 277 NetLogEventType::CERT_VERIFIER_REQUEST_BOUND_TO_JOB,
275 net_log_.source().ToEventParametersCallback()); 278 net_log_.source().ToEventParametersCallback());
276 279
277 requests_.Append(request.get()); 280 requests_.Append(request.get());
278 return request; 281 return request;
279 } 282 }
280 283
281 private: 284 private:
282 using RequestList = base::LinkedList<CertVerifierRequest>; 285 using RequestList = base::LinkedList<CertVerifierRequest>;
283 286
284 // Called on completion of the Job to log UMA metrics and NetLog events. 287 // Called on completion of the Job to log UMA metrics and NetLog events.
285 void LogMetrics(const ResultHelper& verify_result) { 288 void LogMetrics(const ResultHelper& verify_result) {
286 net_log_.EndEvent( 289 net_log_.EndEvent(
287 NetLog::TYPE_CERT_VERIFIER_JOB, 290 NetLogEventType::CERT_VERIFIER_JOB,
288 base::Bind(&CertVerifyResultCallback, verify_result.result)); 291 base::Bind(&CertVerifyResultCallback, verify_result.result));
289 base::TimeDelta latency = base::TimeTicks::Now() - start_time_; 292 base::TimeDelta latency = base::TimeTicks::Now() - start_time_;
290 UMA_HISTOGRAM_CUSTOM_TIMES("Net.CertVerifier_Job_Latency", 293 UMA_HISTOGRAM_CUSTOM_TIMES("Net.CertVerifier_Job_Latency",
291 latency, 294 latency,
292 base::TimeDelta::FromMilliseconds(1), 295 base::TimeDelta::FromMilliseconds(1),
293 base::TimeDelta::FromMinutes(10), 296 base::TimeDelta::FromMinutes(10),
294 100); 297 100);
295 if (is_first_job_) { 298 if (is_first_job_) {
296 UMA_HISTOGRAM_CUSTOM_TIMES("Net.CertVerifier_First_Job_Latency", 299 UMA_HISTOGRAM_CUSTOM_TIMES("Net.CertVerifier_First_Job_Latency",
297 latency, 300 latency,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 // The JobSet is kept in sorted order so items can be found using binary 420 // The JobSet is kept in sorted order so items can be found using binary
418 // search. 421 // search.
419 auto it = std::lower_bound(inflight_.begin(), inflight_.end(), key, 422 auto it = std::lower_bound(inflight_.begin(), inflight_.end(), key,
420 JobToRequestParamsComparator()); 423 JobToRequestParamsComparator());
421 if (it != inflight_.end() && !(key < (*it)->key())) 424 if (it != inflight_.end() && !(key < (*it)->key()))
422 return *it; 425 return *it;
423 return nullptr; 426 return nullptr;
424 } 427 }
425 428
426 } // namespace net 429 } // namespace net
OLDNEW
« no previous file with comments | « net/cert/multi_log_ct_verifier_unittest.cc ('k') | net/disk_cache/blockfile/entry_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698