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

Side by Side Diff: net/base/server_bound_cert_service.cc

Issue 11689002: Fix for spdy cancelling ServerBoundCertServiceRequest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: NET_EXPORT the RequestHandle Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « net/base/server_bound_cert_service.h ('k') | net/base/server_bound_cert_service_unittest.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/base/server_bound_cert_service.h" 5 #include "net/base/server_bound_cert_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 } 342 }
343 } 343 }
344 344
345 std::vector<ServerBoundCertServiceRequest*> requests_; 345 std::vector<ServerBoundCertServiceRequest*> requests_;
346 SSLClientCertType type_; 346 SSLClientCertType type_;
347 }; 347 };
348 348
349 // static 349 // static
350 const char ServerBoundCertService::kEPKIPassword[] = ""; 350 const char ServerBoundCertService::kEPKIPassword[] = "";
351 351
352 ServerBoundCertService::RequestHandle::RequestHandle()
353 : service_(NULL),
354 request_(NULL) {}
355
356 ServerBoundCertService::RequestHandle::~RequestHandle() {
357 Cancel();
358 }
359
360 void ServerBoundCertService::RequestHandle::Cancel() {
361 if (request_) {
362 service_->CancelRequest(request_);
363 request_ = NULL;
364 callback_.Reset();
365 }
366 }
367
368 void ServerBoundCertService::RequestHandle::RequestStarted(
369 ServerBoundCertService* service,
370 ServerBoundCertServiceRequest* request,
371 const CompletionCallback& callback) {
372 DCHECK(request_ == NULL);
373 service_ = service;
374 request_ = request;
375 callback_ = callback;
376 }
377
378 void ServerBoundCertService::RequestHandle::OnRequestComplete(int result) {
379 request_ = NULL;
380 callback_.Run(result);
381 callback_.Reset();
382 }
383
352 ServerBoundCertService::ServerBoundCertService( 384 ServerBoundCertService::ServerBoundCertService(
353 ServerBoundCertStore* server_bound_cert_store, 385 ServerBoundCertStore* server_bound_cert_store,
354 const scoped_refptr<base::TaskRunner>& task_runner) 386 const scoped_refptr<base::TaskRunner>& task_runner)
355 : server_bound_cert_store_(server_bound_cert_store), 387 : server_bound_cert_store_(server_bound_cert_store),
356 task_runner_(task_runner), 388 task_runner_(task_runner),
357 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), 389 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
358 requests_(0), 390 requests_(0),
359 cert_store_hits_(0), 391 cert_store_hits_(0),
360 inflight_joins_(0) { 392 inflight_joins_(0) {
361 base::Time start = base::Time::Now(); 393 base::Time start = base::Time::Now();
(...skipping 22 matching lines...) Expand all
384 std::string* private_key, 416 std::string* private_key,
385 std::string* cert, 417 std::string* cert,
386 const CompletionCallback& callback, 418 const CompletionCallback& callback,
387 RequestHandle* out_req) { 419 RequestHandle* out_req) {
388 DVLOG(1) << __FUNCTION__ << " " << origin << " " 420 DVLOG(1) << __FUNCTION__ << " " << origin << " "
389 << (requested_types.empty() ? -1 : requested_types[0]) 421 << (requested_types.empty() ? -1 : requested_types[0])
390 << (requested_types.size() > 1 ? "..." : ""); 422 << (requested_types.size() > 1 ? "..." : "");
391 DCHECK(CalledOnValidThread()); 423 DCHECK(CalledOnValidThread());
392 base::TimeTicks request_start = base::TimeTicks::Now(); 424 base::TimeTicks request_start = base::TimeTicks::Now();
393 425
394 *out_req = NULL;
395
396 if (callback.is_null() || !private_key || !cert || origin.empty() || 426 if (callback.is_null() || !private_key || !cert || origin.empty() ||
397 requested_types.empty()) { 427 requested_types.empty()) {
398 RecordGetDomainBoundCertResult(INVALID_ARGUMENT); 428 RecordGetDomainBoundCertResult(INVALID_ARGUMENT);
399 return ERR_INVALID_ARGUMENT; 429 return ERR_INVALID_ARGUMENT;
400 } 430 }
401 431
402 std::string domain = GetDomainForHost(GURL(origin).host()); 432 std::string domain = GetDomainForHost(GURL(origin).host());
403 if (domain.empty()) { 433 if (domain.empty()) {
404 RecordGetDomainBoundCertResult(INVALID_ARGUMENT); 434 RecordGetDomainBoundCertResult(INVALID_ARGUMENT);
405 return ERR_INVALID_ARGUMENT; 435 return ERR_INVALID_ARGUMENT;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 // TODO(rkn): Log to the NetLog. 514 // TODO(rkn): Log to the NetLog.
485 LOG(ERROR) << "ServerBoundCertServiceWorker couldn't be started."; 515 LOG(ERROR) << "ServerBoundCertServiceWorker couldn't be started.";
486 RecordGetDomainBoundCertResult(WORKER_FAILURE); 516 RecordGetDomainBoundCertResult(WORKER_FAILURE);
487 return ERR_INSUFFICIENT_RESOURCES; // Just a guess. 517 return ERR_INSUFFICIENT_RESOURCES; // Just a guess.
488 } 518 }
489 job = new ServerBoundCertServiceJob(preferred_type); 519 job = new ServerBoundCertServiceJob(preferred_type);
490 inflight_[domain] = job; 520 inflight_[domain] = job;
491 } 521 }
492 522
493 ServerBoundCertServiceRequest* request = new ServerBoundCertServiceRequest( 523 ServerBoundCertServiceRequest* request = new ServerBoundCertServiceRequest(
494 request_start, callback, type, private_key, cert); 524 request_start,
525 base::Bind(&RequestHandle::OnRequestComplete, base::Unretained(out_req)),
526 type, private_key, cert);
495 job->AddRequest(request); 527 job->AddRequest(request);
496 *out_req = request; 528 out_req->RequestStarted(this, request, callback);
497 return ERR_IO_PENDING; 529 return ERR_IO_PENDING;
498 } 530 }
499 531
500 ServerBoundCertStore* ServerBoundCertService::GetCertStore() { 532 ServerBoundCertStore* ServerBoundCertService::GetCertStore() {
501 return server_bound_cert_store_.get(); 533 return server_bound_cert_store_.get();
502 } 534 }
503 535
504 void ServerBoundCertService::CancelRequest(RequestHandle req) { 536 void ServerBoundCertService::CancelRequest(ServerBoundCertServiceRequest* req) {
505 DCHECK(CalledOnValidThread()); 537 DCHECK(CalledOnValidThread());
506 ServerBoundCertServiceRequest* request = 538 req->Cancel();
507 reinterpret_cast<ServerBoundCertServiceRequest*>(req);
508 request->Cancel();
509 } 539 }
510 540
511 // HandleResult is called by ServerBoundCertServiceWorker on the origin message 541 // HandleResult is called by ServerBoundCertServiceWorker on the origin message
512 // loop. It deletes ServerBoundCertServiceJob. 542 // loop. It deletes ServerBoundCertServiceJob.
513 void ServerBoundCertService::HandleResult( 543 void ServerBoundCertService::HandleResult(
514 const std::string& server_identifier, 544 const std::string& server_identifier,
515 int error, 545 int error,
516 scoped_ptr<ServerBoundCertStore::ServerBoundCert> cert) { 546 scoped_ptr<ServerBoundCertStore::ServerBoundCert> cert) {
517 DCHECK(CalledOnValidThread()); 547 DCHECK(CalledOnValidThread());
518 548
(...skipping 19 matching lines...) Expand all
538 else 568 else
539 job->HandleResult(error, CLIENT_CERT_INVALID_TYPE, "", ""); 569 job->HandleResult(error, CLIENT_CERT_INVALID_TYPE, "", "");
540 delete job; 570 delete job;
541 } 571 }
542 572
543 int ServerBoundCertService::cert_count() { 573 int ServerBoundCertService::cert_count() {
544 return server_bound_cert_store_->GetCertCount(); 574 return server_bound_cert_store_->GetCertCount();
545 } 575 }
546 576
547 } // namespace net 577 } // namespace net
OLDNEW
« no previous file with comments | « net/base/server_bound_cert_service.h ('k') | net/base/server_bound_cert_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698