Chromium Code Reviews| Index: mojo/spy/websocket_server.cc |
| diff --git a/mojo/spy/websocket_server.cc b/mojo/spy/websocket_server.cc |
| index 649a135c13e81fb363db3b878ad8833343ce515c..9267b4436a65fd27360a14cf47c1eb1403b9944b 100644 |
| --- a/mojo/spy/websocket_server.cc |
| +++ b/mojo/spy/websocket_server.cc |
| @@ -4,18 +4,34 @@ |
| #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 %ls\n" \ |
|
viettrungluu
2014/06/30 19:16:54
Do you really need this macro? It's only used in o
ananta
2014/07/03 00:04:40
Leaving the macro as is as it makes it easier to a
ananta
2014/07/03 00:04:40
Done.
|
| + "Message Time Hours : %d\n"\ |
|
viettrungluu
2014/06/30 19:16:55
No space before ':', please.
Also, probably you c
ananta
2014/07/03 00:04:40
Done.
|
| + "Message Time Mins : %d\n"\ |
| + "Message Time Secs : %d\n"\ |
| + "Message Bytes : %d\n"\ |
| + "Message Fields : %d\n"\ |
| + "Message name : %d\n"\ |
|
viettrungluu
2014/06/30 19:16:55
Nit: name -> Name (capitalized; be consistent -- y
ananta
2014/07/03 00:04:40
Done.
|
| + "Message Request ID : %d\n"\ |
|
viettrungluu
2014/06/30 19:16:55
%llu (it's 64-bit)
ananta
2014/07/03 00:04:40
Done.
|
| + "Message Type : %s\n"\ |
| + "End of message\n\"" |
| + |
| WebSocketServer::WebSocketServer(int port) |
| : port_(port), connection_id_(kNotConnected) { |
| } |
| @@ -32,6 +48,48 @@ bool WebSocketServer::Start() { |
| return (error == net::OK); |
| } |
| +void WebSocketServer::LogMessageInfo( |
| + const mojo::MojoMessageHeader& message_header, |
| + const GURL& url, |
| + const base::Time& message_time) { |
| + base::Time::Exploded exploded; |
| + message_time.LocalExplode(&exploded); |
| + |
| + if (Connected()) { |
| + std::string output_message = base::StringPrintf( |
| + MOJO_DEBUGGER_MESSAGE_FORMAT, |
| + url.spec(), |
|
viettrungluu
2014/06/30 19:16:55
url.spec().c_str()?
ananta
2014/07/03 00:04:40
Done.
|
| + exploded.hour, |
| + exploded.second, |
| + message_header.num_bytes, |
|
viettrungluu
2014/06/30 19:16:55
Strictly speaking, for the uint32_t fields, you sh
ananta
2014/07/03 00:04:40
Done.
|
| + message_header.num_fields, |
| + message_header.name, |
| + message_header.num_fields == 3 ? message_header.request_id : -1, |
|
viettrungluu
2014/06/30 19:16:54
Hmmm. You should probably use "%llu" and static_ca
ananta
2014/07/03 00:04:40
Done. If the field is not present we print beef.
ananta
2014/07/09 02:33:56
If the field is not present we print 0 followed by
|
| + message_header.flags & mojo::kMessageExpectsResponse ? |
| + "Expects response" : "Response message"); |
| + server_->SendOverWebSocket(connection_id_, output_message.c_str()); |
| + } else { |
| + DLOG(INFO) << "\n\nStart of message for url :" << url.spec(); |
|
viettrungluu
2014/06/30 19:16:55
Maybe you should just generate the same string (as
ananta
2014/07/03 00:04:40
Done.
|
| + DLOG(INFO) << "Message Time Hours :" << exploded.hour; |
| + DLOG(INFO) << "Message Time Mins :" << exploded.minute; |
| + DLOG(INFO) << "Message Time Secs :" << exploded.second; |
| + DLOG(INFO) << "Message Bytes : " << message_header.num_bytes; |
| + DLOG(INFO) << "Message Fields : " << message_header.num_fields; |
| + DLOG(INFO) << "Message name : " << message_header.name; |
| + if (message_header.num_fields == 3) { |
| + DLOG(INFO) << "Message has request id"; |
| + DLOG(INFO) << "Message Request ID : " |
| + << message_header.request_id; |
| + } |
| + if (message_header.flags & mojo::kMessageExpectsResponse) { |
| + DLOG(INFO) << "Message expects response"; |
| + } else if (message_header.flags & mojo::kMessageIsResponse) { |
| + DLOG(INFO) << "Message is response"; |
| + } |
| + DLOG(INFO) << "End of message : "; |
| + } |
| +} |
| + |
| void WebSocketServer::OnHttpRequest( |
| int connection_id, |
| const net::HttpServerRequestInfo& info) { |
| @@ -67,4 +125,8 @@ void WebSocketServer::OnClose( |
| connection_id_ = kNotConnected; |
| } |
| +bool WebSocketServer::Connected() const { |
| + return connection_id_ != kNotConnected; |
| +} |
| + |
| } // namespace spy |