Chromium Code Reviews| Index: sync/engine/traffic_recorder.h |
| diff --git a/sync/engine/traffic_recorder.h b/sync/engine/traffic_recorder.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0903ee676e81cd4c0be212602f354ca43f658fbd |
| --- /dev/null |
| +++ b/sync/engine/traffic_recorder.h |
| @@ -0,0 +1,74 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_SYNC_ENGINE_TRAFFIC_RECORDER_H_ |
| +#define CHROME_BROWSER_SYNC_ENGINE_TRAFFIC_RECORDER_H_ |
| +#pragma once |
| + |
| +#include <deque> |
| +#include <string> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/gtest_prod_util.h" |
| +#include "sync/protocol/sync.pb.h" |
| + |
| +namespace sync_pb { |
| +class ClientToServerResponse; |
| +class ClientToServerMessage; |
| +} |
| + |
| +namespace browser_sync { |
| + |
| +class TrafficRecorder { |
| + public: |
| + enum TrafficMessageType { |
| + CLIENT_TO_SERVER_MESSAGE, |
| + 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
|
| + UNKNOWN_MESSAGE_TYPE |
| + }; |
| + |
| + struct TrafficRecord { |
| + // The serialized message. |
| + std::string message; |
| + TrafficMessageType message_type; |
| + // If the message is too big to be kept in memory then it should be |
| + // truncated. For now the entire message is omitted if it is too big. |
| + // 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.
|
| + bool truncated; |
| + |
| + TrafficRecord(const std::string& message, |
| + TrafficMessageType message_type, |
| + bool truncated); |
| + TrafficRecord(); |
| + ~TrafficRecord(); |
| + }; |
| + |
| + TrafficRecorder(unsigned int max_messages, unsigned int max_message_size); |
| + ~TrafficRecorder(); |
| + |
| + void RecordClientToServerMessage(const sync_pb::ClientToServerMessage& msg); |
| + void RecordClientToServerResponse( |
| + const sync_pb::ClientToServerResponse& response); |
| + |
| + const std::deque<TrafficRecord>& records() { |
| + return records_; |
| + } |
| + |
| + private: |
| + void AddTrafficToQueue(const TrafficRecord& record); |
| + void StoreProtoInQueue(const ::google::protobuf::MessageLite& msg, |
| + TrafficMessageType type); |
| + |
| + // Maximum number of messages stored in the queue. |
| + unsigned int max_messages_; |
| + |
| + // Maximum size of each message. |
| + unsigned int max_message_size_; |
| + 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
|
| + DISALLOW_COPY_AND_ASSIGN(TrafficRecorder); |
| +}; |
| + |
| +} // namespace browser_sync |
| + |
| +#endif // CHROME_BROWSER_SYNC_ENGINE_TRAFFIC_RECORDER_H_ |