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

Side by Side Diff: net/spdy/spdy_session.cc

Issue 10185007: [net] Change order of RequestPriority to natural: higher > lower (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use MINIMUM_PRIORITY instead of 0. Created 8 years, 8 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
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/spdy/spdy_session.h" 5 #include "net/spdy/spdy_session.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 create_stream_queues_[priority].push( 528 create_stream_queues_[priority].push(
529 PendingCreateStream(url, priority, spdy_stream, 529 PendingCreateStream(url, priority, spdy_stream,
530 stream_net_log, callback)); 530 stream_net_log, callback));
531 return ERR_IO_PENDING; 531 return ERR_IO_PENDING;
532 } 532 }
533 533
534 void SpdySession::ProcessPendingCreateStreams() { 534 void SpdySession::ProcessPendingCreateStreams() {
535 while (!max_concurrent_streams_ || 535 while (!max_concurrent_streams_ ||
536 active_streams_.size() < max_concurrent_streams_) { 536 active_streams_.size() < max_concurrent_streams_) {
537 bool no_pending_create_streams = true; 537 bool no_pending_create_streams = true;
538 for (int i = 0;i < NUM_PRIORITIES;++i) { 538 for (int i = NUM_PRIORITIES - 1; i >= MINIMUM_PRIORITY; --i) {
539 if (!create_stream_queues_[i].empty()) { 539 if (!create_stream_queues_[i].empty()) {
540 PendingCreateStream pending_create = create_stream_queues_[i].front(); 540 PendingCreateStream pending_create = create_stream_queues_[i].front();
541 create_stream_queues_[i].pop(); 541 create_stream_queues_[i].pop();
542 no_pending_create_streams = false; 542 no_pending_create_streams = false;
543 int error = CreateStreamImpl(*pending_create.url, 543 int error = CreateStreamImpl(*pending_create.url,
544 pending_create.priority, 544 pending_create.priority,
545 pending_create.spdy_stream, 545 pending_create.spdy_stream,
546 *pending_create.stream_net_log); 546 *pending_create.stream_net_log);
547 scoped_refptr<SpdyStream>* stream = pending_create.spdy_stream; 547 scoped_refptr<SpdyStream>* stream = pending_create.spdy_stream;
548 DCHECK(!ContainsKey(pending_callback_map_, stream)); 548 DCHECK(!ContainsKey(pending_callback_map_, stream));
(...skipping 12 matching lines...) Expand all
561 } 561 }
562 562
563 void SpdySession::CancelPendingCreateStreams( 563 void SpdySession::CancelPendingCreateStreams(
564 const scoped_refptr<SpdyStream>* spdy_stream) { 564 const scoped_refptr<SpdyStream>* spdy_stream) {
565 PendingCallbackMap::iterator it = pending_callback_map_.find(spdy_stream); 565 PendingCallbackMap::iterator it = pending_callback_map_.find(spdy_stream);
566 if (it != pending_callback_map_.end()) { 566 if (it != pending_callback_map_.end()) {
567 pending_callback_map_.erase(it); 567 pending_callback_map_.erase(it);
568 return; 568 return;
569 } 569 }
570 570
571 for (int i = 0;i < NUM_PRIORITIES;++i) { 571 for (int i = 0; i < NUM_PRIORITIES; ++i) {
Ryan Hamilton 2012/04/23 22:51:05 Should this loop be reversed too, like the previou
szym 2012/04/24 00:19:31 This loop is order-agnostic. It goes through all e
572 PendingCreateStreamQueue tmp; 572 PendingCreateStreamQueue tmp;
573 // Make a copy removing this trans 573 // Make a copy removing this trans
574 while (!create_stream_queues_[i].empty()) { 574 while (!create_stream_queues_[i].empty()) {
575 PendingCreateStream pending_create = create_stream_queues_[i].front(); 575 PendingCreateStream pending_create = create_stream_queues_[i].front();
576 create_stream_queues_[i].pop(); 576 create_stream_queues_[i].pop();
577 if (pending_create.spdy_stream != spdy_stream) 577 if (pending_create.spdy_stream != spdy_stream)
578 tmp.push(pending_create); 578 tmp.push(pending_create);
579 } 579 }
580 // Now copy it back 580 // Now copy it back
581 while (!tmp.empty()) { 581 while (!tmp.empty()) {
582 create_stream_queues_[i].push(tmp.front()); 582 create_stream_queues_[i].push(tmp.front());
583 tmp.pop(); 583 tmp.pop();
584 } 584 }
585 } 585 }
586 } 586 }
587 587
588 int SpdySession::CreateStreamImpl( 588 int SpdySession::CreateStreamImpl(
589 const GURL& url, 589 const GURL& url,
590 RequestPriority priority, 590 RequestPriority priority,
591 scoped_refptr<SpdyStream>* spdy_stream, 591 scoped_refptr<SpdyStream>* spdy_stream,
592 const BoundNetLog& stream_net_log) { 592 const BoundNetLog& stream_net_log) {
593 DCHECK_GE(priority, net::MINIMUM_PRIORITY);
Ryan Hamilton 2012/04/23 22:51:05 nit: no need for net:: prefix
szym 2012/04/24 00:19:31 Agreed.
594 DCHECK_LT(priority, net::NUM_PRIORITIES);
595
593 // Make sure that we don't try to send https/wss over an unauthenticated, but 596 // Make sure that we don't try to send https/wss over an unauthenticated, but
594 // encrypted SSL socket. 597 // encrypted SSL socket.
595 if (is_secure_ && certificate_error_code_ != OK && 598 if (is_secure_ && certificate_error_code_ != OK &&
596 (url.SchemeIs("https") || url.SchemeIs("wss"))) { 599 (url.SchemeIs("https") || url.SchemeIs("wss"))) {
597 CloseSessionOnError( 600 CloseSessionOnError(
598 static_cast<net::Error>(certificate_error_code_), 601 static_cast<net::Error>(certificate_error_code_),
599 true, 602 true,
600 "Tried to create SPDY stream for secure content over an " 603 "Tried to create SPDY stream for secure content over an "
601 "unauthenticated session."); 604 "unauthenticated session.");
602 return ERR_SPDY_PROTOCOL_ERROR; 605 return ERR_SPDY_PROTOCOL_ERROR;
(...skipping 12 matching lines...) Expand all
615 stream->set_priority(priority); 618 stream->set_priority(priority);
616 stream->set_path(path); 619 stream->set_path(path);
617 stream->set_send_window_size(initial_send_window_size_); 620 stream->set_send_window_size(initial_send_window_size_);
618 stream->set_recv_window_size(initial_recv_window_size_); 621 stream->set_recv_window_size(initial_recv_window_size_);
619 ActivateStream(stream); 622 ActivateStream(stream);
620 623
621 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdyPriorityCount", 624 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdyPriorityCount",
622 static_cast<int>(priority), 0, 10, 11); 625 static_cast<int>(priority), 0, 10, 11);
623 626
624 // TODO(mbelshe): Optimize memory allocations 627 // TODO(mbelshe): Optimize memory allocations
625 DCHECK(priority >= net::HIGHEST && priority < net::NUM_PRIORITIES);
626 628
627 DCHECK_EQ(active_streams_[stream_id].get(), stream.get()); 629 DCHECK_EQ(active_streams_[stream_id].get(), stream.get());
628 return OK; 630 return OK;
629 } 631 }
630 632
631 bool SpdySession::NeedsCredentials() const { 633 bool SpdySession::NeedsCredentials() const {
632 if (!is_secure_) 634 if (!is_secure_)
633 return false; 635 return false;
634 SSLClientSocket* ssl_socket = GetSSLClientSocket(); 636 SSLClientSocket* ssl_socket = GetSSLClientSocket();
635 if (ssl_socket->GetNegotiatedProtocol() < kProtoSPDY3) 637 if (ssl_socket->GetNegotiatedProtocol() < kProtoSPDY3)
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 net_log().AddEvent( 829 net_log().AddEvent(
828 NetLog::TYPE_SPDY_SESSION_SEND_RST_STREAM, 830 NetLog::TYPE_SPDY_SESSION_SEND_RST_STREAM,
829 make_scoped_refptr(new NetLogSpdyRstParameter(stream_id, status, 831 make_scoped_refptr(new NetLogSpdyRstParameter(stream_id, status,
830 description))); 832 description)));
831 833
832 DCHECK(buffered_spdy_framer_.get()); 834 DCHECK(buffered_spdy_framer_.get());
833 scoped_ptr<SpdyRstStreamControlFrame> rst_frame( 835 scoped_ptr<SpdyRstStreamControlFrame> rst_frame(
834 buffered_spdy_framer_->CreateRstStream(stream_id, status)); 836 buffered_spdy_framer_->CreateRstStream(stream_id, status));
835 837
836 // Default to lowest priority unless we know otherwise. 838 // Default to lowest priority unless we know otherwise.
837 int priority = 3; 839 RequestPriority priority = net::IDLE;
Ryan Hamilton 2012/04/23 22:51:05 nit: no need for net::
szym 2012/04/24 00:19:31 net::IDLE is shadowed by enum SpdySession::State I
Ryan Hamilton 2012/04/24 00:42:11 I see. *shakes fist at C++* I'm looking fwd to c
Ryan Hamilton 2012/04/24 00:42:11 I see. *shakes fist at C++* I'm looking fwd to c
838 if(IsStreamActive(stream_id)) { 840 if(IsStreamActive(stream_id)) {
839 scoped_refptr<SpdyStream> stream = active_streams_[stream_id]; 841 scoped_refptr<SpdyStream> stream = active_streams_[stream_id];
840 priority = stream->priority(); 842 priority = stream->priority();
841 } 843 }
842 QueueFrame(rst_frame.get(), priority, NULL); 844 QueueFrame(rst_frame.get(), priority, NULL);
843 DeleteStream(stream_id, ERR_SPDY_PROTOCOL_ERROR); 845 DeleteStream(stream_id, ERR_SPDY_PROTOCOL_ERROR);
844 } 846 }
845 847
846 bool SpdySession::IsStreamActive(SpdyStreamId stream_id) const { 848 bool SpdySession::IsStreamActive(SpdyStreamId stream_id) const {
847 return ContainsKey(active_streams_, stream_id); 849 return ContainsKey(active_streams_, stream_id);
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 "spdy.abandoned_push_streams"); 1087 "spdy.abandoned_push_streams");
1086 1088
1087 if (!active_streams_.empty()) 1089 if (!active_streams_.empty())
1088 abandoned_streams.Add(active_streams_.size()); 1090 abandoned_streams.Add(active_streams_.size());
1089 if (!unclaimed_pushed_streams_.empty()) { 1091 if (!unclaimed_pushed_streams_.empty()) {
1090 streams_abandoned_count_ += unclaimed_pushed_streams_.size(); 1092 streams_abandoned_count_ += unclaimed_pushed_streams_.size();
1091 abandoned_push_streams.Add(unclaimed_pushed_streams_.size()); 1093 abandoned_push_streams.Add(unclaimed_pushed_streams_.size());
1092 unclaimed_pushed_streams_.clear(); 1094 unclaimed_pushed_streams_.clear();
1093 } 1095 }
1094 1096
1095 for (int i = 0;i < NUM_PRIORITIES;++i) { 1097 for (int i = 0; i < NUM_PRIORITIES; ++i) {
Ryan Hamilton 2012/04/23 22:51:05 Same question about reversing the loop
szym 2012/04/24 00:19:31 Same answer. Order-agnostic, unless the order of c
Ryan Hamilton 2012/04/24 00:42:11 Gotcha. That makes sense.
1096 while (!create_stream_queues_[i].empty()) { 1098 while (!create_stream_queues_[i].empty()) {
1097 PendingCreateStream pending_create = create_stream_queues_[i].front(); 1099 PendingCreateStream pending_create = create_stream_queues_[i].front();
1098 create_stream_queues_[i].pop(); 1100 create_stream_queues_[i].pop();
1099 pending_create.callback.Run(ERR_ABORTED); 1101 pending_create.callback.Run(ERR_ABORTED);
1100 } 1102 }
1101 } 1103 }
1102 1104
1103 while (!active_streams_.empty()) { 1105 while (!active_streams_.empty()) {
1104 ActiveStreamMap::iterator it = active_streams_.begin(); 1106 ActiveStreamMap::iterator it = active_streams_.begin();
1105 const scoped_refptr<SpdyStream>& stream = it->second; 1107 const scoped_refptr<SpdyStream>& stream = it->second;
(...skipping 11 matching lines...) Expand all
1117 1119
1118 int SpdySession::GetNewStreamId() { 1120 int SpdySession::GetNewStreamId() {
1119 int id = stream_hi_water_mark_; 1121 int id = stream_hi_water_mark_;
1120 stream_hi_water_mark_ += 2; 1122 stream_hi_water_mark_ += 2;
1121 if (stream_hi_water_mark_ > 0x7fff) 1123 if (stream_hi_water_mark_ > 0x7fff)
1122 stream_hi_water_mark_ = 1; 1124 stream_hi_water_mark_ = 1;
1123 return id; 1125 return id;
1124 } 1126 }
1125 1127
1126 void SpdySession::QueueFrame(SpdyFrame* frame, 1128 void SpdySession::QueueFrame(SpdyFrame* frame,
1127 SpdyPriority priority, 1129 RequestPriority priority,
1128 SpdyStream* stream) { 1130 SpdyStream* stream) {
1129 int length = SpdyFrame::kHeaderSize + frame->length(); 1131 int length = SpdyFrame::kHeaderSize + frame->length();
1130 IOBuffer* buffer = new IOBuffer(length); 1132 IOBuffer* buffer = new IOBuffer(length);
1131 memcpy(buffer->data(), frame->data(), length); 1133 memcpy(buffer->data(), frame->data(), length);
1132 queue_.push(SpdyIOBuffer(buffer, length, priority, stream)); 1134 queue_.push(SpdyIOBuffer(buffer, length, priority, stream));
1133 1135
1134 WriteSocketLater(); 1136 WriteSocketLater();
1135 } 1137 }
1136 1138
1137 void SpdySession::CloseSessionOnError(net::Error err, 1139 void SpdySession::CloseSessionOnError(net::Error err,
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
1732 1734
1733 net_log_.AddEvent( 1735 net_log_.AddEvent(
1734 NetLog::TYPE_SPDY_SESSION_SEND_SETTINGS, 1736 NetLog::TYPE_SPDY_SESSION_SEND_SETTINGS,
1735 make_scoped_refptr(new NetLogSpdySettingsParameter(settings_map_new))); 1737 make_scoped_refptr(new NetLogSpdySettingsParameter(settings_map_new)));
1736 1738
1737 // Create the SETTINGS frame and send it. 1739 // Create the SETTINGS frame and send it.
1738 DCHECK(buffered_spdy_framer_.get()); 1740 DCHECK(buffered_spdy_framer_.get());
1739 scoped_ptr<SpdySettingsControlFrame> settings_frame( 1741 scoped_ptr<SpdySettingsControlFrame> settings_frame(
1740 buffered_spdy_framer_->CreateSettings(settings_map_new)); 1742 buffered_spdy_framer_->CreateSettings(settings_map_new));
1741 sent_settings_ = true; 1743 sent_settings_ = true;
1742 QueueFrame(settings_frame.get(), 0, NULL); 1744 QueueFrame(settings_frame.get(), HIGHEST, NULL);
1743 } 1745 }
1744 1746
1745 void SpdySession::HandleSetting(uint32 id, uint32 value) { 1747 void SpdySession::HandleSetting(uint32 id, uint32 value) {
1746 switch (id) { 1748 switch (id) {
1747 case SETTINGS_MAX_CONCURRENT_STREAMS: 1749 case SETTINGS_MAX_CONCURRENT_STREAMS:
1748 max_concurrent_streams_ = std::min(static_cast<size_t>(value), 1750 max_concurrent_streams_ = std::min(static_cast<size_t>(value),
1749 g_max_concurrent_stream_limit); 1751 g_max_concurrent_stream_limit);
1750 ProcessPendingCreateStreams(); 1752 ProcessPendingCreateStreams();
1751 break; 1753 break;
1752 case SETTINGS_INITIAL_WINDOW_SIZE: 1754 case SETTINGS_INITIAL_WINDOW_SIZE:
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1809 void SpdySession::SendTrailingPing() { 1811 void SpdySession::SendTrailingPing() {
1810 DCHECK(trailing_ping_pending_); 1812 DCHECK(trailing_ping_pending_);
1811 trailing_ping_pending_ = false; 1813 trailing_ping_pending_ = false;
1812 WritePingFrame(next_ping_id_); 1814 WritePingFrame(next_ping_id_);
1813 } 1815 }
1814 1816
1815 void SpdySession::WritePingFrame(uint32 unique_id) { 1817 void SpdySession::WritePingFrame(uint32 unique_id) {
1816 DCHECK(buffered_spdy_framer_.get()); 1818 DCHECK(buffered_spdy_framer_.get());
1817 scoped_ptr<SpdyPingControlFrame> ping_frame( 1819 scoped_ptr<SpdyPingControlFrame> ping_frame(
1818 buffered_spdy_framer_->CreatePingFrame(next_ping_id_)); 1820 buffered_spdy_framer_->CreatePingFrame(next_ping_id_));
1819 QueueFrame( 1821 QueueFrame(ping_frame.get(), HIGHEST, NULL);
1820 ping_frame.get(), buffered_spdy_framer_->GetHighestPriority(), NULL);
1821 1822
1822 if (net_log().IsLoggingAllEvents()) { 1823 if (net_log().IsLoggingAllEvents()) {
1823 net_log().AddEvent( 1824 net_log().AddEvent(
1824 NetLog::TYPE_SPDY_SESSION_PING, 1825 NetLog::TYPE_SPDY_SESSION_PING,
1825 make_scoped_refptr(new NetLogSpdyPingParameter(next_ping_id_, "sent"))); 1826 make_scoped_refptr(new NetLogSpdyPingParameter(next_ping_id_, "sent")));
1826 } 1827 }
1827 if (unique_id % 2 != 0) { 1828 if (unique_id % 2 != 0) {
1828 next_ping_id_ += 2; 1829 next_ping_id_ += 2;
1829 ++pings_in_flight_; 1830 ++pings_in_flight_;
1830 need_to_send_ping_ = false; 1831 need_to_send_ping_ = false;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1964 SSLClientSocket* SpdySession::GetSSLClientSocket() const { 1965 SSLClientSocket* SpdySession::GetSSLClientSocket() const {
1965 if (!is_secure_) 1966 if (!is_secure_)
1966 return NULL; 1967 return NULL;
1967 SSLClientSocket* ssl_socket = 1968 SSLClientSocket* ssl_socket =
1968 reinterpret_cast<SSLClientSocket*>(connection_->socket()); 1969 reinterpret_cast<SSLClientSocket*>(connection_->socket());
1969 DCHECK(ssl_socket); 1970 DCHECK(ssl_socket);
1970 return ssl_socket; 1971 return ssl_socket;
1971 } 1972 }
1972 1973
1973 } // namespace net 1974 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698