Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_SYNC_ENGINE_TRAFFIC_RECORDER_H_ | |
| 6 #define CHROME_BROWSER_SYNC_ENGINE_TRAFFIC_RECORDER_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <deque> | |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/gtest_prod_util.h" | |
| 13 #include "sync/protocol/sync.pb.h" | |
| 14 | |
| 15 namespace sync_pb { | |
| 16 class ClientToServerResponse; | |
| 17 class ClientToServerMessage; | |
| 18 } | |
| 19 | |
| 20 namespace browser_sync { | |
| 21 | |
| 22 extern const unsigned int kMaxMessages; | |
| 23 extern const unsigned int kMaxMessageSize; | |
| 24 | |
| 25 class TrafficRecorder { | |
| 26 enum TrafficMessageType { | |
| 27 CLIENT_TO_SERVER_MESSAGE, | |
| 28 CLIENT_TO_SERVER_RESPONSE, | |
| 29 UNKNOWN_MESSAGE_TYPE | |
| 30 }; | |
| 31 | |
| 32 struct TrafficRecord { | |
| 33 // The serialized message. | |
| 34 std::string message; | |
| 35 TrafficMessageType message_type; | |
| 36 // If the message is too big to be kept in memory then it should be | |
| 37 // truncated. For now the entire message is omitted if it is too big. | |
| 38 // TODO(lipalani): Truncate the specifics to fit with in size. | |
| 39 bool truncated; | |
| 40 | |
| 41 TrafficRecord(const std::string& message, | |
| 42 TrafficMessageType message_type, | |
| 43 bool truncated); | |
| 44 TrafficRecord(); | |
| 45 ~TrafficRecord(); | |
| 46 }; | |
| 47 | |
| 48 public: | |
| 49 TrafficRecorder(); | |
| 50 ~TrafficRecorder(); | |
| 51 | |
| 52 void RecordClientToServerMessage(const sync_pb::ClientToServerMessage& msg); | |
| 53 void RecordClientToServerResponse( | |
| 54 const sync_pb::ClientToServerResponse& response); | |
| 55 | |
| 56 private: | |
| 57 FRIEND_TEST_ALL_PREFIXES(TrafficRecorderTest, MaxRecordsTest); | |
|
akalin
2012/03/27 23:53:44
I prefer doing read accessors over giving tests ac
lipalani1
2012/03/29 00:23:13
Done.
| |
| 58 FRIEND_TEST_ALL_PREFIXES(TrafficRecorderTest, MaxMessageSizeTest); | |
| 59 void AddTrafficToQueue(const TrafficRecord& record); | |
| 60 void StoreProtoInQueue(const ::google::protobuf::MessageLite& msg, | |
| 61 TrafficMessageType type); | |
| 62 | |
| 63 std::deque<TrafficRecord> records_; | |
|
akalin
2012/03/27 23:53:44
DISALLOW_COPY_AND_ASSIGN()
(don't forget to inclu
lipalani1
2012/03/29 00:23:13
Done.
| |
| 64 }; | |
| 65 | |
| 66 } // namespace browser_sync | |
| 67 | |
| 68 #endif // CHROME_BROWSER_SYNC_ENGINE_TRAFFIC_RECORDER_H_ | |
| OLD | NEW |