OLD | NEW |
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/spdy/spdy_stream.h" | 5 #include "net/spdy/spdy_stream.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 delegate_(NULL), | 83 delegate_(NULL), |
84 request_time_(base::Time::Now()), | 84 request_time_(base::Time::Now()), |
85 response_(new spdy::SpdyHeaderBlock), | 85 response_(new spdy::SpdyHeaderBlock), |
86 io_state_(STATE_NONE), | 86 io_state_(STATE_NONE), |
87 response_status_(OK), | 87 response_status_(OK), |
88 cancelled_(false), | 88 cancelled_(false), |
89 has_upload_data_(false), | 89 has_upload_data_(false), |
90 net_log_(net_log), | 90 net_log_(net_log), |
91 send_bytes_(0), | 91 send_bytes_(0), |
92 recv_bytes_(0), | 92 recv_bytes_(0), |
93 ob_cert_type_(CLIENT_CERT_INVALID_TYPE) { | 93 domain_bound_cert_type_(CLIENT_CERT_INVALID_TYPE) { |
94 } | 94 } |
95 | 95 |
96 SpdyStream::~SpdyStream() { | 96 SpdyStream::~SpdyStream() { |
97 UpdateHistograms(); | 97 UpdateHistograms(); |
98 } | 98 } |
99 | 99 |
100 void SpdyStream::SetDelegate(Delegate* delegate) { | 100 void SpdyStream::SetDelegate(Delegate* delegate) { |
101 CHECK(delegate); | 101 CHECK(delegate); |
102 delegate_ = delegate; | 102 delegate_ = delegate; |
103 | 103 |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 // STATE_DONE. However, we still want to return IO_PENDING to mimic non-push | 483 // STATE_DONE. However, we still want to return IO_PENDING to mimic non-push |
484 // behavior. | 484 // behavior. |
485 has_upload_data_ = has_upload_data; | 485 has_upload_data_ = has_upload_data; |
486 if (pushed_) { | 486 if (pushed_) { |
487 send_time_ = base::TimeTicks::Now(); | 487 send_time_ = base::TimeTicks::Now(); |
488 DCHECK(!has_upload_data_); | 488 DCHECK(!has_upload_data_); |
489 DCHECK(response_received()); | 489 DCHECK(response_received()); |
490 return ERR_IO_PENDING; | 490 return ERR_IO_PENDING; |
491 } | 491 } |
492 CHECK_EQ(STATE_NONE, io_state_); | 492 CHECK_EQ(STATE_NONE, io_state_); |
493 io_state_ = STATE_GET_ORIGIN_BOUND_CERT; | 493 io_state_ = STATE_GET_DOMAIN_BOUND_CERT; |
494 return DoLoop(OK); | 494 return DoLoop(OK); |
495 } | 495 } |
496 | 496 |
497 int SpdyStream::WriteStreamData(IOBuffer* data, int length, | 497 int SpdyStream::WriteStreamData(IOBuffer* data, int length, |
498 spdy::SpdyDataFlags flags) { | 498 spdy::SpdyDataFlags flags) { |
499 return session_->WriteStreamData(stream_id_, data, length, flags); | 499 return session_->WriteStreamData(stream_id_, data, length, flags); |
500 } | 500 } |
501 | 501 |
502 bool SpdyStream::GetSSLInfo(SSLInfo* ssl_info, | 502 bool SpdyStream::GetSSLInfo(SSLInfo* ssl_info, |
503 bool* was_npn_negotiated, | 503 bool* was_npn_negotiated, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 it = headers->find(host_header); | 552 it = headers->find(host_header); |
553 if (it != (*headers).end()) | 553 if (it != (*headers).end()) |
554 host_port = it->second; | 554 host_port = it->second; |
555 it = headers->find(path_header); | 555 it = headers->find(path_header); |
556 if (it != (*headers).end()) | 556 if (it != (*headers).end()) |
557 path = it->second; | 557 path = it->second; |
558 std::string url = scheme + "://" + host_port + path; | 558 std::string url = scheme + "://" + host_port + path; |
559 return GURL(url); | 559 return GURL(url); |
560 } | 560 } |
561 | 561 |
562 void SpdyStream::OnGetOriginBoundCertComplete(int result) { | 562 void SpdyStream::OnGetDomainBoundCertComplete(int result) { |
563 DCHECK_EQ(STATE_GET_ORIGIN_BOUND_CERT_COMPLETE, io_state_); | 563 DCHECK_EQ(STATE_GET_DOMAIN_BOUND_CERT_COMPLETE, io_state_); |
564 DoLoop(result); | 564 DoLoop(result); |
565 } | 565 } |
566 | 566 |
567 int SpdyStream::DoLoop(int result) { | 567 int SpdyStream::DoLoop(int result) { |
568 do { | 568 do { |
569 State state = io_state_; | 569 State state = io_state_; |
570 io_state_ = STATE_NONE; | 570 io_state_ = STATE_NONE; |
571 switch (state) { | 571 switch (state) { |
572 // State machine 1: Send headers and body. | 572 // State machine 1: Send headers and body. |
573 case STATE_GET_ORIGIN_BOUND_CERT: | 573 case STATE_GET_DOMAIN_BOUND_CERT: |
574 CHECK_EQ(OK, result); | 574 CHECK_EQ(OK, result); |
575 result = DoGetOriginBoundCert(); | 575 result = DoGetDomainBoundCert(); |
576 break; | 576 break; |
577 case STATE_GET_ORIGIN_BOUND_CERT_COMPLETE: | 577 case STATE_GET_DOMAIN_BOUND_CERT_COMPLETE: |
578 result = DoGetOriginBoundCertComplete(result); | 578 result = DoGetDomainBoundCertComplete(result); |
579 break; | 579 break; |
580 case STATE_SEND_ORIGIN_BOUND_CERT: | 580 case STATE_SEND_DOMAIN_BOUND_CERT: |
581 CHECK_EQ(OK, result); | 581 CHECK_EQ(OK, result); |
582 result = DoSendOriginBoundCert(); | 582 result = DoSendDomainBoundCert(); |
583 break; | 583 break; |
584 case STATE_SEND_ORIGIN_BOUND_CERT_COMPLETE: | 584 case STATE_SEND_DOMAIN_BOUND_CERT_COMPLETE: |
585 result = DoSendOriginBoundCertComplete(result); | 585 result = DoSendDomainBoundCertComplete(result); |
586 break; | 586 break; |
587 case STATE_SEND_HEADERS: | 587 case STATE_SEND_HEADERS: |
588 CHECK_EQ(OK, result); | 588 CHECK_EQ(OK, result); |
589 result = DoSendHeaders(); | 589 result = DoSendHeaders(); |
590 break; | 590 break; |
591 case STATE_SEND_HEADERS_COMPLETE: | 591 case STATE_SEND_HEADERS_COMPLETE: |
592 result = DoSendHeadersComplete(result); | 592 result = DoSendHeadersComplete(result); |
593 break; | 593 break; |
594 case STATE_SEND_BODY: | 594 case STATE_SEND_BODY: |
595 CHECK_EQ(OK, result); | 595 CHECK_EQ(OK, result); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 default: | 628 default: |
629 NOTREACHED() << io_state_; | 629 NOTREACHED() << io_state_; |
630 break; | 630 break; |
631 } | 631 } |
632 } while (result != ERR_IO_PENDING && io_state_ != STATE_NONE && | 632 } while (result != ERR_IO_PENDING && io_state_ != STATE_NONE && |
633 io_state_ != STATE_OPEN); | 633 io_state_ != STATE_OPEN); |
634 | 634 |
635 return result; | 635 return result; |
636 } | 636 } |
637 | 637 |
638 int SpdyStream::DoGetOriginBoundCert() { | 638 int SpdyStream::DoGetDomainBoundCert() { |
639 CHECK(request_.get()); | 639 CHECK(request_.get()); |
640 HostPortPair origin(HostPortPair::FromURL(GetUrl())); | 640 HostPortPair origin(HostPortPair::FromURL(GetUrl())); |
641 if (!session_->NeedsCredentials(origin)) { | 641 if (!session_->NeedsCredentials(origin)) { |
642 // Proceed directly to sending headers | 642 // Proceed directly to sending headers |
643 io_state_ = STATE_SEND_HEADERS; | 643 io_state_ = STATE_SEND_HEADERS; |
644 return OK; | 644 return OK; |
645 } | 645 } |
646 | 646 |
647 io_state_ = STATE_GET_ORIGIN_BOUND_CERT_COMPLETE; | 647 io_state_ = STATE_GET_DOMAIN_BOUND_CERT_COMPLETE; |
648 OriginBoundCertService* obc_service = session_->GetOriginBoundCertService(); | 648 ServerBoundCertService* sbc_service = session_->GetServerBoundCertService(); |
649 DCHECK(obc_service != NULL); | 649 DCHECK(sbc_service != NULL); |
650 std::vector<uint8> requested_cert_types; | 650 std::vector<uint8> requested_cert_types; |
651 requested_cert_types.push_back(session_->GetOriginBoundCertType()); | 651 requested_cert_types.push_back(session_->GetDomainBoundCertType()); |
652 int rv = obc_service->GetOriginBoundCert( | 652 int rv = sbc_service->GetDomainBoundCert( |
653 GetUrl().GetOrigin().spec(), requested_cert_types, &ob_cert_type_, | 653 GetUrl().GetOrigin().spec(), requested_cert_types, |
654 &ob_private_key_, &ob_cert_, | 654 &domain_bound_cert_type_, &domain_bound_private_key_, &domain_bound_cert_, |
655 base::Bind(&SpdyStream::OnGetOriginBoundCertComplete, | 655 base::Bind(&SpdyStream::OnGetDomainBoundCertComplete, |
656 base::Unretained(this)), | 656 base::Unretained(this)), |
657 &ob_cert_request_handle_); | 657 &domain_bound_cert_request_handle_); |
658 return rv; | 658 return rv; |
659 } | 659 } |
660 | 660 |
661 int SpdyStream::DoGetOriginBoundCertComplete(int result) { | 661 int SpdyStream::DoGetDomainBoundCertComplete(int result) { |
662 if (result != OK) | 662 if (result != OK) |
663 return result; | 663 return result; |
664 | 664 |
665 io_state_ = STATE_SEND_ORIGIN_BOUND_CERT; | 665 io_state_ = STATE_SEND_DOMAIN_BOUND_CERT; |
666 return OK; | 666 return OK; |
667 } | 667 } |
668 | 668 |
669 int SpdyStream::DoSendOriginBoundCert() { | 669 int SpdyStream::DoSendDomainBoundCert() { |
670 io_state_ = STATE_SEND_ORIGIN_BOUND_CERT_COMPLETE; | 670 io_state_ = STATE_SEND_DOMAIN_BOUND_CERT_COMPLETE; |
671 CHECK(request_.get()); | 671 CHECK(request_.get()); |
672 std::string origin = GetUrl().GetOrigin().spec(); | 672 std::string origin = GetUrl().GetOrigin().spec(); |
673 origin.erase(origin.length() - 1); // trim trailing slash | 673 origin.erase(origin.length() - 1); // trim trailing slash |
674 int rv = session_->WriteCredentialFrame( | 674 int rv = session_->WriteCredentialFrame( |
675 origin, ob_cert_type_, ob_private_key_, ob_cert_, | 675 origin, domain_bound_cert_type_, domain_bound_private_key_, |
676 static_cast<RequestPriority>(priority_)); | 676 domain_bound_cert_, static_cast<RequestPriority>(priority_)); |
677 if (rv != ERR_IO_PENDING) | 677 if (rv != ERR_IO_PENDING) |
678 return rv; | 678 return rv; |
679 return OK; | 679 return OK; |
680 } | 680 } |
681 | 681 |
682 int SpdyStream::DoSendOriginBoundCertComplete(int result) { | 682 int SpdyStream::DoSendDomainBoundCertComplete(int result) { |
683 if (result < 0) | 683 if (result < 0) |
684 return result; | 684 return result; |
685 | 685 |
686 io_state_ = STATE_SEND_HEADERS; | 686 io_state_ = STATE_SEND_HEADERS; |
687 return OK; | 687 return OK; |
688 } | 688 } |
689 | 689 |
690 int SpdyStream::DoSendHeaders() { | 690 int SpdyStream::DoSendHeaders() { |
691 CHECK(!cancelled_); | 691 CHECK(!cancelled_); |
692 | 692 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 UMA_HISTOGRAM_TIMES("Net.SpdyStreamDownloadTime", | 774 UMA_HISTOGRAM_TIMES("Net.SpdyStreamDownloadTime", |
775 recv_last_byte_time_ - recv_first_byte_time_); | 775 recv_last_byte_time_ - recv_first_byte_time_); |
776 UMA_HISTOGRAM_TIMES("Net.SpdyStreamTime", | 776 UMA_HISTOGRAM_TIMES("Net.SpdyStreamTime", |
777 recv_last_byte_time_ - send_time_); | 777 recv_last_byte_time_ - send_time_); |
778 | 778 |
779 UMA_HISTOGRAM_COUNTS("Net.SpdySendBytes", send_bytes_); | 779 UMA_HISTOGRAM_COUNTS("Net.SpdySendBytes", send_bytes_); |
780 UMA_HISTOGRAM_COUNTS("Net.SpdyRecvBytes", recv_bytes_); | 780 UMA_HISTOGRAM_COUNTS("Net.SpdyRecvBytes", recv_bytes_); |
781 } | 781 } |
782 | 782 |
783 } // namespace net | 783 } // namespace net |
OLD | NEW |