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 #include <utility> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 96 } |
97 | 97 |
98 void ChunkedByteBuffer::Append(const std::string& string) { | 98 void ChunkedByteBuffer::Append(const std::string& string) { |
99 Append(reinterpret_cast<const uint8_t*>(string.data()), string.size()); | 99 Append(reinterpret_cast<const uint8_t*>(string.data()), string.size()); |
100 } | 100 } |
101 | 101 |
102 bool ChunkedByteBuffer::HasChunks() const { | 102 bool ChunkedByteBuffer::HasChunks() const { |
103 return !chunks_.empty(); | 103 return !chunks_.empty(); |
104 } | 104 } |
105 | 105 |
106 scoped_ptr<std::vector<uint8_t>> ChunkedByteBuffer::PopChunk() { | 106 std::unique_ptr<std::vector<uint8_t>> ChunkedByteBuffer::PopChunk() { |
107 if (chunks_.empty()) | 107 if (chunks_.empty()) |
108 return scoped_ptr<std::vector<uint8_t>>(); | 108 return std::unique_ptr<std::vector<uint8_t>>(); |
109 scoped_ptr<Chunk> chunk(*chunks_.begin()); | 109 std::unique_ptr<Chunk> chunk(*chunks_.begin()); |
110 chunks_.weak_erase(chunks_.begin()); | 110 chunks_.weak_erase(chunks_.begin()); |
111 DCHECK_EQ(chunk->header.size(), kHeaderLength); | 111 DCHECK_EQ(chunk->header.size(), kHeaderLength); |
112 DCHECK_EQ(chunk->content->size(), chunk->ExpectedContentLength()); | 112 DCHECK_EQ(chunk->content->size(), chunk->ExpectedContentLength()); |
113 total_bytes_stored_ -= chunk->content->size(); | 113 total_bytes_stored_ -= chunk->content->size(); |
114 total_bytes_stored_ -= kHeaderLength; | 114 total_bytes_stored_ -= kHeaderLength; |
115 return std::move(chunk->content); | 115 return std::move(chunk->content); |
116 } | 116 } |
117 | 117 |
118 void ChunkedByteBuffer::Clear() { | 118 void ChunkedByteBuffer::Clear() { |
119 chunks_.clear(); | 119 chunks_.clear(); |
120 partial_chunk_.reset(new Chunk()); | 120 partial_chunk_.reset(new Chunk()); |
121 total_bytes_stored_ = 0; | 121 total_bytes_stored_ = 0; |
122 } | 122 } |
123 | 123 |
124 ChunkedByteBuffer::Chunk::Chunk() : content(new std::vector<uint8_t>()) {} | 124 ChunkedByteBuffer::Chunk::Chunk() : content(new std::vector<uint8_t>()) {} |
125 | 125 |
126 ChunkedByteBuffer::Chunk::~Chunk() { | 126 ChunkedByteBuffer::Chunk::~Chunk() { |
127 } | 127 } |
128 | 128 |
129 size_t ChunkedByteBuffer::Chunk::ExpectedContentLength() const { | 129 size_t ChunkedByteBuffer::Chunk::ExpectedContentLength() const { |
130 DCHECK_EQ(header.size(), kHeaderLength); | 130 DCHECK_EQ(header.size(), kHeaderLength); |
131 return static_cast<size_t>(ReadBigEndian32(&header[0])); | 131 return static_cast<size_t>(ReadBigEndian32(&header[0])); |
132 } | 132 } |
133 | 133 |
134 } // namespace content | 134 } // namespace content |
OLD | NEW |