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

Unified Diff: net/spdy/spdy_buffer.cc

Issue 2832973003: Split net/spdy into core and chromium subdirectories. (Closed)
Patch Set: Fix some more build rules. Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/spdy/spdy_buffer.h ('k') | net/spdy/spdy_buffer_producer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/spdy/spdy_buffer.cc
diff --git a/net/spdy/spdy_buffer.cc b/net/spdy/spdy_buffer.cc
deleted file mode 100644
index 1c2d6ede6b022681b7a2236849bd950cd0713c2b..0000000000000000000000000000000000000000
--- a/net/spdy/spdy_buffer.cc
+++ /dev/null
@@ -1,117 +0,0 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "net/spdy/spdy_buffer.h"
-
-#include <cstring>
-#include <utility>
-
-#include "base/callback.h"
-#include "base/logging.h"
-#include "base/macros.h"
-#include "net/base/io_buffer.h"
-#include "net/spdy/platform/api/spdy_estimate_memory_usage.h"
-#include "net/spdy/spdy_protocol.h"
-
-namespace net {
-
-namespace {
-
-// Bound on largest frame any SPDY version has allowed.
-const size_t kMaxSpdyFrameSize = 0x00ffffff;
-
-// Makes a SpdySerializedFrame with |size| bytes of data copied from |data|.
-// |data| must be non-NULL and |size| must be positive.
-std::unique_ptr<SpdySerializedFrame> MakeSpdySerializedFrame(const char* data,
- size_t size) {
- DCHECK(data);
- CHECK_GT(size, 0u);
- CHECK_LE(size, kMaxSpdyFrameSize);
- std::unique_ptr<char[]> frame_data(new char[size]);
- std::memcpy(frame_data.get(), data, size);
- std::unique_ptr<SpdySerializedFrame> frame(new SpdySerializedFrame(
- frame_data.release(), size, true /* owns_buffer */));
- return frame;
-}
-
-} // namespace
-
-// This class is an IOBuffer implementation that simply holds a
-// reference to a SharedFrame object and a fixed offset. Used by
-// SpdyBuffer::GetIOBufferForRemainingData().
-class SpdyBuffer::SharedFrameIOBuffer : public IOBuffer {
- public:
- SharedFrameIOBuffer(const scoped_refptr<SharedFrame>& shared_frame,
- size_t offset)
- : IOBuffer(shared_frame->data->data() + offset),
- shared_frame_(shared_frame) {}
-
- private:
- ~SharedFrameIOBuffer() override {
- // Prevent ~IOBuffer() from trying to delete |data_|.
- data_ = NULL;
- }
-
- const scoped_refptr<SharedFrame> shared_frame_;
-
- DISALLOW_COPY_AND_ASSIGN(SharedFrameIOBuffer);
-};
-
-SpdyBuffer::SpdyBuffer(std::unique_ptr<SpdySerializedFrame> frame)
- : shared_frame_(new SharedFrame()), offset_(0) {
- shared_frame_->data = std::move(frame);
-}
-
-// The given data may not be strictly a SPDY frame; we (ab)use
-// |frame_| just as a container.
-SpdyBuffer::SpdyBuffer(const char* data, size_t size) :
- shared_frame_(new SharedFrame()),
- offset_(0) {
- CHECK_GT(size, 0u);
- CHECK_LE(size, kMaxSpdyFrameSize);
- shared_frame_->data = MakeSpdySerializedFrame(data, size);
-}
-
-SpdyBuffer::~SpdyBuffer() {
- if (GetRemainingSize() > 0)
- ConsumeHelper(GetRemainingSize(), DISCARD);
-}
-
-const char* SpdyBuffer::GetRemainingData() const {
- return shared_frame_->data->data() + offset_;
-}
-
-size_t SpdyBuffer::GetRemainingSize() const {
- return shared_frame_->data->size() - offset_;
-}
-
-void SpdyBuffer::AddConsumeCallback(const ConsumeCallback& consume_callback) {
- consume_callbacks_.push_back(consume_callback);
-}
-
-void SpdyBuffer::Consume(size_t consume_size) {
- ConsumeHelper(consume_size, CONSUME);
-};
-
-IOBuffer* SpdyBuffer::GetIOBufferForRemainingData() {
- return new SharedFrameIOBuffer(shared_frame_, offset_);
-}
-
-size_t SpdyBuffer::EstimateMemoryUsage() const {
- // TODO(xunjieli): Estimate |consume_callbacks_|. https://crbug.com/669108.
- return SpdyEstimateMemoryUsage(shared_frame_->data);
-}
-
-void SpdyBuffer::ConsumeHelper(size_t consume_size,
- ConsumeSource consume_source) {
- DCHECK_GE(consume_size, 1u);
- DCHECK_LE(consume_size, GetRemainingSize());
- offset_ += consume_size;
- for (std::vector<ConsumeCallback>::const_iterator it =
- consume_callbacks_.begin(); it != consume_callbacks_.end(); ++it) {
- it->Run(consume_size, consume_source);
- }
-};
-
-} // namespace net
« 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