More bring up of ui code on iOS.
[chromium-blink-merge.git] / sync / engine / traffic_recorder.h
blob28edec557d23318adf943e3da18a1297d06aaf78
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_
8 #include <deque>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/values.h"
14 #include "sync/protocol/sync.pb.h"
16 namespace sync_pb {
17 class ClientToServerResponse;
18 class ClientToServerMessage;
21 namespace syncer {
23 class TrafficRecorder {
24 public:
25 enum TrafficMessageType {
26 CLIENT_TO_SERVER_MESSAGE,
27 CLIENT_TO_SERVER_RESPONSE,
28 UNKNOWN_MESSAGE_TYPE
31 struct TrafficRecord {
32 // The serialized message.
33 std::string 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.
38 bool truncated;
40 TrafficRecord(const std::string& message,
41 TrafficMessageType message_type,
42 bool truncated);
43 TrafficRecord();
44 ~TrafficRecord();
45 DictionaryValue* ToValue() const;
48 TrafficRecorder(unsigned int max_messages, unsigned int max_message_size);
49 ~TrafficRecorder();
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() {
57 return records_;
60 private:
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);
74 } // namespace syncer
76 #endif // CHROME_BROWSER_SYNC_ENGINE_TRAFFIC_RECORDER_H_