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/basictypes.h" | |
| 13 #include "base/gtest_prod_util.h" | |
| 14 #include "sync/protocol/sync.pb.h" | |
| 15 | |
| 16 namespace sync_pb { | |
| 17 class ClientToServerResponse; | |
| 18 class ClientToServerMessage; | |
| 19 } | |
| 20 | |
| 21 namespace browser_sync { | |
| 22 | |
| 23 class TrafficRecorder { | |
| 24 public: | |
| 25 enum TrafficMessageType { | |
| 26 CLIENT_TO_SERVER_MESSAGE, | |
| 27 CLIENT_TO_SERVER_RESPONSE, | |
|
rlarocque
2012/03/29 17:56:21
Shouldn't at least one of these be SERVER_TO_CLIEN
lipalani1
2012/03/29 18:39:29
Ideally yes. But the proto is named this way and t
| |
| 28 UNKNOWN_MESSAGE_TYPE | |
| 29 }; | |
| 30 | |
| 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 with in size. | |
|
rlarocque
2012/03/29 17:56:21
nit: s/with in/within/
lipalani1
2012/03/29 18:39:29
Done.
| |
| 38 bool truncated; | |
| 39 | |
| 40 TrafficRecord(const std::string& message, | |
| 41 TrafficMessageType message_type, | |
| 42 bool truncated); | |
| 43 TrafficRecord(); | |
| 44 ~TrafficRecord(); | |
| 45 }; | |
| 46 | |
| 47 TrafficRecorder(unsigned int max_messages, unsigned int max_message_size); | |
| 48 ~TrafficRecorder(); | |
| 49 | |
| 50 void RecordClientToServerMessage(const sync_pb::ClientToServerMessage& msg); | |
| 51 void RecordClientToServerResponse( | |
| 52 const sync_pb::ClientToServerResponse& response); | |
| 53 | |
| 54 const std::deque<TrafficRecord>& records() { | |
| 55 return records_; | |
| 56 } | |
| 57 | |
| 58 private: | |
| 59 void AddTrafficToQueue(const TrafficRecord& record); | |
| 60 void StoreProtoInQueue(const ::google::protobuf::MessageLite& msg, | |
| 61 TrafficMessageType type); | |
| 62 | |
| 63 // Maximum number of messages stored in the queue. | |
| 64 unsigned int max_messages_; | |
| 65 | |
| 66 // Maximum size of each message. | |
| 67 unsigned int max_message_size_; | |
| 68 std::deque<TrafficRecord> records_; | |
|
rlarocque
2012/03/29 17:56:21
I normally try to avoid premature optimization, bu
lipalani1
2012/03/29 18:39:29
answered in the next comment. Bottom line this wou
| |
| 69 DISALLOW_COPY_AND_ASSIGN(TrafficRecorder); | |
| 70 }; | |
| 71 | |
| 72 } // namespace browser_sync | |
| 73 | |
| 74 #endif // CHROME_BROWSER_SYNC_ENGINE_TRAFFIC_RECORDER_H_ | |
| OLD | NEW |