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

Unified Diff: components/ui_devtools/devtools_server.cc

Issue 2455833002: Pass task_runner_ to server and send 404 when incorrect url (Closed)
Patch Set: Created 4 years, 2 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: components/ui_devtools/devtools_server.cc
diff --git a/components/ui_devtools/devtools_server.cc b/components/ui_devtools/devtools_server.cc
index 32818171c97e9c274b1fcb659d0eb9954d2295da..40ff1f24f2b9fc099b0da3495cf9f1e3cff12e91 100644
--- a/components/ui_devtools/devtools_server.cc
+++ b/components/ui_devtools/devtools_server.cc
@@ -27,13 +27,17 @@ const char kChromeDeveloperToolsPrefix[] =
"chrome-devtools://devtools/bundled/inspector.html?ws=";
} // namespace
-UiDevToolsServer::UiDevToolsServer()
- : thread_(new base::Thread("UiDevToolsServerThread")) {}
+UiDevToolsServer::UiDevToolsServer(
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner)
+ : task_runner_(task_runner) {
+ DCHECK(task_runner_);
+}
UiDevToolsServer::~UiDevToolsServer() {}
// static
-std::unique_ptr<UiDevToolsServer> UiDevToolsServer::Create() {
+std::unique_ptr<UiDevToolsServer> UiDevToolsServer::Create(
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
std::unique_ptr<UiDevToolsServer> server;
if (base::CommandLine::ForCurrentProcess()->HasSwitch(kEnableUiDevTools)) {
// TODO(mhashmi): Change port if more than one inspectable clients
@@ -42,7 +46,7 @@ std::unique_ptr<UiDevToolsServer> UiDevToolsServer::Create() {
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
kEnableUiDevTools),
&port);
- server.reset(new UiDevToolsServer());
+ server.reset(new UiDevToolsServer(task_runner));
server->Start("127.0.0.1", port);
}
return server;
@@ -54,24 +58,16 @@ void UiDevToolsServer::AttachClient(std::unique_ptr<UiDevToolsClient> client) {
void UiDevToolsServer::SendOverWebSocket(int connection_id,
const String& message) {
- thread_->task_runner()->PostTask(
+ task_runner_->PostTask(
FROM_HERE,
base::Bind(&net::HttpServer::SendOverWebSocket,
base::Unretained(server_.get()), connection_id, message));
}
void UiDevToolsServer::Start(const std::string& address_string, uint16_t port) {
- if (thread_ && thread_->IsRunning())
- return;
-
- // Start IO thread upon which all the methods will run
- base::Thread::Options options;
- options.message_loop_type = base::MessageLoop::TYPE_IO;
- if (thread_->StartWithOptions(options)) {
- thread_->task_runner()->PostTask(
- FROM_HERE, base::Bind(&UiDevToolsServer::StartServer,
- base::Unretained(this), address_string, port));
- }
+ task_runner_->PostTask(
+ FROM_HERE, base::Bind(&UiDevToolsServer::StartServer,
+ base::Unretained(this), address_string, port));
}
void UiDevToolsServer::StartServer(const std::string& address_string,
@@ -109,11 +105,15 @@ void UiDevToolsServer::OnHttpRequest(int connection_id,
ip.ToString().c_str(), i);
}
clientHTML += "</html>";
- thread_->task_runner()->PostTask(
+ task_runner_->PostTask(
FROM_HERE,
base::Bind(&net::HttpServer::Send200, base::Unretained(server_.get()),
connection_id, clientHTML, "text/html"));
+ return;
}
+ task_runner_->PostTask(
+ FROM_HERE, base::Bind(&net::HttpServer::Send404,
+ base::Unretained(server_.get()), connection_id));
}
void UiDevToolsServer::OnWebSocketRequest(
@@ -131,7 +131,7 @@ void UiDevToolsServer::OnWebSocketRequest(
return;
client->set_connection_id(connection_id);
connections_[connection_id] = client;
- thread_->task_runner()->PostTask(
+ task_runner_->PostTask(
FROM_HERE,
base::Bind(&net::HttpServer::AcceptWebSocket,
base::Unretained(server_.get()), connection_id, info));
@@ -143,14 +143,14 @@ void UiDevToolsServer::OnWebSocketMessage(int connection_id,
DCHECK(it != connections_.end());
UiDevToolsClient* client = it->second;
DCHECK(client);
- thread_->task_runner()->PostTask(
- FROM_HERE,
- base::Bind(&UiDevToolsClient::Dispatch, base::Unretained(client), data));
+ task_runner_->PostTask(FROM_HERE, base::Bind(&UiDevToolsClient::Dispatch,
+ base::Unretained(client), data));
}
void UiDevToolsServer::OnClose(int connection_id) {
ConnectionsMap::iterator it = connections_.find(connection_id);
- DCHECK(it != connections_.end());
+ if (it == connections_.end())
+ return;
sadrul 2016/10/28 02:32:27 Hm, any idea why this happens?
Sarmad Hashmi 2016/10/28 17:02:46 So, I realized we need this either way because if
UiDevToolsClient* client = it->second;
DCHECK(client);
client->set_connection_id(UiDevToolsClient::kNotConnected);
« components/ui_devtools/devtools_server.h ('K') | « components/ui_devtools/devtools_server.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698