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

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

Issue 1171183002: Use struct AlternativeService in OnAltSvc() and OnSpdyAltSvc() methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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/spdy/spdy_framer.h ('k') | net/spdy/spdy_framer_test.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/spdy/spdy_framer.h" 5 #include "net/spdy/spdy_framer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 10
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/third_party/valgrind/memcheck.h" 13 #include "base/third_party/valgrind/memcheck.h"
14 #include "net/spdy/spdy_alt_svc_wire_format.h"
15 #include "net/spdy/spdy_frame_builder.h" 14 #include "net/spdy/spdy_frame_builder.h"
16 #include "net/spdy/spdy_frame_reader.h" 15 #include "net/spdy/spdy_frame_reader.h"
17 #include "net/spdy/spdy_bitmasks.h" 16 #include "net/spdy/spdy_bitmasks.h"
18 #include "third_party/zlib/zlib.h" 17 #include "third_party/zlib/zlib.h"
19 18
20 using base::StringPiece; 19 using base::StringPiece;
21 using std::string; 20 using std::string;
22 using std::vector; 21 using std::vector;
23 22
24 namespace net { 23 namespace net {
(...skipping 2025 matching lines...) Expand 10 before | Expand all | Expand 10 after
2050 altsvc_scratch_.buffer_length); 2049 altsvc_scratch_.buffer_length);
2051 StringPiece origin; 2050 StringPiece origin;
2052 bool successful_read = reader.ReadStringPiece16(&origin); 2051 bool successful_read = reader.ReadStringPiece16(&origin);
2053 if (!successful_read) { 2052 if (!successful_read) {
2054 set_error(SPDY_INVALID_CONTROL_FRAME); 2053 set_error(SPDY_INVALID_CONTROL_FRAME);
2055 return 0; 2054 return 0;
2056 } 2055 }
2057 StringPiece value(altsvc_scratch_.buffer.get() + reader.GetBytesConsumed(), 2056 StringPiece value(altsvc_scratch_.buffer.get() + reader.GetBytesConsumed(),
2058 altsvc_scratch_.buffer_length - reader.GetBytesConsumed()); 2057 altsvc_scratch_.buffer_length - reader.GetBytesConsumed());
2059 2058
2060 string protocol_id; 2059 SpdyAltSvcWireFormat::AlternativeService altsvc;
2061 string host; 2060 bool success = SpdyAltSvcWireFormat::ParseHeaderFieldValue(value, &altsvc);
2062 uint16 port; 2061 if (!success || altsvc.protocol_id.length() == 0) {
2063 uint32 max_age;
2064 double p;
2065 bool success = SpdyAltSvcWireFormat::ParseHeaderFieldValue(
2066 value, &protocol_id, &host, &port, &max_age, &p);
2067 if (!success || protocol_id.length() == 0) {
2068 set_error(SPDY_INVALID_CONTROL_FRAME); 2062 set_error(SPDY_INVALID_CONTROL_FRAME);
2069 return 0; 2063 return 0;
2070 } 2064 }
2071 2065
2072 // TODO(bnc): Pass on |p|. 2066 visitor_->OnAltSvc(current_frame_stream_id_, origin, altsvc);
2073 visitor_->OnAltSvc(current_frame_stream_id_, max_age, port, protocol_id, host,
2074 origin);
2075 CHANGE_STATE(SPDY_AUTO_RESET); 2067 CHANGE_STATE(SPDY_AUTO_RESET);
2076 return len; 2068 return len;
2077 } 2069 }
2078 2070
2079 size_t SpdyFramer::ProcessDataFramePaddingLength(const char* data, size_t len) { 2071 size_t SpdyFramer::ProcessDataFramePaddingLength(const char* data, size_t len) {
2080 DCHECK_EQ(SPDY_READ_DATA_FRAME_PADDING_LENGTH, state_); 2072 DCHECK_EQ(SPDY_READ_DATA_FRAME_PADDING_LENGTH, state_);
2081 DCHECK_EQ(0u, remaining_padding_payload_length_); 2073 DCHECK_EQ(0u, remaining_padding_payload_length_);
2082 DCHECK_EQ(DATA, current_frame_type_); 2074 DCHECK_EQ(DATA, current_frame_type_);
2083 2075
2084 size_t original_len = len; 2076 size_t original_len = len;
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
2770 2762
2771 builder.WriteBytes(&hpack_encoding[0], hpack_encoding.size()); 2763 builder.WriteBytes(&hpack_encoding[0], hpack_encoding.size());
2772 return builder.take(); 2764 return builder.take();
2773 } 2765 }
2774 2766
2775 SpdyFrame* SpdyFramer::SerializeAltSvc(const SpdyAltSvcIR& altsvc) { 2767 SpdyFrame* SpdyFramer::SerializeAltSvc(const SpdyAltSvcIR& altsvc) {
2776 DCHECK_LT(SPDY3, protocol_version()); 2768 DCHECK_LT(SPDY3, protocol_version());
2777 2769
2778 size_t size = GetAltSvcMinimumSize(); 2770 size_t size = GetAltSvcMinimumSize();
2779 size += altsvc.origin().length(); 2771 size += altsvc.origin().length();
2780 // TODO(bnc): Add probability to SpdyAltSvcIR and pass it on. 2772 string value =
2781 string value = SpdyAltSvcWireFormat::SerializeHeaderFieldValue( 2773 SpdyAltSvcWireFormat::SerializeHeaderFieldValue(altsvc.altsvc());
2782 altsvc.protocol_id(), altsvc.host(), altsvc.port(), altsvc.max_age(),
2783 1.0);
2784 size += value.length(); 2774 size += value.length();
2785 2775
2786 SpdyFrameBuilder builder(size, protocol_version()); 2776 SpdyFrameBuilder builder(size, protocol_version());
2787 builder.BeginNewFrame(*this, ALTSVC, kNoFlags, altsvc.stream_id()); 2777 builder.BeginNewFrame(*this, ALTSVC, kNoFlags, altsvc.stream_id());
2788 2778
2789 builder.WriteUInt16(altsvc.origin().length()); 2779 builder.WriteUInt16(altsvc.origin().length());
2790 builder.WriteBytes(altsvc.origin().data(), altsvc.origin().length()); 2780 builder.WriteBytes(altsvc.origin().data(), altsvc.origin().length());
2791 builder.WriteBytes(value.data(), value.length()); 2781 builder.WriteBytes(value.data(), value.length());
2792 DCHECK_LT(GetAltSvcMinimumSize(), builder.length()); 2782 DCHECK_LT(GetAltSvcMinimumSize(), builder.length());
2793 return builder.take(); 2783 return builder.take();
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
3215 #else 3205 #else
3216 WriteHeaderBlockToZ(&frame.name_value_block(), compressor); 3206 WriteHeaderBlockToZ(&frame.name_value_block(), compressor);
3217 #endif // defined(USE_SYSTEM_ZLIB) 3207 #endif // defined(USE_SYSTEM_ZLIB)
3218 3208
3219 int compressed_size = compressed_max_size - compressor->avail_out; 3209 int compressed_size = compressed_max_size - compressor->avail_out;
3220 builder->Seek(compressed_size); 3210 builder->Seek(compressed_size);
3221 builder->RewriteLength(*this); 3211 builder->RewriteLength(*this);
3222 } 3212 }
3223 3213
3224 } // namespace net 3214 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_framer.h ('k') | net/spdy/spdy_framer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698