| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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_buffer.h" | 5 #include "net/spdy/spdy_buffer.h" |
| 6 | 6 |
| 7 #include <cstring> | 7 #include <cstring> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
| 14 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h" |
| 14 #include "net/spdy/spdy_protocol.h" | 15 #include "net/spdy/spdy_protocol.h" |
| 15 | 16 |
| 16 namespace net { | 17 namespace net { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 // Bound on largest frame any SPDY version has allowed. | 21 // Bound on largest frame any SPDY version has allowed. |
| 21 const size_t kMaxSpdyFrameSize = 0x00ffffff; | 22 const size_t kMaxSpdyFrameSize = 0x00ffffff; |
| 22 | 23 |
| 23 // Makes a SpdySerializedFrame with |size| bytes of data copied from |data|. | 24 // Makes a SpdySerializedFrame with |size| bytes of data copied from |data|. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } | 91 } |
| 91 | 92 |
| 92 void SpdyBuffer::Consume(size_t consume_size) { | 93 void SpdyBuffer::Consume(size_t consume_size) { |
| 93 ConsumeHelper(consume_size, CONSUME); | 94 ConsumeHelper(consume_size, CONSUME); |
| 94 }; | 95 }; |
| 95 | 96 |
| 96 IOBuffer* SpdyBuffer::GetIOBufferForRemainingData() { | 97 IOBuffer* SpdyBuffer::GetIOBufferForRemainingData() { |
| 97 return new SharedFrameIOBuffer(shared_frame_, offset_); | 98 return new SharedFrameIOBuffer(shared_frame_, offset_); |
| 98 } | 99 } |
| 99 | 100 |
| 101 size_t SpdyBuffer::EstimateMemoryUsage() const { |
| 102 // TODO(xunjieli): Estimate |consume_callbacks_|. https://crbug.com/669108. |
| 103 return SpdyEstimateMemoryUsage(shared_frame_->data); |
| 104 } |
| 105 |
| 100 void SpdyBuffer::ConsumeHelper(size_t consume_size, | 106 void SpdyBuffer::ConsumeHelper(size_t consume_size, |
| 101 ConsumeSource consume_source) { | 107 ConsumeSource consume_source) { |
| 102 DCHECK_GE(consume_size, 1u); | 108 DCHECK_GE(consume_size, 1u); |
| 103 DCHECK_LE(consume_size, GetRemainingSize()); | 109 DCHECK_LE(consume_size, GetRemainingSize()); |
| 104 offset_ += consume_size; | 110 offset_ += consume_size; |
| 105 for (std::vector<ConsumeCallback>::const_iterator it = | 111 for (std::vector<ConsumeCallback>::const_iterator it = |
| 106 consume_callbacks_.begin(); it != consume_callbacks_.end(); ++it) { | 112 consume_callbacks_.begin(); it != consume_callbacks_.end(); ++it) { |
| 107 it->Run(consume_size, consume_source); | 113 it->Run(consume_size, consume_source); |
| 108 } | 114 } |
| 109 }; | 115 }; |
| 110 | 116 |
| 111 } // namespace net | 117 } // namespace net |
| OLD | NEW |