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

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 e9ea716c03b0076e170c6c2ffbb7678c34d315a4..0025b17bdaa6129b4b98a83d730f2fcff7f81223 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,58 @@ TrafficRecorder::TrafficRecorder(unsigned int max_messages,
TrafficRecorder::~TrafficRecorder() {
}
+namespace {
+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 "";
+}
+}
+
+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))
+ 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();
+}
+
+
+ListValue* TrafficRecorder::ToValue() const {
+ scoped_ptr<ListValue> value(new ListValue());
+ std::deque<TrafficRecord>::const_iterator it;
+ for (it = records_.begin(); it != records_.end(); ++it) {
+ const TrafficRecord& record = *it;
+ value->Append(record.ToValue());
+ }
+
+ return value.release();
+}
+
+
void TrafficRecorder::AddTrafficToQueue(TrafficRecord* record) {
records_.resize(records_.size() + 1);
@@ -56,7 +109,7 @@ void TrafficRecorder::StoreProtoInQueue(
TrafficMessageType type) {
bool truncated = false;
std::string message;
- if (static_cast<unsigned int>(msg.ByteSize()) >= max_message_size_) {
+ if ((unsigned int)msg.ByteSize() >= max_message_size_) {
rlarocque 2012/03/30 21:01:11 This line changed a few times throughout the revie
lipalani1 2012/03/30 23:34:05 Bad merge. It is static_cast after the latest reba
// TODO(lipalani): Trim the specifics to fit in size.
truncated = true;
} else {
@@ -76,6 +129,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