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

Unified Diff: sky/tools/debugger/prompt/prompt.cc

Issue 841113003: Rewrite how skydb starts prompt.cc (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: updated Created 5 years, 11 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 | « no previous file | sky/tools/skydb » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/tools/debugger/prompt/prompt.cc
diff --git a/sky/tools/debugger/prompt/prompt.cc b/sky/tools/debugger/prompt/prompt.cc
index df7886548f6e526fefe59848d8123e3e07eedab2..58c2e240eec8b9255b6ccbe741983e77be336648 100644
--- a/sky/tools/debugger/prompt/prompt.cc
+++ b/sky/tools/debugger/prompt/prompt.cc
@@ -4,6 +4,8 @@
#include "base/bind.h"
#include "base/memory/weak_ptr.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/stringprintf.h"
#include "mojo/application/application_runner_chromium.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/application_delegate.h"
@@ -31,21 +33,20 @@ class Prompt : public mojo::ApplicationDelegate, public net::HttpServer::Delegat
// Overridden from mojo::ApplicationDelegate:
virtual void Initialize(mojo::ApplicationImpl* app) override {
app->ConnectToService("mojo:tracing", &tracing_);
- if (app->args().size() > 1)
- url_ = app->args()[1];
- else {
- url_ = "https://raw.githubusercontent.com/domokit/mojo/master/sky/"
- "examples/home.sky";
+ // app_url, command_port, url_to_load
+ if (app->args().size() < 2) {
+ LOG(ERROR) << "--args-for required to specify command_port";
+ exit(2);
}
+
+ base::StringToUint(app->args()[1], &command_port_);
+
scoped_ptr<net::ServerSocket> server_socket(
new net::TCPServerSocket(NULL, net::NetLog::Source()));
- // FIXME: This port needs to be configurable, as-is we can only run
- // one copy of mojo_shell with sky at a time!
- uint16 port = 7777;
- int result = server_socket->ListenWithAddressAndPort("0.0.0.0", port, 1);
+ int result = server_socket->ListenWithAddressAndPort("0.0.0.0", command_port_, 1);
if (result != net::OK) {
// FIXME: Should we quit here?
- LOG(ERROR) << "Failed to bind to port " << port
+ LOG(ERROR) << "Failed to bind to port " << command_port_
<< " skydb commands will not work, exiting.";
exit(2);
return;
@@ -56,7 +57,6 @@ class Prompt : public mojo::ApplicationDelegate, public net::HttpServer::Delegat
virtual bool ConfigureIncomingConnection(
mojo::ApplicationConnection* connection) override {
connection->ConnectToService(&debugger_);
- Reload();
return true;
}
@@ -102,13 +102,14 @@ class Prompt : public mojo::ApplicationDelegate, public net::HttpServer::Delegat
}
void Help(std::string path, int connection_id) {
- std::string help = "Sky Debugger\n"
+ std::string help = base::StringPrintf("Sky Debugger running on port %d\n"
"Supported URLs:\n"
"/toggle_tracing -- Start/stop tracing\n"
"/reload -- Reload the current page\n"
"/inspect -- Start inspector server for current page\n"
"/quit -- Quit\n"
- "/load -- Load a new URL, url in POST body.\n";
+ "/load -- Load a new URL, url in POST body.\n",
+ command_port_);
if (path != "/")
help = "Unknown path: " + path + "\n\n" + help;
Respond(connection_id, help);
@@ -117,7 +118,8 @@ class Prompt : public mojo::ApplicationDelegate, public net::HttpServer::Delegat
void Load(int connection_id, std::string url) {
url_ = url;
Reload();
- Respond(connection_id, "OK\n");
+ std::string response = std::string("Loaded ") + url + "\n";
+ Respond(connection_id, response);
}
void Reload() {
@@ -154,6 +156,7 @@ class Prompt : public mojo::ApplicationDelegate, public net::HttpServer::Delegat
std::string url_;
base::WeakPtrFactory<Prompt> weak_ptr_factory_;
scoped_ptr<net::HttpServer> web_server_;
+ unsigned command_port_;
jamesr 2015/01/08 23:50:38 please use uint32_t. unsigned is longer to type a
DISALLOW_COPY_AND_ASSIGN(Prompt);
};
« no previous file with comments | « no previous file | sky/tools/skydb » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698