Chromium Code Reviews| Index: chrome/browser/extensions/api/serial/serial_apitest.cc |
| diff --git a/chrome/browser/extensions/api/serial/serial_apitest.cc b/chrome/browser/extensions/api/serial/serial_apitest.cc |
| index db0d110d0d0f96ac9194222e1f064066671ffe53..92135969b482091925b97994b0a8ad8bac0df990 100644 |
| --- a/chrome/browser/extensions/api/serial/serial_apitest.cc |
| +++ b/chrome/browser/extensions/api/serial/serial_apitest.cc |
| @@ -2,6 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include <deque> |
| #include <string> |
| #include <vector> |
| @@ -74,19 +75,22 @@ class FakeEchoSerialConnection : public SerialConnection { |
| virtual void Flush() { |
| DCHECK(opened_); |
| - read_index_ = write_index_ = 0; |
| + ring_buffer_.clear(); |
| } |
| - virtual int Read(uint8* byte) { |
| - DCHECK(byte); |
| + virtual int Read(scoped_refptr<net::IOBufferWithSize> io_buffer) { |
| + DCHECK(io_buffer->data()); |
| - if (read_index_ >= write_index_) { |
| + if (ring_buffer_.empty()) { |
| return 0; |
| } |
| - *byte = ring_buffer_[read_index_++]; |
| - if (read_index_ == BUFFER_SIZE) |
| - read_index_ = 0; |
| - return 1; |
| + char *data = io_buffer->data(); |
| + int bytes_to_copy = io_buffer->size(); |
| + while (bytes_to_copy--) { |
|
Peng
2012/08/02 16:31:32
Maybe test !ring_buffer_.empty() as well, and retu
|
| + *data++ = ring_buffer_.front(); |
| + ring_buffer_.pop_front(); |
| + } |
| + return io_buffer->size(); |
| } |
| virtual int Write(scoped_refptr<net::IOBuffer> io_buffer, int byte_count) { |
| @@ -95,11 +99,8 @@ class FakeEchoSerialConnection : public SerialConnection { |
| char *data = io_buffer->data(); |
| int count = byte_count; |
| - while (count--) { |
| - ring_buffer_[write_index_++] = *data++; |
| - if (write_index_ == BUFFER_SIZE) |
| - write_index_ = 0; |
| - } |
| + while (count--) |
| + ring_buffer_.push_back(*data++); |
| return byte_count; |
| } |
| @@ -107,11 +108,8 @@ class FakeEchoSerialConnection : public SerialConnection { |
| MOCK_METHOD1(SetControlSignals, bool(const ControlSignals &)); |
| private: |
| - enum { BUFFER_SIZE = 256 }; |
| bool opened_; |
| - char ring_buffer_[BUFFER_SIZE]; |
| - int read_index_; |
| - int write_index_; |
| + std::deque<char> ring_buffer_; |
|
Peng
2012/08/02 16:31:32
Maybe just buffer_ is better.
|
| DISALLOW_COPY_AND_ASSIGN(FakeEchoSerialConnection); |
| }; |