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

Unified Diff: mojo/spy/spy.cc

Issue 258693011: First cut at mojo spy's websocket server (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 6 years, 8 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/test/spy_repl_test.html » ('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 d29cea5417ea76040c582e1793c6e9084a09fa3d..eb20c5deb51715e2af7879f90dab507d41861708 100644
--- a/mojo/spy/spy.cc
+++ b/mojo/spy/spy.cc
@@ -8,15 +8,20 @@
#include "base/compiler_specific.h"
#include "base/location.h"
#include "base/memory/ref_counted.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_split.h"
+#include "base/threading/thread.h"
#include "base/threading/worker_pool.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/service_manager/service_manager.h"
+#include "mojo/spy/websocket_server.h"
namespace {
const size_t kMessageBufSize = 2 * 1024;
const size_t kHandleBufSize = 64;
+const int kDefaultWebSocketPort = 42424;
void CloseHandles(MojoHandle* handles, size_t count) {
for (size_t ix = 0; ix != count; ++count)
@@ -127,7 +132,7 @@ class SpyInterceptor : public mojo::ServiceManager::Interceptor {
return real_client.Pass();
// You can get an invalid handle if the app (or service) is
- // by unconventional means, for example the command line.
+ // created by unconventional means, for example the command line.
if (!real_client.is_valid())
return real_client.Pass();
@@ -152,11 +157,53 @@ class SpyInterceptor : public mojo::ServiceManager::Interceptor {
}
};
+spy::WebSocketServer* ws_server = NULL;
+
+void StartServer(int port) {
+ // TODO(cpu) figure out lifetime of the server. See Spy() dtor.
+ ws_server = new spy::WebSocketServer(port);
+ ws_server->Start();
+}
+
+struct SpyOptions {
+ int websocket_port;
+
+ SpyOptions()
+ : websocket_port(kDefaultWebSocketPort) {
+ }
+};
+
+SpyOptions ProcessOptions(const std::string& options) {
+ SpyOptions spy_options;
+ if (options.empty())
+ return spy_options;
+ base::StringPairs kv_pairs;
+ base::SplitStringIntoKeyValuePairs(options, ':', ',', &kv_pairs);
+ base::StringPairs::iterator it = kv_pairs.begin();
+ for (; it != kv_pairs.end(); ++it) {
+ if (it->first == "port") {
+ int port;
+ if (base::StringToInt(it->second, &port))
+ spy_options.websocket_port = port;
+ }
+ }
+ return spy_options;
+}
+
} // namespace
namespace mojo {
Spy::Spy(mojo::ServiceManager* service_manager, const std::string& options) {
+ SpyOptions spy_options = ProcessOptions(options);
+ // 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));
+
+ // Start intercepting mojo services.
service_manager->SetInterceptor(new SpyInterceptor());
}
« no previous file with comments | « mojo/spy/spy.h ('k') | mojo/spy/test/spy_repl_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698