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

Side by Side Diff: content/browser/renderer_host/pepper/pepper_tcp_socket.cc

Issue 11275088: Remove implicit scoped_refptr operator T* Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 8 years, 1 month 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 (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 "content/browser/renderer_host/pepper/pepper_tcp_socket.h" 5 #include "content/browser/renderer_host/pepper/pepper_tcp_socket.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 SendReadACKError(); 161 SendReadACKError();
162 return; 162 return;
163 } 163 }
164 164
165 if (bytes_to_read > ppapi::TCPSocketPrivateImpl::kMaxReadSize) { 165 if (bytes_to_read > ppapi::TCPSocketPrivateImpl::kMaxReadSize) {
166 NOTREACHED(); 166 NOTREACHED();
167 bytes_to_read = ppapi::TCPSocketPrivateImpl::kMaxReadSize; 167 bytes_to_read = ppapi::TCPSocketPrivateImpl::kMaxReadSize;
168 } 168 }
169 169
170 read_buffer_ = new net::IOBuffer(bytes_to_read); 170 read_buffer_ = new net::IOBuffer(bytes_to_read);
171 int result = socket_->Read(read_buffer_, bytes_to_read, 171 int result = socket_->Read(read_buffer_.get(), bytes_to_read,
172 base::Bind(&PepperTCPSocket::OnReadCompleted, 172 base::Bind(&PepperTCPSocket::OnReadCompleted,
173 base::Unretained(this))); 173 base::Unretained(this)));
174 if (result != net::ERR_IO_PENDING) 174 if (result != net::ERR_IO_PENDING)
175 OnReadCompleted(result); 175 OnReadCompleted(result);
176 } 176 }
177 177
178 void PepperTCPSocket::Write(const std::string& data) { 178 void PepperTCPSocket::Write(const std::string& data) {
179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
180 180
181 if (!IsConnected() || write_buffer_base_.get() || write_buffer_.get() || 181 if (!IsConnected() || write_buffer_base_.get() || write_buffer_.get() ||
182 data.empty()) { 182 data.empty()) {
183 SendWriteACKError(); 183 SendWriteACKError();
184 return; 184 return;
185 } 185 }
186 186
187 int data_size = data.size(); 187 int data_size = data.size();
188 if (data_size > ppapi::TCPSocketPrivateImpl::kMaxWriteSize) { 188 if (data_size > ppapi::TCPSocketPrivateImpl::kMaxWriteSize) {
189 NOTREACHED(); 189 NOTREACHED();
190 data_size = ppapi::TCPSocketPrivateImpl::kMaxWriteSize; 190 data_size = ppapi::TCPSocketPrivateImpl::kMaxWriteSize;
191 } 191 }
192 192
193 write_buffer_base_ = new net::IOBuffer(data_size); 193 write_buffer_base_ = new net::IOBuffer(data_size);
194 memcpy(write_buffer_base_->data(), data.data(), data_size); 194 memcpy(write_buffer_base_->data(), data.data(), data_size);
195 write_buffer_ = new net::DrainableIOBuffer(write_buffer_base_, data_size); 195 write_buffer_ =
196 new net::DrainableIOBuffer(write_buffer_base_.get(), data_size);
196 DoWrite(); 197 DoWrite();
197 } 198 }
198 199
199 void PepperTCPSocket::StartConnect(const net::AddressList& addresses) { 200 void PepperTCPSocket::StartConnect(const net::AddressList& addresses) {
200 DCHECK(connection_state_ == CONNECT_IN_PROGRESS); 201 DCHECK(connection_state_ == CONNECT_IN_PROGRESS);
201 202
202 socket_.reset( 203 socket_.reset(
203 new net::TCPClientSocket(addresses, NULL, net::NetLog::Source())); 204 new net::TCPClientSocket(addresses, NULL, net::NetLog::Source()));
204 int result = socket_->Connect( 205 int result = socket_->Connect(
205 base::Bind(&PepperTCPSocket::OnConnectCompleted, 206 base::Bind(&PepperTCPSocket::OnConnectCompleted,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 265
265 // static 266 // static
266 bool PepperTCPSocket::GetCertificateFields( 267 bool PepperTCPSocket::GetCertificateFields(
267 const char* der, 268 const char* der,
268 uint32_t length, 269 uint32_t length,
269 ppapi::PPB_X509Certificate_Fields* fields) { 270 ppapi::PPB_X509Certificate_Fields* fields) {
270 scoped_refptr<net::X509Certificate> cert = 271 scoped_refptr<net::X509Certificate> cert =
271 net::X509Certificate::CreateFromBytes(der, length); 272 net::X509Certificate::CreateFromBytes(der, length);
272 if (!cert.get()) 273 if (!cert.get())
273 return false; 274 return false;
274 return GetCertificateFields(*cert, fields); 275 return GetCertificateFields(*cert.get(), fields);
275 } 276 }
276 277
277 void PepperTCPSocket::SendReadACKError() { 278 void PepperTCPSocket::SendReadACKError() {
278 manager_->Send(new PpapiMsg_PPBTCPSocket_ReadACK( 279 manager_->Send(new PpapiMsg_PPBTCPSocket_ReadACK(
279 routing_id_, plugin_dispatcher_id_, socket_id_, false, std::string())); 280 routing_id_, plugin_dispatcher_id_, socket_id_, false, std::string()));
280 } 281 }
281 282
282 void PepperTCPSocket::SendWriteACKError() { 283 void PepperTCPSocket::SendWriteACKError() {
283 manager_->Send(new PpapiMsg_PPBTCPSocket_WriteACK( 284 manager_->Send(new PpapiMsg_PPBTCPSocket_WriteACK(
284 routing_id_, plugin_dispatcher_id_, socket_id_, false, 0)); 285 routing_id_, plugin_dispatcher_id_, socket_id_, false, 0));
285 } 286 }
286 287
287 void PepperTCPSocket::SendSSLHandshakeACK(bool succeeded) { 288 void PepperTCPSocket::SendSSLHandshakeACK(bool succeeded) {
288 ppapi::PPB_X509Certificate_Fields certificate_fields; 289 ppapi::PPB_X509Certificate_Fields certificate_fields;
289 if (succeeded) { 290 if (succeeded) {
290 // Our socket is guaranteed to be an SSL socket if we get here. 291 // Our socket is guaranteed to be an SSL socket if we get here.
291 net::SSLClientSocket* ssl_socket = 292 net::SSLClientSocket* ssl_socket =
292 static_cast<net::SSLClientSocket*>(socket_.get()); 293 static_cast<net::SSLClientSocket*>(socket_.get());
293 net::SSLInfo ssl_info; 294 net::SSLInfo ssl_info;
294 ssl_socket->GetSSLInfo(&ssl_info); 295 ssl_socket->GetSSLInfo(&ssl_info);
295 if (ssl_info.cert.get()) 296 if (ssl_info.cert.get())
296 GetCertificateFields(*ssl_info.cert, &certificate_fields); 297 GetCertificateFields(*ssl_info.cert.get(), &certificate_fields);
297 } 298 }
298 manager_->Send(new PpapiMsg_PPBTCPSocket_SSLHandshakeACK( 299 manager_->Send(new PpapiMsg_PPBTCPSocket_SSLHandshakeACK(
299 routing_id_, 300 routing_id_,
300 plugin_dispatcher_id_, 301 plugin_dispatcher_id_,
301 socket_id_, 302 socket_id_,
302 succeeded, 303 succeeded,
303 certificate_fields)); 304 certificate_fields));
304 } 305 }
305 306
306 void PepperTCPSocket::OnResolveCompleted(int result) { 307 void PepperTCPSocket::OnResolveCompleted(int result) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 404
404 bool PepperTCPSocket::IsConnected() const { 405 bool PepperTCPSocket::IsConnected() const {
405 return connection_state_ == CONNECTED || connection_state_ == SSL_CONNECTED; 406 return connection_state_ == CONNECTED || connection_state_ == SSL_CONNECTED;
406 } 407 }
407 408
408 void PepperTCPSocket::DoWrite() { 409 void PepperTCPSocket::DoWrite() {
409 DCHECK(write_buffer_base_.get()); 410 DCHECK(write_buffer_base_.get());
410 DCHECK(write_buffer_.get()); 411 DCHECK(write_buffer_.get());
411 DCHECK_GT(write_buffer_->BytesRemaining(), 0); 412 DCHECK_GT(write_buffer_->BytesRemaining(), 0);
412 413
413 int result = socket_->Write(write_buffer_, write_buffer_->BytesRemaining(), 414 int result = socket_->
414 base::Bind(&PepperTCPSocket::OnWriteCompleted, 415 Write(write_buffer_.get(), write_buffer_->BytesRemaining(),
415 base::Unretained(this))); 416 base::Bind(&PepperTCPSocket::OnWriteCompleted,
417 base::Unretained(this)));
416 if (result != net::ERR_IO_PENDING) 418 if (result != net::ERR_IO_PENDING)
417 OnWriteCompleted(result); 419 OnWriteCompleted(result);
418 } 420 }
419 421
420 } // namespace content 422 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/p2p/socket_host_udp.cc ('k') | content/browser/renderer_host/pepper/pepper_udp_socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698