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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SYNC_ENGINE_TRAFFIC_RECORDER_H_
6 #define CHROME_BROWSER_SYNC_ENGINE_TRAFFIC_RECORDER_H_
11 #include "base/basictypes.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/values.h"
14 #include "sync/protocol/sync.pb.h"
17 class ClientToServerResponse
;
18 class ClientToServerMessage
;
23 class TrafficRecorder
{
25 enum TrafficMessageType
{
26 CLIENT_TO_SERVER_MESSAGE
,
27 CLIENT_TO_SERVER_RESPONSE
,
31 struct TrafficRecord
{
32 // The serialized message.
34 TrafficMessageType message_type
;
35 // If the message is too big to be kept in memory then it should be
36 // truncated. For now the entire message is omitted if it is too big.
37 // TODO(lipalani): Truncate the specifics to fit within size.
40 TrafficRecord(const std::string
& message
,
41 TrafficMessageType message_type
,
45 DictionaryValue
* ToValue() const;
48 TrafficRecorder(unsigned int max_messages
, unsigned int max_message_size
);
51 void RecordClientToServerMessage(const sync_pb::ClientToServerMessage
& msg
);
52 void RecordClientToServerResponse(
53 const sync_pb::ClientToServerResponse
& response
);
54 ListValue
* ToValue() const;
56 const std::deque
<TrafficRecord
>& records() {
61 void AddTrafficToQueue(TrafficRecord
* record
);
62 void StoreProtoInQueue(const ::google::protobuf::MessageLite
& msg
,
63 TrafficMessageType type
);
65 // Maximum number of messages stored in the queue.
66 unsigned int max_messages_
;
68 // Maximum size of each message.
69 unsigned int max_message_size_
;
70 std::deque
<TrafficRecord
> records_
;
71 DISALLOW_COPY_AND_ASSIGN(TrafficRecorder
);
76 #endif // CHROME_BROWSER_SYNC_ENGINE_TRAFFIC_RECORDER_H_