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

Unified Diff: mojo/spy/spy.cc

Issue 284743002: Adding a mojo interface to the mojo spy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clang 2 Created 6 years, 7 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/spy.h ('k') | mojo/spy/spy_server_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/spy/spy.cc
diff --git a/mojo/spy/spy.cc b/mojo/spy/spy.cc
index eb20c5deb51715e2af7879f90dab507d41861708..c861bbb0aefe62095cadfaaff56bc37bab31fa90 100644
--- a/mojo/spy/spy.cc
+++ b/mojo/spy/spy.cc
@@ -4,10 +4,13 @@
#include "mojo/spy/spy.h"
+#include <vector>
+
#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/location.h"
#include "base/memory/ref_counted.h"
+#include "base/message_loop/message_loop_proxy.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/threading/thread.h"
@@ -15,7 +18,10 @@
#include "mojo/public/cpp/system/core.h"
#include "mojo/service_manager/service_manager.h"
+#include "mojo/spy/public/spy.mojom.h"
+#include "mojo/spy/spy_server_impl.h"
#include "mojo/spy/websocket_server.h"
+#include "url/gurl.h"
namespace {
@@ -33,11 +39,9 @@ void CloseHandles(MojoHandle* handles, size_t count) {
class MessageProcessor :
public base::RefCountedThreadSafe<MessageProcessor> {
public:
-
MessageProcessor()
: last_result_(MOJO_RESULT_OK),
bytes_transfered_(0) {
-
message_count_[0] = 0;
message_count_[1] = 0;
handle_count_[0] = 0;
@@ -107,24 +111,30 @@ class MessageProcessor :
}
private:
- friend class base::RefCountedThreadSafe<MessageProcessor>;
- virtual ~MessageProcessor() {}
-
- bool CheckResult(MojoResult mr) {
- if (mr == MOJO_RESULT_OK)
- return true;
- last_result_ = mr;
- return false;
- }
-
- MojoResult last_result_;
- uint32_t bytes_transfered_;
- uint32_t message_count_[2];
- uint32_t handle_count_[2];
+ friend class base::RefCountedThreadSafe<MessageProcessor>;
+ virtual ~MessageProcessor() {}
+
+ bool CheckResult(MojoResult mr) {
+ if (mr == MOJO_RESULT_OK)
+ return true;
+ last_result_ = mr;
+ return false;
+ }
+
+ MojoResult last_result_;
+ uint32_t bytes_transfered_;
+ uint32_t message_count_[2];
+ uint32_t handle_count_[2];
};
// In charge of intercepting access to the service manager.
class SpyInterceptor : public mojo::ServiceManager::Interceptor {
+ public:
+ explicit SpyInterceptor(scoped_refptr<mojo::SpyServerImpl> spy_server)
+ : spy_server_(spy_server),
+ proxy_(base::MessageLoopProxy::current()) {
+ }
+
private:
virtual mojo::ScopedMessagePipeHandle OnConnectToClient(
const GURL& url, mojo::ScopedMessagePipeHandle real_client) OVERRIDE {
@@ -153,15 +163,21 @@ class SpyInterceptor : public mojo::ServiceManager::Interceptor {
bool MustIntercept(const GURL& url) {
// TODO(cpu): manage who and when to intercept.
+ proxy_->PostTask(
+ FROM_HERE,
+ base::Bind(&mojo::SpyServerImpl::OnIntercept, spy_server_, url));
return true;
}
+
+ scoped_refptr<mojo::SpyServerImpl> spy_server_;
+ scoped_refptr<base::MessageLoopProxy> proxy_;
};
-spy::WebSocketServer* ws_server = NULL;
+mojo::WebSocketServer* ws_server = NULL;
-void StartServer(int port) {
+void StartWebServer(int port, mojo::ScopedMessagePipeHandle pipe) {
// TODO(cpu) figure out lifetime of the server. See Spy() dtor.
- ws_server = new spy::WebSocketServer(port);
+ ws_server = new mojo::WebSocketServer(port, pipe.Pass());
ws_server->Start();
}
@@ -196,18 +212,23 @@ namespace mojo {
Spy::Spy(mojo::ServiceManager* service_manager, const std::string& options) {
SpyOptions spy_options = ProcessOptions(options);
+
+ spy_server_ = new SpyServerImpl();
+
// Start the tread what will accept commands from the frontend.
control_thread_.reset(new base::Thread("mojo_spy_control_thread"));
base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0);
control_thread_->StartWithOptions(thread_options);
control_thread_->message_loop_proxy()->PostTask(
- FROM_HERE, base::Bind(&StartServer, spy_options.websocket_port));
+ FROM_HERE, base::Bind(&StartWebServer,
+ spy_options.websocket_port,
+ base::Passed(spy_server_->ServerPipe())));
// Start intercepting mojo services.
- service_manager->SetInterceptor(new SpyInterceptor());
+ service_manager->SetInterceptor(new SpyInterceptor(spy_server_));
}
-Spy::~Spy(){
+Spy::~Spy() {
// TODO(cpu): Do not leak the interceptor. Lifetime between the
// service_manager and the spy is still unclear hence the leak.
}
« no previous file with comments | « mojo/spy/spy.h ('k') | mojo/spy/spy_server_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698