Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / net / spdy / spdy_read_queue.cc
blob627bf5b83b421e2ca513dd8666500cc490cbeff4
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.
5 #include "net/spdy/spdy_read_queue.h"
7 #include "base/logging.h"
8 #include "base/stl_util.h"
9 #include "net/spdy/spdy_buffer.h"
11 namespace net {
13 SpdyReadQueue::SpdyReadQueue() : total_size_(0) {}
15 SpdyReadQueue::~SpdyReadQueue() {
16 Clear();
19 bool SpdyReadQueue::IsEmpty() const {
20 DCHECK_EQ(queue_.empty(), total_size_ == 0);
21 return queue_.empty();
24 size_t SpdyReadQueue::GetTotalSize() const {
25 return total_size_;
28 void SpdyReadQueue::Enqueue(scoped_ptr<SpdyBuffer> buffer) {
29 DCHECK_GT(buffer->GetRemainingSize(), 0u);
30 total_size_ += buffer->GetRemainingSize();
31 queue_.push_back(buffer.release());
34 size_t SpdyReadQueue::Dequeue(char* out, size_t len) {
35 DCHECK_GT(len, 0u);
36 size_t bytes_copied = 0;
37 while (!queue_.empty() && bytes_copied < len) {
38 SpdyBuffer* buffer = queue_.front();
39 size_t bytes_to_copy =
40 std::min(len - bytes_copied, buffer->GetRemainingSize());
41 memcpy(out + bytes_copied, buffer->GetRemainingData(), bytes_to_copy);
42 bytes_copied += bytes_to_copy;
43 if (bytes_to_copy == buffer->GetRemainingSize()) {
44 delete queue_.front();
45 queue_.pop_front();
46 } else {
47 buffer->Consume(bytes_to_copy);
50 total_size_ -= bytes_copied;
51 return bytes_copied;
54 void SpdyReadQueue::Clear() {
55 STLDeleteElements(&queue_);
58 } // namespace net