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

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: Presubmit warnings 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 baa87095cbccd9b6ca302cef67ecab006f2c3e80..3f044ed60e1b93e66e58489f0e6afa21a4462665 100644
--- a/mojo/spy/websocket_server.cc
+++ b/mojo/spy/websocket_server.cc
@@ -7,20 +7,29 @@
#include <string>
#include "base/bind.h"
+#include "base/logging.h"
#include "base/strings/stringprintf.h"
-
#include "mojo/public/cpp/bindings/message.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 mojo {
const int kNotConnected = -1;
+#define MOJO_DEBUGGER_MESSAGE_FORMAT "\"url: %s\n," \
+ "time: %02d:%02d:%02d\n,"\
+ "bytes: %u\n,"\
+ "fields: %u\n,"\
+ "name: %u\n,"\
+ "requestId: %llu\n,"\
+ "type: %s\n,"\
+ "end:\n\""
+
WebSocketServer::WebSocketServer(int port,
mojo::ScopedMessagePipeHandle server_pipe)
: port_(port),
@@ -41,6 +50,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()) {
+ web_server_->SendOverWebSocket(connection_id_, output_message.c_str());
+ } else {
+ DVLOG(1) << output_message;
+ }
+}
+
void WebSocketServer::OnHttpRequest(
int connection_id,
const net::HttpServerRequestInfo& info) {
@@ -113,4 +152,9 @@ void WebSocketServer::OnStartSession(spy_api::Result, mojo::String) {
web_server_->SendOverWebSocket(connection_id_, "\"ok start\"");
}
+bool WebSocketServer::Connected() const {
+ return connection_id_ != kNotConnected;
+}
+
} // namespace mojo
+
« 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