cc: Remove unused disable_hi_res_timer_tasks_on_battery flag.
[chromium-blink-merge.git] / components / pairing / message_buffer.h
blob8b2fcc0186dbcdd1c3dc5c6c7591da16182c5ef8
1 // Copyright 2014 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 #ifndef COMPONENTS_PAIRING_MESSAGE_BUFFER_H_
6 #define COMPONENTS_PAIRING_MESSAGE_BUFFER_H_
8 #include <deque>
10 #include "base/logging.h"
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
14 namespace net {
15 class IOBuffer;
18 namespace pairing_chromeos {
20 // A MessageBuffer is a simple wrapper around an ordered set of buffers received
21 // from a socket. It keeps track of the amount of unread data, and allows data
22 // to be retreived that was split across buffers in a single chunk.
23 class MessageBuffer {
24 public:
25 MessageBuffer();
26 ~MessageBuffer();
28 // Returns the number of bytes currently received, but not yet read.
29 int AvailableBytes();
31 // Read |size| bytes into |buffer|. |size| must be smaller than or equal to
32 // the current number of available bytes.
33 void ReadBytes(char* buffer, int size);
35 // Add the data from an IOBuffer. A reference to the IOBuffer will be
36 // maintained until it is drained.
37 void AddIOBuffer(scoped_refptr<net::IOBuffer> io_buffer, int size);
39 private:
40 // Offset of the next byte to be read from the current IOBuffer.
41 int buffer_offset_;
42 // Total number of bytes in IOBuffers in |pending_data_|, including bytes that
43 // have already been read.
44 int total_buffer_size_;
45 std::deque<std::pair<scoped_refptr<net::IOBuffer>, int> > pending_data_;
47 DISALLOW_COPY_AND_ASSIGN(MessageBuffer);
50 } // namespace pairing_chromeos
52 #endif // COMPONENTS_PAIRING_MESSAGE_BUFFER_H_