Chromium Code Reviews| Index: sync/engine/traffic_recorder.cc |
| diff --git a/sync/engine/traffic_recorder.cc b/sync/engine/traffic_recorder.cc |
| index a92412e06ed0931b3f140c81f7e621c19f6dbaf3..2bdcac7f75ed7c66f6880f3e79e20bceca9560fe 100644 |
| --- a/sync/engine/traffic_recorder.cc |
| +++ b/sync/engine/traffic_recorder.cc |
| @@ -7,6 +7,7 @@ |
| #include "base/json/json_writer.h" |
| #include "base/logging.h" |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/stringprintf.h" |
| #include "base/values.h" |
| #include "sync/protocol/proto_value_conversions.h" |
| #include "sync/protocol/sync.pb.h" |
| @@ -39,6 +40,63 @@ TrafficRecorder::TrafficRecorder(unsigned int max_messages, |
| TrafficRecorder::~TrafficRecorder() { |
| } |
| +namespace { |
| +#define ENUM_CASE(x) case TrafficRecorder::##x: return #x; break; |
| + |
| +const char* GetMessageTypeString(TrafficRecorder::TrafficMessageType type) { |
|
rlarocque
2012/03/29 22:54:27
I'd like to take this opportunity to hide some unu
lipalani1
2012/03/29 23:58:37
Done.
|
| + switch(type) { |
| + ENUM_CASE(CLIENT_TO_SERVER_MESSAGE) |
| + ENUM_CASE(CLIENT_TO_SERVER_RESPONSE) |
| + } |
| + NOTREACHED(); |
| + return ""; |
| +} |
| + |
| +#undef ENUM_CASE |
| +} |
| + |
| +DictionaryValue* TrafficRecorder::TrafficRecord::ToValue() const { |
| + scoped_ptr<DictionaryValue> value; |
| + if (truncated) { |
| + value.reset(new DictionaryValue()); |
| + value->SetString("message_type", |
| + GetMessageTypeString(message_type)); |
| + value->SetBoolean("truncated", true); |
| + } else if (message_type == TrafficRecorder::CLIENT_TO_SERVER_MESSAGE) { |
| + sync_pb::ClientToServerMessage message_proto; |
| + if (message_proto.ParseFromString(message)) |
|
rlarocque
2012/03/30 00:20:51
By the way, do we really need to round-trip the me
akalin
2012/03/30 01:55:04
Yeah, I wanted it to be stored serialized to save
lipalani1
2012/03/30 20:35:16
We had a discussion about the best format for stor
rlarocque
2012/03/30 21:01:11
I'm not entirely convinced that this will be a sig
|
| + value.reset( |
| + ClientToServerMessageToValue(message_proto, |
|
rlarocque
2012/03/29 22:58:49
Because the JavaScript isn't processing this in an
lipalani1
2012/03/29 23:58:37
JS converts this into a formatted string using JSO
rlarocque
2012/03/30 00:20:51
Right, but that dictionary could consist solely of
akalin
2012/03/30 01:55:04
I'm not sure I follow; why would serializing to a
rlarocque
2012/03/30 17:49:02
I don't mean to argue that it's necessarily better
|
| + false /* include_specifics */)); |
| + } else if (message_type == TrafficRecorder::CLIENT_TO_SERVER_RESPONSE) { |
| + sync_pb::ClientToServerResponse message_proto; |
| + if (message_proto.ParseFromString(message)) |
| + value.reset( |
| + ClientToServerResponseToValue(message_proto, |
| + false /* include_specifics */)); |
| + } else { |
| + NOTREACHED(); |
| + } |
| + |
| + return value.release(); |
| +} |
| + |
| + |
| +DictionaryValue* TrafficRecorder::ToValue() const { |
| + int message_count = 0; |
| + scoped_ptr<DictionaryValue> dictionary(new DictionaryValue()); |
| + std::deque<TrafficRecord>::const_iterator it; |
| + for (it = records_.begin(); it != records_.end(); ++it) { |
| + const TrafficRecord& record = *it; |
| + std::string message_id = StringPrintf("message%d", message_count); |
|
rlarocque
2012/03/29 22:54:27
Couldn't this be an array instead? I don't see th
lipalani1
2012/03/29 23:58:37
We have to put this in a dictionary. Having it as
rlarocque
2012/03/30 00:20:51
Same idea as above. A single-attribute dictionary
akalin
2012/03/30 01:55:04
See my comment re. using ListValue for this. The
|
| + dictionary->Set(message_id, record.ToValue()); |
| + ++message_count; |
| + } |
| + |
| + return dictionary.release(); |
| +} |
| + |
| + |
| void TrafficRecorder::AddTrafficToQueue(TrafficRecord* record) { |
| records_.resize(records_.size() + 1); |
| @@ -76,6 +134,5 @@ void TrafficRecorder::RecordClientToServerResponse( |
| const sync_pb::ClientToServerResponse& response) { |
| StoreProtoInQueue(response, CLIENT_TO_SERVER_RESPONSE); |
| } |
| - |
| } // namespace browser_sync |