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

Unified Diff: mojo/spy/spy.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: Fixed indentation Created 6 years, 6 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: mojo/spy/spy.cc
diff --git a/mojo/spy/spy.cc b/mojo/spy/spy.cc
index 3fcc49c3d66798b6fdc14f047f58be15ef59e144..911889b3c52be37fe20a0d846e3c5450c9f5f24b 100644
--- a/mojo/spy/spy.cc
+++ b/mojo/spy/spy.cc
@@ -7,7 +7,9 @@
#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/location.h"
+#include "base/logging.h"
#include "base/memory/ref_counted.h"
+#include "base/time/time.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/threading/thread.h"
@@ -15,10 +17,13 @@
#include "mojo/public/cpp/system/core.h"
#include "mojo/service_manager/service_manager.h"
+#include "mojo/spy/common.h"
#include "mojo/spy/websocket_server.h"
namespace {
+spy::WebSocketServer* ws_server = NULL;
+
const size_t kMessageBufSize = 2 * 1024;
const size_t kHandleBufSize = 64;
const int kDefaultWebSocketPort = 42424;
@@ -34,9 +39,10 @@ class MessageProcessor :
public base::RefCountedThreadSafe<MessageProcessor> {
public:
- MessageProcessor()
+ MessageProcessor(base::MessageLoopProxy* control_loop_proxy)
: last_result_(MOJO_RESULT_OK),
- bytes_transfered_(0) {
+ bytes_transfered_(0),
+ control_loop_proxy_(control_loop_proxy) {
message_count_[0] = 0;
message_count_[1] = 0;
@@ -45,7 +51,8 @@ class MessageProcessor :
}
void Start(mojo::ScopedMessagePipeHandle client,
- mojo::ScopedMessagePipeHandle interceptor) {
+ mojo::ScopedMessagePipeHandle interceptor,
+ const GURL& url) {
std::vector<mojo::MessagePipeHandle> pipes;
pipes.push_back(client.get());
pipes.push_back(interceptor.get());
@@ -88,6 +95,8 @@ class MessageProcessor :
++message_count_[r];
bytes_transfered_ += bytes_read;
+ LogMessageInfo(mbuf.get(), url);
+
mojo::MessagePipeHandle write_handle = (r == 0) ? pipes[1] : pipes[0];
if (!CheckResult(Wait(write_handle,
MOJO_HANDLE_SIGNAL_WRITABLE,
@@ -117,14 +126,29 @@ class MessageProcessor :
return false;
}
+ void LogMessageInfo(void* data, const GURL& url) {
+ mojo::MojoMessageData* message_data =
+ reinterpret_cast<mojo::MojoMessageData*>(data);
+ control_loop_proxy_->PostTask(
+ FROM_HERE,
+ base::Bind(&spy::WebSocketServer::LogMessageInfo,
+ base::Unretained(ws_server),
+ message_data->header, url, base::Time::Now()));
+ }
+
MojoResult last_result_;
uint32_t bytes_transfered_;
uint32_t message_count_[2];
uint32_t handle_count_[2];
+ scoped_refptr<base::MessageLoopProxy> control_loop_proxy_;
};
// In charge of intercepting access to the service manager.
class SpyInterceptor : public mojo::ServiceManager::Interceptor {
+ public:
+ SpyInterceptor(base::MessageLoopProxy* control_loop_proxy)
+ : control_loop_proxy_(control_loop_proxy) {}
+
private:
virtual mojo::ScopedMessagePipeHandle OnConnectToClient(
const GURL& url, mojo::ScopedMessagePipeHandle real_client) OVERRIDE {
@@ -140,12 +164,14 @@ class SpyInterceptor : public mojo::ServiceManager::Interceptor {
mojo::ScopedMessagePipeHandle interceptor;
CreateMessagePipe(NULL, &faux_client, &interceptor);
- scoped_refptr<MessageProcessor> processor = new MessageProcessor();
+ scoped_refptr<MessageProcessor> processor = new MessageProcessor(
+ control_loop_proxy_);
base::WorkerPool::PostTask(
FROM_HERE,
base::Bind(&MessageProcessor::Start,
processor,
- base::Passed(&real_client), base::Passed(&interceptor)),
+ base::Passed(&real_client), base::Passed(&interceptor),
+ url),
true);
return faux_client.Pass();
@@ -155,9 +181,9 @@ class SpyInterceptor : public mojo::ServiceManager::Interceptor {
// TODO(cpu): manage who and when to intercept.
return true;
}
-};
-spy::WebSocketServer* ws_server = NULL;
+ scoped_refptr<base::MessageLoopProxy> control_loop_proxy_;
+};
void StartServer(int port) {
// TODO(cpu) figure out lifetime of the server. See Spy() dtor.
@@ -204,7 +230,8 @@ Spy::Spy(mojo::ServiceManager* service_manager, const std::string& options) {
FROM_HERE, base::Bind(&StartServer, spy_options.websocket_port));
// Start intercepting mojo services.
- service_manager->SetInterceptor(new SpyInterceptor());
+ service_manager->SetInterceptor(new SpyInterceptor(
+ control_thread_->message_loop_proxy()));
}
Spy::~Spy(){
« no previous file with comments | « mojo/spy/common.h ('k') | mojo/spy/websocket_server.h » ('j') | mojo/spy/websocket_server.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698