1 // Copyright 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/time.h"
14 #include "base/values.h"
15 #include "sync/base/sync_export.h"
16 #include "sync/protocol/sync.pb.h"
19 class ClientToServerResponse
;
20 class ClientToServerMessage
;
25 class SYNC_EXPORT_PRIVATE TrafficRecorder
{
27 enum TrafficMessageType
{
28 CLIENT_TO_SERVER_MESSAGE
,
29 CLIENT_TO_SERVER_RESPONSE
,
33 struct SYNC_EXPORT_PRIVATE TrafficRecord
{
34 // The serialized message.
36 TrafficMessageType message_type
;
37 // If the message is too big to be kept in memory then it should be
38 // truncated. For now the entire message is omitted if it is too big.
39 // TODO(lipalani): Truncate the specifics to fit within size.
42 TrafficRecord(const std::string
& message
,
43 TrafficMessageType message_type
,
48 DictionaryValue
* ToValue() const;
50 // Time of record creation.
54 TrafficRecorder(unsigned int max_messages
, unsigned int max_message_size
);
55 virtual ~TrafficRecorder();
57 void RecordClientToServerMessage(const sync_pb::ClientToServerMessage
& msg
);
58 void RecordClientToServerResponse(
59 const sync_pb::ClientToServerResponse
& response
);
60 ListValue
* ToValue() const;
62 const std::deque
<TrafficRecord
>& records() {
67 void AddTrafficToQueue(TrafficRecord
* record
);
68 void StoreProtoInQueue(const ::google::protobuf::MessageLite
& msg
,
69 TrafficMessageType type
);
71 // Method to get record creation time.
72 virtual base::Time
GetTime();
74 // Maximum number of messages stored in the queue.
75 unsigned int max_messages_
;
77 // Maximum size of each message.
78 unsigned int max_message_size_
;
79 std::deque
<TrafficRecord
> records_
;
80 DISALLOW_COPY_AND_ASSIGN(TrafficRecorder
);
85 #endif // CHROME_BROWSER_SYNC_ENGINE_TRAFFIC_RECORDER_H_