| Index: trunk/src/mojo/spy/spy.cc
|
| ===================================================================
|
| --- trunk/src/mojo/spy/spy.cc (revision 272462)
|
| +++ trunk/src/mojo/spy/spy.cc (working copy)
|
| @@ -4,13 +4,10 @@
|
|
|
| #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"
|
| @@ -18,10 +15,7 @@
|
|
|
| #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 {
|
|
|
| @@ -39,9 +33,11 @@
|
| 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;
|
| @@ -111,30 +107,24 @@
|
| }
|
|
|
| private:
|
| - friend class base::RefCountedThreadSafe<MessageProcessor>;
|
| - virtual ~MessageProcessor() {}
|
| + friend class base::RefCountedThreadSafe<MessageProcessor>;
|
| + virtual ~MessageProcessor() {}
|
|
|
| - bool CheckResult(MojoResult mr) {
|
| - if (mr == MOJO_RESULT_OK)
|
| - return true;
|
| - last_result_ = mr;
|
| - return false;
|
| - }
|
| + 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];
|
| + 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 {
|
| @@ -163,21 +153,15 @@
|
|
|
| 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_;
|
| };
|
|
|
| -mojo::WebSocketServer* ws_server = NULL;
|
| +spy::WebSocketServer* ws_server = NULL;
|
|
|
| -void StartWebServer(int port, mojo::ScopedMessagePipeHandle pipe) {
|
| +void StartServer(int port) {
|
| // TODO(cpu) figure out lifetime of the server. See Spy() dtor.
|
| - ws_server = new mojo::WebSocketServer(port, pipe.Pass());
|
| + ws_server = new spy::WebSocketServer(port);
|
| ws_server->Start();
|
| }
|
|
|
| @@ -212,23 +196,18 @@
|
|
|
| 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(&StartWebServer,
|
| - spy_options.websocket_port,
|
| - base::Passed(spy_server_->ServerPipe())));
|
| + FROM_HERE, base::Bind(&StartServer, spy_options.websocket_port));
|
|
|
| // Start intercepting mojo services.
|
| - service_manager->SetInterceptor(new SpyInterceptor(spy_server_));
|
| + service_manager->SetInterceptor(new SpyInterceptor());
|
| }
|
|
|
| -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.
|
| }
|
|
|