Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1334)

Unified Diff: sync/engine/traffic_recorder.cc

Issue 9826035: [Sync] Display the client server traffic log in about:sync. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For review. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sync/engine/traffic_recorder.cc
diff --git a/sync/engine/traffic_recorder.cc b/sync/engine/traffic_recorder.cc
index a92412e06ed0931b3f140c81f7e621c19f6dbaf3..0b7635a7d4e4db5911c27e4eb1a2b6c955b869fb 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,65 @@ TrafficRecorder::TrafficRecorder(unsigned int max_messages,
TrafficRecorder::~TrafficRecorder() {
}
+namespace {
+#define ENUM_CASE(x) case TrafficRecorder::##x: return #x; break;
akalin 2012/03/30 01:45:35 looks like you don't use this macro after all
lipalani1 2012/03/30 20:35:16 Done.
+
+const char* GetMessageTypeString(TrafficRecorder::TrafficMessageType type) {
+ switch(type) {
+ case TrafficRecorder::CLIENT_TO_SERVER_MESSAGE:
+ return "Request";
+ case TrafficRecorder::CLIENT_TO_SERVER_RESPONSE:
+ return "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));
akalin 2012/03/30 01:45:35 line up with (
lipalani1 2012/03/30 20:35:16 Done.
+ value->SetBoolean("truncated", true);
+ } else if (message_type == TrafficRecorder::CLIENT_TO_SERVER_MESSAGE) {
+ sync_pb::ClientToServerMessage message_proto;
+ if (message_proto.ParseFromString(message))
+ value.reset(
+ ClientToServerMessageToValue(message_proto,
+ 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);
akalin 2012/03/30 01:45:35 is it necessary to have a string ID? Why not fill
lipalani1 2012/03/30 20:35:16 Done.
+ dictionary->Set(message_id, record.ToValue());
+ ++message_count;
+ }
+
+ return dictionary.release();
+}
+
+
void TrafficRecorder::AddTrafficToQueue(TrafficRecord* record) {
records_.resize(records_.size() + 1);
@@ -76,6 +136,5 @@ void TrafficRecorder::RecordClientToServerResponse(
const sync_pb::ClientToServerResponse& response) {
StoreProtoInQueue(response, CLIENT_TO_SERVER_RESPONSE);
}
-
} // namespace browser_sync

Powered by Google App Engine
This is Rietveld 408576698