| 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 #ifndef CONTENT_BROWSER_SPEECH_CHUNKED_BYTE_BUFFER_H_ | 5 #ifndef CONTENT_BROWSER_SPEECH_CHUNKED_BYTE_BUFFER_H_ |
| 6 #define CONTENT_BROWSER_SPEECH_CHUNKED_BYTE_BUFFER_H_ | 6 #define CONTENT_BROWSER_SPEECH_CHUNKED_BYTE_BUFFER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <memory> |
| 11 #include <string> | 12 #include <string> |
| 12 #include <vector> | 13 #include <vector> |
| 13 | 14 |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
| 17 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 | 20 |
| 21 // Models a chunk-oriented byte buffer. The term chunk is herein defined as an | 21 // Models a chunk-oriented byte buffer. The term chunk is herein defined as an |
| 22 // arbitrary sequence of bytes that is preceeded by N header bytes, indicating | 22 // arbitrary sequence of bytes that is preceeded by N header bytes, indicating |
| 23 // its size. Data may be appended to the buffer with no particular respect of | 23 // its size. Data may be appended to the buffer with no particular respect of |
| 24 // chunks boundaries. However, chunks can be extracted (FIFO) only when their | 24 // chunks boundaries. However, chunks can be extracted (FIFO) only when their |
| 25 // content (according to their header) is fully available in the buffer. | 25 // content (according to their header) is fully available in the buffer. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 37 void Append(const uint8_t* start, size_t length); | 37 void Append(const uint8_t* start, size_t length); |
| 38 | 38 |
| 39 // Appends bytes contained in the |string| to the buffer. | 39 // Appends bytes contained in the |string| to the buffer. |
| 40 void Append(const std::string& string); | 40 void Append(const std::string& string); |
| 41 | 41 |
| 42 // Checks whether one or more complete chunks are available in the buffer. | 42 // Checks whether one or more complete chunks are available in the buffer. |
| 43 bool HasChunks() const; | 43 bool HasChunks() const; |
| 44 | 44 |
| 45 // If enough data is available, reads and removes the first complete chunk | 45 // If enough data is available, reads and removes the first complete chunk |
| 46 // from the buffer. Returns a NULL pointer if no complete chunk is available. | 46 // from the buffer. Returns a NULL pointer if no complete chunk is available. |
| 47 scoped_ptr<std::vector<uint8_t>> PopChunk(); | 47 std::unique_ptr<std::vector<uint8_t>> PopChunk(); |
| 48 | 48 |
| 49 // Clears all the content of the buffer. | 49 // Clears all the content of the buffer. |
| 50 void Clear(); | 50 void Clear(); |
| 51 | 51 |
| 52 // Returns the number of raw bytes (including headers) present. | 52 // Returns the number of raw bytes (including headers) present. |
| 53 size_t GetTotalLength() const { return total_bytes_stored_; } | 53 size_t GetTotalLength() const { return total_bytes_stored_; } |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 struct Chunk { | 56 struct Chunk { |
| 57 Chunk(); | 57 Chunk(); |
| 58 ~Chunk(); | 58 ~Chunk(); |
| 59 | 59 |
| 60 std::vector<uint8_t> header; | 60 std::vector<uint8_t> header; |
| 61 scoped_ptr<std::vector<uint8_t>> content; | 61 std::unique_ptr<std::vector<uint8_t>> content; |
| 62 size_t ExpectedContentLength() const; | 62 size_t ExpectedContentLength() const; |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 DISALLOW_COPY_AND_ASSIGN(Chunk); | 65 DISALLOW_COPY_AND_ASSIGN(Chunk); |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 ScopedVector<Chunk> chunks_; | 68 ScopedVector<Chunk> chunks_; |
| 69 scoped_ptr<Chunk> partial_chunk_; | 69 std::unique_ptr<Chunk> partial_chunk_; |
| 70 size_t total_bytes_stored_; | 70 size_t total_bytes_stored_; |
| 71 | 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(ChunkedByteBuffer); | 72 DISALLOW_COPY_AND_ASSIGN(ChunkedByteBuffer); |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 | 75 |
| 76 } // namespace content | 76 } // namespace content |
| 77 | 77 |
| 78 #endif // CONTENT_BROWSER_SPEECH_CHUNKED_BYTE_BUFFER_H_ | 78 #endif // CONTENT_BROWSER_SPEECH_CHUNKED_BYTE_BUFFER_H_ |
| OLD | NEW |