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

Side by Side Diff: content/browser/devtools/protocol/tethering_handler.cc

Issue 2435863004: Remove stl_util's deletion function use from content/. (Closed)
Patch Set: minus service worker 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/browser/devtools/protocol/tethering_handler.h" 5 #include "content/browser/devtools/protocol/tethering_handler.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "content/public/browser/browser_thread.h" 8 #include "content/public/browser/browser_thread.h"
9 #include "net/base/io_buffer.h" 9 #include "net/base/io_buffer.h"
10 #include "net/base/ip_address.h" 10 #include "net/base/ip_address.h"
11 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
12 #include "net/log/net_log_source.h" 12 #include "net/log/net_log_source.h"
13 #include "net/socket/server_socket.h" 13 #include "net/socket/server_socket.h"
14 #include "net/socket/stream_socket.h" 14 #include "net/socket/stream_socket.h"
15 #include "net/socket/tcp_server_socket.h" 15 #include "net/socket/tcp_server_socket.h"
16 16
17 namespace content { 17 namespace content {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 void Unbind(DevToolsCommandId command_id, uint16_t port); 240 void Unbind(DevToolsCommandId command_id, uint16_t port);
241 void Accepted(uint16_t port, const std::string& name); 241 void Accepted(uint16_t port, const std::string& name);
242 242
243 private: 243 private:
244 void SendInternalError(DevToolsCommandId command_id, 244 void SendInternalError(DevToolsCommandId command_id,
245 const std::string& message); 245 const std::string& message);
246 246
247 base::WeakPtr<TetheringHandler> handler_; 247 base::WeakPtr<TetheringHandler> handler_;
248 CreateServerSocketCallback socket_callback_; 248 CreateServerSocketCallback socket_callback_;
249 249
250 typedef std::map<uint16_t, BoundSocket*> BoundSockets; 250 std::map<uint16_t, std::unique_ptr<BoundSocket>> bound_sockets_;
251 BoundSockets bound_sockets_;
252 }; 251 };
253 252
254 TetheringHandler::TetheringImpl::TetheringImpl( 253 TetheringHandler::TetheringImpl::TetheringImpl(
255 base::WeakPtr<TetheringHandler> handler, 254 base::WeakPtr<TetheringHandler> handler,
256 const CreateServerSocketCallback& socket_callback) 255 const CreateServerSocketCallback& socket_callback)
257 : handler_(handler), 256 : handler_(handler),
258 socket_callback_(socket_callback) { 257 socket_callback_(socket_callback) {
259 } 258 }
260 259
261 TetheringHandler::TetheringImpl::~TetheringImpl() { 260 TetheringHandler::TetheringImpl::~TetheringImpl() = default;
262 base::STLDeleteValues(&bound_sockets_);
263 }
264 261
265 void TetheringHandler::TetheringImpl::Bind(DevToolsCommandId command_id, 262 void TetheringHandler::TetheringImpl::Bind(DevToolsCommandId command_id,
266 uint16_t port) { 263 uint16_t port) {
267 if (bound_sockets_.find(port) != bound_sockets_.end()) { 264 if (bound_sockets_.find(port) != bound_sockets_.end()) {
268 SendInternalError(command_id, "Port already bound"); 265 SendInternalError(command_id, "Port already bound");
269 return; 266 return;
270 } 267 }
271 268
272 BoundSocket::AcceptedCallback callback = base::Bind( 269 BoundSocket::AcceptedCallback callback = base::Bind(
273 &TetheringHandler::TetheringImpl::Accepted, base::Unretained(this)); 270 &TetheringHandler::TetheringImpl::Accepted, base::Unretained(this));
274 std::unique_ptr<BoundSocket> bound_socket( 271 std::unique_ptr<BoundSocket> bound_socket =
275 new BoundSocket(callback, socket_callback_)); 272 base::MakeUnique<BoundSocket>(callback, socket_callback_);
276 if (!bound_socket->Listen(port)) { 273 if (!bound_socket->Listen(port)) {
277 SendInternalError(command_id, "Could not bind port"); 274 SendInternalError(command_id, "Could not bind port");
278 return; 275 return;
279 } 276 }
280 277
281 bound_sockets_[port] = bound_socket.release(); 278 bound_sockets_[port] = std::move(bound_socket);
282 BrowserThread::PostTask( 279 BrowserThread::PostTask(
283 BrowserThread::UI, 280 BrowserThread::UI,
284 FROM_HERE, 281 FROM_HERE,
285 base::Bind(&TetheringHandler::SendBindSuccess, handler_, command_id)); 282 base::Bind(&TetheringHandler::SendBindSuccess, handler_, command_id));
286 } 283 }
287 284
288 void TetheringHandler::TetheringImpl::Unbind(DevToolsCommandId command_id, 285 void TetheringHandler::TetheringImpl::Unbind(DevToolsCommandId command_id,
289 uint16_t port) { 286 uint16_t port) {
290 BoundSockets::iterator it = bound_sockets_.find(port); 287 auto it = bound_sockets_.find(port);
291 if (it == bound_sockets_.end()) { 288 if (it == bound_sockets_.end()) {
292 SendInternalError(command_id, "Port is not bound"); 289 SendInternalError(command_id, "Port is not bound");
293 return; 290 return;
294 } 291 }
295 292
296 delete it->second;
297 bound_sockets_.erase(it); 293 bound_sockets_.erase(it);
298 BrowserThread::PostTask( 294 BrowserThread::PostTask(
299 BrowserThread::UI, 295 BrowserThread::UI,
300 FROM_HERE, 296 FROM_HERE,
301 base::Bind(&TetheringHandler::SendUnbindSuccess, handler_, command_id)); 297 base::Bind(&TetheringHandler::SendUnbindSuccess, handler_, command_id));
302 } 298 }
303 299
304 void TetheringHandler::TetheringImpl::Accepted(uint16_t port, 300 void TetheringHandler::TetheringImpl::Accepted(uint16_t port,
305 const std::string& name) { 301 const std::string& name) {
306 BrowserThread::PostTask( 302 BrowserThread::PostTask(
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 } 390 }
395 391
396 void TetheringHandler::SendInternalError(DevToolsCommandId command_id, 392 void TetheringHandler::SendInternalError(DevToolsCommandId command_id,
397 const std::string& message) { 393 const std::string& message) {
398 client_->SendError(command_id, Response::InternalError(message)); 394 client_->SendError(command_id, Response::InternalError(message));
399 } 395 }
400 396
401 } // namespace tethering 397 } // namespace tethering
402 } // namespace devtools 398 } // namespace devtools
403 } // namespace content 399 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698