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

Side by Side Diff: net/server/http_server.cc

Issue 1893083002: Change scoped_ptr to std::unique_ptr in //net. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptr-net-all: iwyu Created 4 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 unified diff | Download patch
« no previous file with comments | « net/server/http_server.h ('k') | net/server/http_server_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/server/http_server.h" 5 #include "net/server/http_server.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ptr_util.h"
13 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
14 #include "base/stl_util.h" 15 #include "base/stl_util.h"
15 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
17 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
18 #include "base/sys_byteorder.h" 19 #include "base/sys_byteorder.h"
19 #include "base/thread_task_runner_handle.h" 20 #include "base/thread_task_runner_handle.h"
20 #include "build/build_config.h" 21 #include "build/build_config.h"
21 #include "net/base/net_errors.h" 22 #include "net/base/net_errors.h"
22 #include "net/server/http_connection.h" 23 #include "net/server/http_connection.h"
23 #include "net/server/http_server_request_info.h" 24 #include "net/server/http_server_request_info.h"
24 #include "net/server/http_server_response_info.h" 25 #include "net/server/http_server_response_info.h"
25 #include "net/server/web_socket.h" 26 #include "net/server/web_socket.h"
26 #include "net/socket/server_socket.h" 27 #include "net/socket/server_socket.h"
27 #include "net/socket/stream_socket.h" 28 #include "net/socket/stream_socket.h"
28 #include "net/socket/tcp_server_socket.h" 29 #include "net/socket/tcp_server_socket.h"
29 30
30 namespace net { 31 namespace net {
31 32
32 HttpServer::HttpServer(scoped_ptr<ServerSocket> server_socket, 33 HttpServer::HttpServer(std::unique_ptr<ServerSocket> server_socket,
33 HttpServer::Delegate* delegate) 34 HttpServer::Delegate* delegate)
34 : server_socket_(std::move(server_socket)), 35 : server_socket_(std::move(server_socket)),
35 delegate_(delegate), 36 delegate_(delegate),
36 last_id_(0), 37 last_id_(0),
37 weak_ptr_factory_(this) { 38 weak_ptr_factory_(this) {
38 DCHECK(server_socket_); 39 DCHECK(server_socket_);
39 // Start accepting connections in next run loop in case when delegate is not 40 // Start accepting connections in next run loop in case when delegate is not
40 // ready to get callbacks. 41 // ready to get callbacks.
41 base::ThreadTaskRunnerHandle::Get()->PostTask( 42 base::ThreadTaskRunnerHandle::Get()->PostTask(
42 FROM_HERE, 43 FROM_HERE,
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 if (!ParseHeaders(read_buf->StartOfBuffer(), read_buf->GetSize(), 233 if (!ParseHeaders(read_buf->StartOfBuffer(), read_buf->GetSize(),
233 &request, &pos)) { 234 &request, &pos)) {
234 break; 235 break;
235 } 236 }
236 237
237 // Sets peer address if exists. 238 // Sets peer address if exists.
238 connection->socket()->GetPeerAddress(&request.peer); 239 connection->socket()->GetPeerAddress(&request.peer);
239 240
240 if (request.HasHeaderValue("connection", "upgrade")) { 241 if (request.HasHeaderValue("connection", "upgrade")) {
241 connection->SetWebSocket( 242 connection->SetWebSocket(
242 make_scoped_ptr(new WebSocket(this, connection))); 243 base::WrapUnique(new WebSocket(this, connection)));
243 read_buf->DidConsume(pos); 244 read_buf->DidConsume(pos);
244 delegate_->OnWebSocketRequest(connection->id(), request); 245 delegate_->OnWebSocketRequest(connection->id(), request);
245 if (HasClosedConnection(connection)) 246 if (HasClosedConnection(connection))
246 return ERR_CONNECTION_CLOSED; 247 return ERR_CONNECTION_CLOSED;
247 continue; 248 continue;
248 } 249 }
249 250
250 const char kContentLength[] = "content-length"; 251 const char kContentLength[] = "content-length";
251 if (request.headers.count(kContentLength) > 0) { 252 if (request.headers.count(kContentLength) > 0) {
252 size_t content_length = 0; 253 size_t content_length = 0;
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 462
462 // This is called after any delegate callbacks are called to check if Close() 463 // This is called after any delegate callbacks are called to check if Close()
463 // has been called during callback processing. Using the pointer of connection, 464 // has been called during callback processing. Using the pointer of connection,
464 // |connection| is safe here because Close() deletes the connection in next run 465 // |connection| is safe here because Close() deletes the connection in next run
465 // loop. 466 // loop.
466 bool HttpServer::HasClosedConnection(HttpConnection* connection) { 467 bool HttpServer::HasClosedConnection(HttpConnection* connection) {
467 return FindConnection(connection->id()) != connection; 468 return FindConnection(connection->id()) != connection;
468 } 469 }
469 470
470 } // namespace net 471 } // namespace net
OLDNEW
« no previous file with comments | « net/server/http_server.h ('k') | net/server/http_server_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698