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

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

Issue 13990005: [SPDY] Replace SpdyIOBuffer with new SpdyBuffer class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix missing include Created 7 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
« no previous file with comments | « net/spdy/spdy_buffer.h ('k') | net/spdy/spdy_buffer_producer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/spdy/spdy_buffer.h"
6
7 #include <cstring>
8
9 #include "base/logging.h"
10 #include "net/base/io_buffer.h"
11 #include "net/spdy/spdy_protocol.h"
12
13 namespace net {
14
15 namespace {
16
17 // Makes a SpdyFrame with |size| bytes of data copied from
18 // |data|. |data| must be non-NULL and |size| must be positive.
19 scoped_ptr<SpdyFrame> MakeSpdyFrame(const char* data, size_t size) {
20 DCHECK(data);
21 DCHECK_GT(size, 0u);
22 scoped_array<char> frame_data(new char[size]);
23 std::memcpy(frame_data.get(), data, size);
24 scoped_ptr<SpdyFrame> frame(
25 new SpdyFrame(frame_data.release(), size, true /* owns_buffer */));
26 return frame.Pass();
27 }
28
29 } // namespace
30
31 SpdyBuffer::SpdyBuffer(scoped_ptr<SpdyFrame> frame)
32 : frame_(frame.Pass()),
33 offset_(0) {}
34
35 // The given data may not be strictly a SPDY frame; we (ab)use
36 // |frame_| just as a container.
37 SpdyBuffer::SpdyBuffer(const char* data, size_t size) :
38 frame_(MakeSpdyFrame(data, size)),
39 offset_(0) {}
40
41 SpdyBuffer::~SpdyBuffer() {}
42
43 const char* SpdyBuffer::GetRemainingData() const {
44 return frame_->data() + offset_;
45 }
46
47 size_t SpdyBuffer::GetRemainingSize() const {
48 return frame_->size() - offset_;
49 }
50
51 void SpdyBuffer::Consume(size_t consume_size) {
52 DCHECK_GE(consume_size, 1u);
53 DCHECK_LE(consume_size, GetRemainingSize());
54 offset_ += consume_size;
55 };
56
57 IOBuffer* SpdyBuffer::GetIOBufferForRemainingData() {
58 return new WrappedIOBuffer(GetRemainingData());
59 }
60
61 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_buffer.h ('k') | net/spdy/spdy_buffer_producer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698