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

Unified Diff: mojo/spy/websocket_server.cc

Issue 354043003: Add support for logging information about mojo messages retrieved by the mojo debugger (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Intercept the first set of pipes Created 6 years, 5 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
« no previous file with comments | « mojo/spy/websocket_server.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/spy/websocket_server.cc
diff --git a/mojo/spy/websocket_server.cc b/mojo/spy/websocket_server.cc
index 649a135c13e81fb363db3b878ad8833343ce515c..3da8d3cbe7a95da73dc5863826ad0df7d8b93a8a 100644
--- a/mojo/spy/websocket_server.cc
+++ b/mojo/spy/websocket_server.cc
@@ -4,18 +4,32 @@
#include "mojo/spy/websocket_server.h"
+#include <string>
+
#include "base/bind.h"
+#include "base/logging.h"
#include "base/strings/stringprintf.h"
+#include "base/time/time.h"
#include "net/base/ip_endpoint.h"
#include "net/base/net_errors.h"
#include "net/server/http_server_request_info.h"
#include "net/server/http_server_response_info.h"
#include "net/socket/tcp_listen_socket.h"
+#include "url/gurl.h"
namespace spy {
const int kNotConnected = -1;
+#define MOJO_DEBUGGER_MESSAGE_FORMAT "\"Start of message for url %s\n" \
+ "Message Time: %02d:%02d:%02d\n"\
+ "Message Bytes: %u\n"\
+ "Message Fields: %u\n"\
+ "Message Name: %u\n"\
+ "Message Request ID: %llu\n"\
+ "Message Type: %s\n"\
cpu_(ooo_6.6-7.5) 2014/07/09 18:18:45 for this to come out properly formatted you need n
ananta 2014/07/09 21:24:55 Leaving \n as is. Fixed overall formatting.
+ "End of message\n\""
+
WebSocketServer::WebSocketServer(int port)
: port_(port), connection_id_(kNotConnected) {
}
@@ -32,6 +46,36 @@ bool WebSocketServer::Start() {
return (error == net::OK);
}
+void WebSocketServer::LogMessageInfo(
+ const mojo::MojoRequestHeader& message_header,
+ const GURL& url,
+ const base::Time& message_time) {
+ base::Time::Exploded exploded;
+ message_time.LocalExplode(&exploded);
+
+ std::string output_message = base::StringPrintf(
+ MOJO_DEBUGGER_MESSAGE_FORMAT,
+ url.spec().c_str(),
+ exploded.hour,
+ exploded.minute,
+ exploded.second,
+ static_cast<unsigned>(message_header.num_bytes),
+ static_cast<unsigned>(message_header.num_fields),
+ static_cast<unsigned>(message_header.name),
+ static_cast<unsigned long long>(
+ message_header.num_fields == 3 ? message_header.request_id
+ : 0),
+ message_header.flags != 0 ?
+ (message_header.flags & mojo::kMessageExpectsResponse ?
+ "Expects response" : "Response message")
+ : "Not a request or response message");
+ if (Connected()) {
+ server_->SendOverWebSocket(connection_id_, output_message.c_str());
+ } else {
+ DLOG(INFO) << output_message;
+ }
+}
+
void WebSocketServer::OnHttpRequest(
int connection_id,
const net::HttpServerRequestInfo& info) {
@@ -67,4 +111,8 @@ void WebSocketServer::OnClose(
connection_id_ = kNotConnected;
}
+bool WebSocketServer::Connected() const {
+ return connection_id_ != kNotConnected;
+}
+
} // namespace spy
« no previous file with comments | « mojo/spy/websocket_server.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698