summaryrefslogtreecommitdiffstats
path: root/sync/internal_api/protocol_event_buffer.h
blob: 71a9c6433b1c1bf945125ed08df892049b9354dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SYNC_INTERNAL_API_PROTOCOL_EVENT_BUFFER_H_
#define SYNC_INTERNAL_API_PROTOCOL_EVENT_BUFFER_H_

#include <stddef.h>

#include <deque>

#include "base/macros.h"
#include "base/memory/scoped_vector.h"
#include "sync/base/sync_export.h"

namespace syncer {

class ProtocolEvent;

// A container for ProtocolEvents.
//
// Stores at most kBufferSize events, then starts dropping the oldest events.
class SYNC_EXPORT ProtocolEventBuffer {
 public:
  static const size_t kBufferSize;

  ProtocolEventBuffer();
  ~ProtocolEventBuffer();

  // Records an event.  May cause the oldest event to be dropped.
  void RecordProtocolEvent(const ProtocolEvent& event);

  // Returns the buffered contents.  Will not clear the buffer.
  ScopedVector<ProtocolEvent> GetBufferedProtocolEvents() const;

 private:
  std::deque<ProtocolEvent*> buffer_;
  STLElementDeleter<std::deque<ProtocolEvent*> > buffer_deleter_;

  DISALLOW_COPY_AND_ASSIGN(ProtocolEventBuffer);
};

}  // namespace syncer

#endif  // SYNC_INTERNAL_API_PROTOCOL_EVENT_BUFFER_H_