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

Side by Side Diff: extensions/browser/api/socket/tls_socket.cc

Issue 598173003: Run clang-modernize -use-nullptr over src/extensions/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 "extensions/browser/api/socket/tls_socket.h" 5 #include "extensions/browser/api/socket/tls_socket.h"
6 6
7 #include "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "extensions/browser/api/api_resource.h" 9 #include "extensions/browser/api/api_resource.h"
10 #include "net/base/address_list.h" 10 #include "net/base/address_list.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 if (tls_socket_) { 87 if (tls_socket_) {
88 tls_socket_->Disconnect(); 88 tls_socket_->Disconnect();
89 tls_socket_.reset(); 89 tls_socket_.reset();
90 } 90 }
91 } 91 }
92 92
93 void TLSSocket::Read(int count, const ReadCompletionCallback& callback) { 93 void TLSSocket::Read(int count, const ReadCompletionCallback& callback) {
94 DCHECK(!callback.is_null()); 94 DCHECK(!callback.is_null());
95 95
96 if (!read_callback_.is_null()) { 96 if (!read_callback_.is_null()) {
97 callback.Run(net::ERR_IO_PENDING, NULL); 97 callback.Run(net::ERR_IO_PENDING, nullptr);
98 return; 98 return;
99 } 99 }
100 100
101 if (count <= 0) { 101 if (count <= 0) {
102 callback.Run(net::ERR_INVALID_ARGUMENT, NULL); 102 callback.Run(net::ERR_INVALID_ARGUMENT, nullptr);
103 return; 103 return;
104 } 104 }
105 105
106 if (!tls_socket_.get() || !IsConnected()) { 106 if (!tls_socket_.get() || !IsConnected()) {
107 callback.Run(net::ERR_SOCKET_NOT_CONNECTED, NULL); 107 callback.Run(net::ERR_SOCKET_NOT_CONNECTED, nullptr);
108 return; 108 return;
109 } 109 }
110 110
111 read_callback_ = callback; 111 read_callback_ = callback;
112 scoped_refptr<net::IOBuffer> io_buffer(new net::IOBuffer(count)); 112 scoped_refptr<net::IOBuffer> io_buffer(new net::IOBuffer(count));
113 // |tls_socket_| is owned by this class and the callback won't be run once 113 // |tls_socket_| is owned by this class and the callback won't be run once
114 // |tls_socket_| is gone (as in an a call to Disconnect()). Therefore, it is 114 // |tls_socket_| is gone (as in an a call to Disconnect()). Therefore, it is
115 // safe to use base::Unretained() here. 115 // safe to use base::Unretained() here.
116 int result = tls_socket_->Read( 116 int result = tls_socket_->Read(
117 io_buffer.get(), 117 io_buffer.get(),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 149
150 int TLSSocket::Listen(const std::string& address, 150 int TLSSocket::Listen(const std::string& address,
151 int port, 151 int port,
152 int backlog, 152 int backlog,
153 std::string* error_msg) { 153 std::string* error_msg) {
154 *error_msg = kTLSSocketTypeInvalidError; 154 *error_msg = kTLSSocketTypeInvalidError;
155 return net::ERR_NOT_IMPLEMENTED; 155 return net::ERR_NOT_IMPLEMENTED;
156 } 156 }
157 157
158 void TLSSocket::Accept(const AcceptCompletionCallback& callback) { 158 void TLSSocket::Accept(const AcceptCompletionCallback& callback) {
159 callback.Run(net::ERR_FAILED, NULL); 159 callback.Run(net::ERR_FAILED, nullptr);
160 } 160 }
161 161
162 bool TLSSocket::IsConnected() { 162 bool TLSSocket::IsConnected() {
163 return tls_socket_.get() && tls_socket_->IsConnected(); 163 return tls_socket_.get() && tls_socket_->IsConnected();
164 } 164 }
165 165
166 bool TLSSocket::GetPeerAddress(net::IPEndPoint* address) { 166 bool TLSSocket::GetPeerAddress(net::IPEndPoint* address) {
167 return IsConnected() && tls_socket_->GetPeerAddress(address); 167 return IsConnected() && tls_socket_->GetPeerAddress(address);
168 } 168 }
169 169
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 net::SSLClientSocket* saved_ssl_socket = ssl_socket.get(); 280 net::SSLClientSocket* saved_ssl_socket = ssl_socket.get();
281 281
282 // Try establish a TLS connection. Pass ownership of |ssl_socket| to 282 // Try establish a TLS connection. Pass ownership of |ssl_socket| to
283 // TlsConnectDone, which will pass it on to |callback|. |connect_cb| below 283 // TlsConnectDone, which will pass it on to |callback|. |connect_cb| below
284 // is only for UpgradeSocketToTLS use, and not be confused with the 284 // is only for UpgradeSocketToTLS use, and not be confused with the
285 // argument |callback|, which gets invoked by TlsConnectDone() after 285 // argument |callback|, which gets invoked by TlsConnectDone() after
286 // Connect() below returns. 286 // Connect() below returns.
287 base::Callback<void(int)> connect_cb(base::Bind( 287 base::Callback<void(int)> connect_cb(base::Bind(
288 &TlsConnectDone, base::Passed(&ssl_socket), extension_id, callback)); 288 &TlsConnectDone, base::Passed(&ssl_socket), extension_id, callback));
289 int status = saved_ssl_socket->Connect(connect_cb); 289 int status = saved_ssl_socket->Connect(connect_cb);
290 saved_ssl_socket = NULL; 290 saved_ssl_socket = nullptr;
291 291
292 // Connect completed synchronously, or failed. 292 // Connect completed synchronously, or failed.
293 if (status != net::ERR_IO_PENDING) { 293 if (status != net::ERR_IO_PENDING) {
294 // Note: this can't recurse -- if |socket| is already a connected 294 // Note: this can't recurse -- if |socket| is already a connected
295 // TLSSocket, it will return TYPE_TLS instead of TYPE_TCP, causing 295 // TLSSocket, it will return TYPE_TLS instead of TYPE_TCP, causing
296 // UpgradeSocketToTLS() to fail with an error above. If 296 // UpgradeSocketToTLS() to fail with an error above. If
297 // UpgradeSocketToTLS() is called on |socket| twice, the call to 297 // UpgradeSocketToTLS() is called on |socket| twice, the call to
298 // Release() on |socket| above causes the additional call to 298 // Release() on |socket| above causes the additional call to
299 // fail with an error above. 299 // fail with an error above.
300 if (status != net::OK) { 300 if (status != net::OK) {
301 DVLOG(1) << "Status is not OK or IO-pending: " 301 DVLOG(1) << "Status is not OK or IO-pending: "
302 << net::ErrorToString(status); 302 << net::ErrorToString(status);
303 } 303 }
304 connect_cb.Run(status); 304 connect_cb.Run(status);
305 } 305 }
306 } 306 }
307 307
308 } // namespace extensions 308 } // namespace extensions
309 309
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698