summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-23 19:34:15 +0000
committerrch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-23 19:34:15 +0000
commit86ca526233473fbc44c02e342d11513e4afc4761 (patch)
tree561767c65b6c12c2996f35e8c57e0f9f2470b151
parentaa4d9e4710dca9f41f2fcea256b996421b10912f (diff)
downloadchromium_src-86ca526233473fbc44c02e342d11513e4afc4761.zip
chromium_src-86ca526233473fbc44c02e342d11513e4afc4761.tar.gz
chromium_src-86ca526233473fbc44c02e342d11513e4afc4761.tar.bz2
Remove SpdyFramer::CompressFrame() and use CompressControlFrame instead.
Review URL: http://codereview.chromium.org/10138003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133496 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/spdy/buffered_spdy_framer.cc9
-rw-r--r--net/spdy/buffered_spdy_framer.h2
-rw-r--r--net/spdy/spdy_framer.cc39
-rw-r--r--net/spdy/spdy_framer.h6
-rw-r--r--net/spdy/spdy_framer_test.cc14
-rw-r--r--net/spdy/spdy_session.cc4
6 files changed, 42 insertions, 32 deletions
diff --git a/net/spdy/buffered_spdy_framer.cc b/net/spdy/buffered_spdy_framer.cc
index a71155f..1839b52 100644
--- a/net/spdy/buffered_spdy_framer.cc
+++ b/net/spdy/buffered_spdy_framer.cc
@@ -241,14 +241,15 @@ SpdyPriority BufferedSpdyFramer::GetHighestPriority() const {
return spdy_framer_.GetHighestPriority();
}
-SpdyFrame* BufferedSpdyFramer::CompressFrame(const SpdyFrame& frame) {
- return spdy_framer_.CompressFrame(frame);
-}
-
bool BufferedSpdyFramer::IsCompressible(const SpdyFrame& frame) const {
return spdy_framer_.IsCompressible(frame);
}
+SpdyControlFrame* BufferedSpdyFramer::CompressControlFrame(
+ const SpdyControlFrame& frame) {
+ return spdy_framer_.CompressControlFrame(frame);
+}
+
void BufferedSpdyFramer::InitHeaderStreaming(const SpdyControlFrame* frame) {
memset(header_buffer_, 0, kHeaderBufferSize);
header_buffer_used_ = 0;
diff --git a/net/spdy/buffered_spdy_framer.h b/net/spdy/buffered_spdy_framer.h
index 5954f72..880f972 100644
--- a/net/spdy/buffered_spdy_framer.h
+++ b/net/spdy/buffered_spdy_framer.h
@@ -140,8 +140,8 @@ class NET_EXPORT_PRIVATE BufferedSpdyFramer
uint32 len,
SpdyDataFlags flags);
SpdyPriority GetHighestPriority() const;
- SpdyFrame* CompressFrame(const SpdyFrame& frame);
bool IsCompressible(const SpdyFrame& frame) const;
+ SpdyControlFrame* CompressControlFrame(const SpdyControlFrame& frame);
int frames_received() const { return frames_received_; }
diff --git a/net/spdy/spdy_framer.cc b/net/spdy/spdy_framer.cc
index 57cc48b..929bf15 100644
--- a/net/spdy/spdy_framer.cc
+++ b/net/spdy/spdy_framer.cc
@@ -1257,29 +1257,6 @@ static const int kCompressorLevel = 9;
static const int kCompressorWindowSizeInBits = 11;
static const int kCompressorMemLevel = 1;
-SpdyFrame* SpdyFramer::CompressFrame(const SpdyFrame& frame) {
- if (frame.is_control_frame()) {
- return CompressControlFrame(
- reinterpret_cast<const SpdyControlFrame&>(frame));
- }
- return NULL;
-}
-
-bool SpdyFramer::IsCompressible(const SpdyFrame& frame) const {
- // The important frames to compress are those which contain large
- // amounts of compressible data - namely the headers in the SYN_STREAM
- // and SYN_REPLY.
- if (frame.is_control_frame()) {
- const SpdyControlFrame& control_frame =
- reinterpret_cast<const SpdyControlFrame&>(frame);
- return control_frame.type() == SYN_STREAM ||
- control_frame.type() == SYN_REPLY;
- }
-
- // We don't compress Data frames.
- return false;
-}
-
z_stream* SpdyFramer::GetHeaderCompressor() {
if (header_compressor_.get())
return header_compressor_.get(); // Already initialized.
@@ -1554,6 +1531,22 @@ SpdyFrame* SpdyFramer::DuplicateFrame(const SpdyFrame& frame) {
return new_frame;
}
+bool SpdyFramer::IsCompressible(const SpdyFrame& frame) const {
+ // The important frames to compress are those which contain large
+ // amounts of compressible data - namely the headers in the SYN_STREAM
+ // and SYN_REPLY.
+ if (frame.is_control_frame()) {
+ const SpdyControlFrame& control_frame =
+ reinterpret_cast<const SpdyControlFrame&>(frame);
+ return control_frame.type() == SYN_STREAM ||
+ control_frame.type() == SYN_REPLY ||
+ control_frame.type() == HEADERS;
+ }
+
+ // We don't compress Data frames.
+ return false;
+}
+
size_t SpdyFramer::GetMinimumControlFrameSize(int version,
SpdyControlType type) {
switch (type) {
diff --git a/net/spdy/spdy_framer.h b/net/spdy/spdy_framer.h
index 7609491..fc05e90 100644
--- a/net/spdy/spdy_framer.h
+++ b/net/spdy/spdy_framer.h
@@ -386,6 +386,9 @@ class NET_EXPORT_PRIVATE SpdyFramer {
// Returns true if a frame could be compressed.
bool IsCompressible(const SpdyFrame& frame) const;
+ // Returns a new SpdyControlFrame with the compressed payload of |frame|.
+ SpdyControlFrame* CompressControlFrame(const SpdyControlFrame& frame);
+
// Get the minimum size of the control frame for the given control frame
// type. This is useful for validating frame blocks.
static size_t GetMinimumControlFrameSize(int version, SpdyControlType type);
@@ -465,9 +468,6 @@ class NET_EXPORT_PRIVATE SpdyFramer {
z_stream* GetHeaderCompressor();
z_stream* GetHeaderDecompressor();
- // Compression helpers
- SpdyControlFrame* CompressControlFrame(const SpdyControlFrame& frame);
-
// Deliver the given control frame's compressed headers block to the visitor
// in decompressed form, in chunks. Returns true if the visitor has
// accepted all of the chunks.
diff --git a/net/spdy/spdy_framer_test.cc b/net/spdy/spdy_framer_test.cc
index 9279539..1a03ed7 100644
--- a/net/spdy/spdy_framer_test.cc
+++ b/net/spdy/spdy_framer_test.cc
@@ -538,6 +538,20 @@ INSTANTIATE_TEST_CASE_P(SpdyFramerTests,
SpdyFramerTest,
::testing::Values(SPDY2, SPDY3));
+TEST_P(SpdyFramerTest, IsCompressible) {
+ SpdyFramer framer(spdy_version_);
+ for (SpdyControlType type = SYN_STREAM;
+ type < NUM_CONTROL_FRAME_TYPES;
+ type = static_cast<SpdyControlType>(type + 1)) {
+ SpdyFrameBuilder frame(type, CONTROL_FLAG_NONE, spdy_version_, 1024);
+ scoped_ptr<SpdyControlFrame> control_frame(
+ reinterpret_cast<SpdyControlFrame*>(frame.take()));
+ EXPECT_EQ(control_frame->has_header_block(),
+ framer.IsCompressible(*control_frame))
+ << "Frame type: " << type;
+ }
+}
+
// Test that we can encode and decode a SpdyHeaderBlock in serialized form.
TEST_P(SpdyFramerTest, HeaderBlockInBuffer) {
SpdyHeaderBlock headers;
diff --git a/net/spdy/spdy_session.cc b/net/spdy/spdy_session.cc
index be67c99..278fa25 100644
--- a/net/spdy/spdy_session.cc
+++ b/net/spdy/spdy_session.cc
@@ -1035,8 +1035,10 @@ void SpdySession::WriteSocket() {
SpdyFrame uncompressed_frame(next_buffer.buffer()->data(), false);
size_t size;
if (buffered_spdy_framer_->IsCompressible(uncompressed_frame)) {
+ DCHECK(uncompressed_frame.is_control_frame());
scoped_ptr<SpdyFrame> compressed_frame(
- buffered_spdy_framer_->CompressFrame(uncompressed_frame));
+ buffered_spdy_framer_->CompressControlFrame(
+ reinterpret_cast<const SpdyControlFrame&>(uncompressed_frame)));
if (!compressed_frame.get()) {
CloseSessionOnError(
net::ERR_SPDY_PROTOCOL_ERROR, true, "SPDY Compression failure.");