OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/speech/chunked_byte_buffer.h" | 5 #include "content/browser/speech/chunked_byte_buffer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> |
8 | 9 |
9 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 | 12 |
12 namespace { | 13 namespace { |
13 | 14 |
14 static const size_t kHeaderLength = sizeof(uint32_t); | 15 static const size_t kHeaderLength = sizeof(uint32_t); |
15 | 16 |
16 static_assert(sizeof(size_t) >= kHeaderLength, | 17 static_assert(sizeof(size_t) >= kHeaderLength, |
17 "chunked byte buffer not supported on this architecture"); | 18 "chunked byte buffer not supported on this architecture"); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 105 |
105 scoped_ptr<std::vector<uint8_t>> ChunkedByteBuffer::PopChunk() { | 106 scoped_ptr<std::vector<uint8_t>> ChunkedByteBuffer::PopChunk() { |
106 if (chunks_.empty()) | 107 if (chunks_.empty()) |
107 return scoped_ptr<std::vector<uint8_t>>(); | 108 return scoped_ptr<std::vector<uint8_t>>(); |
108 scoped_ptr<Chunk> chunk(*chunks_.begin()); | 109 scoped_ptr<Chunk> chunk(*chunks_.begin()); |
109 chunks_.weak_erase(chunks_.begin()); | 110 chunks_.weak_erase(chunks_.begin()); |
110 DCHECK_EQ(chunk->header.size(), kHeaderLength); | 111 DCHECK_EQ(chunk->header.size(), kHeaderLength); |
111 DCHECK_EQ(chunk->content->size(), chunk->ExpectedContentLength()); | 112 DCHECK_EQ(chunk->content->size(), chunk->ExpectedContentLength()); |
112 total_bytes_stored_ -= chunk->content->size(); | 113 total_bytes_stored_ -= chunk->content->size(); |
113 total_bytes_stored_ -= kHeaderLength; | 114 total_bytes_stored_ -= kHeaderLength; |
114 return chunk->content.Pass(); | 115 return std::move(chunk->content); |
115 } | 116 } |
116 | 117 |
117 void ChunkedByteBuffer::Clear() { | 118 void ChunkedByteBuffer::Clear() { |
118 chunks_.clear(); | 119 chunks_.clear(); |
119 partial_chunk_.reset(new Chunk()); | 120 partial_chunk_.reset(new Chunk()); |
120 total_bytes_stored_ = 0; | 121 total_bytes_stored_ = 0; |
121 } | 122 } |
122 | 123 |
123 ChunkedByteBuffer::Chunk::Chunk() : content(new std::vector<uint8_t>()) {} | 124 ChunkedByteBuffer::Chunk::Chunk() : content(new std::vector<uint8_t>()) {} |
124 | 125 |
125 ChunkedByteBuffer::Chunk::~Chunk() { | 126 ChunkedByteBuffer::Chunk::~Chunk() { |
126 } | 127 } |
127 | 128 |
128 size_t ChunkedByteBuffer::Chunk::ExpectedContentLength() const { | 129 size_t ChunkedByteBuffer::Chunk::ExpectedContentLength() const { |
129 DCHECK_EQ(header.size(), kHeaderLength); | 130 DCHECK_EQ(header.size(), kHeaderLength); |
130 return static_cast<size_t>(ReadBigEndian32(&header[0])); | 131 return static_cast<size_t>(ReadBigEndian32(&header[0])); |
131 } | 132 } |
132 | 133 |
133 } // namespace content | 134 } // namespace content |
OLD | NEW |