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

Side by Side Diff: components/ui_devtools/devtools_server.cc

Issue 2928603002: Create and remove |UiDevToolsServer::server_| in the same thread. (Closed)
Patch Set: . Created 3 years, 5 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 unified diff | Download patch
« no previous file with comments | « components/ui_devtools/devtools_server.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/ui_devtools/devtools_server.h" 5 #include "components/ui_devtools/devtools_server.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/format_macros.h" 10 #include "base/format_macros.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 return; 58 return;
59 // If io_thread_task_runner not passed in, create an I/O thread 59 // If io_thread_task_runner not passed in, create an I/O thread
60 thread_.reset(new base::Thread("UiDevToolsServerThread")); 60 thread_.reset(new base::Thread("UiDevToolsServerThread"));
61 base::Thread::Options options; 61 base::Thread::Options options;
62 options.message_loop_type = base::MessageLoop::TYPE_IO; 62 options.message_loop_type = base::MessageLoop::TYPE_IO;
63 CHECK(thread_->StartWithOptions(options)); 63 CHECK(thread_->StartWithOptions(options));
64 io_thread_task_runner_ = thread_->task_runner(); 64 io_thread_task_runner_ = thread_->task_runner();
65 } 65 }
66 66
67 UiDevToolsServer::~UiDevToolsServer() { 67 UiDevToolsServer::~UiDevToolsServer() {
68 DCHECK(io_thread_task_runner_);
69 io_thread_task_runner_->PostTask(
70 FROM_HERE,
71 base::Bind(&UiDevToolsServer::StopServer, base::Unretained(this)));
72 if (thread_->IsRunning())
sadrul 2017/06/26 22:43:30 This will not work when |io_thread_task_runner_| h
thanhph 2017/06/27 15:02:29 To elaborate more, with current patch 1, does this
sadrul 2017/06/28 04:49:10 No. The problem with this change was, that if UiDe
thanhph 2017/06/28 14:38:22 Acknowledged! Thanks for the explanation.
73 thread_->Stop();
68 devtools_server_ = nullptr; 74 devtools_server_ = nullptr;
69 } 75 }
70 76
71 // static 77 // static
72 std::unique_ptr<UiDevToolsServer> UiDevToolsServer::Create( 78 std::unique_ptr<UiDevToolsServer> UiDevToolsServer::Create(
73 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner) { 79 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner) {
74 std::unique_ptr<UiDevToolsServer> server; 80 std::unique_ptr<UiDevToolsServer> server;
75 if (IsUiDevToolsEnabled() && !devtools_server_) { 81 if (IsUiDevToolsEnabled() && !devtools_server_) {
76 // TODO(mhashmi): Change port if more than one inspectable clients 82 // TODO(mhashmi): Change port if more than one inspectable clients
77 server.reset(new UiDevToolsServer(io_thread_task_runner)); 83 server.reset(new UiDevToolsServer(io_thread_task_runner));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 DCHECK(!server_); 126 DCHECK(!server_);
121 std::unique_ptr<net::ServerSocket> socket( 127 std::unique_ptr<net::ServerSocket> socket(
122 new net::TCPServerSocket(nullptr, net::NetLogSource())); 128 new net::TCPServerSocket(nullptr, net::NetLogSource()));
123 constexpr int kBacklog = 1; 129 constexpr int kBacklog = 1;
124 if (socket->ListenWithAddressAndPort(address_string, port, kBacklog) != 130 if (socket->ListenWithAddressAndPort(address_string, port, kBacklog) !=
125 net::OK) 131 net::OK)
126 return; 132 return;
127 server_ = base::MakeUnique<net::HttpServer>(std::move(socket), this); 133 server_ = base::MakeUnique<net::HttpServer>(std::move(socket), this);
128 } 134 }
129 135
136 void UiDevToolsServer::StopServer() {
137 server_.reset();
138 }
139
130 // HttpServer::Delegate Implementation 140 // HttpServer::Delegate Implementation
131 void UiDevToolsServer::OnConnect(int connection_id) { 141 void UiDevToolsServer::OnConnect(int connection_id) {
132 NOTIMPLEMENTED(); 142 NOTIMPLEMENTED();
133 } 143 }
134 144
135 void UiDevToolsServer::OnHttpRequest(int connection_id, 145 void UiDevToolsServer::OnHttpRequest(int connection_id,
136 const net::HttpServerRequestInfo& info) { 146 const net::HttpServerRequestInfo& info) {
137 NOTIMPLEMENTED(); 147 NOTIMPLEMENTED();
138 } 148 }
139 149
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 return; 185 return;
176 UiDevToolsClient* client = it->second; 186 UiDevToolsClient* client = it->second;
177 DCHECK(client); 187 DCHECK(client);
178 main_thread_task_runner_->PostTask( 188 main_thread_task_runner_->PostTask(
179 FROM_HERE, 189 FROM_HERE,
180 base::Bind(&UiDevToolsClient::Disconnect, base::Unretained(client))); 190 base::Bind(&UiDevToolsClient::Disconnect, base::Unretained(client)));
181 connections_.erase(it); 191 connections_.erase(it);
182 } 192 }
183 193
184 } // namespace ui_devtools 194 } // namespace ui_devtools
OLDNEW
« no previous file with comments | « components/ui_devtools/devtools_server.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698