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

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

Issue 8824006: Migrate net/socket/socket.h, net/socket/stream_socket.h to base::Bind(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_tcp_socket.h" 5 #include "content/browser/renderer_host/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 22 matching lines...) Expand all
33 PepperTCPSocket::PepperTCPSocket( 33 PepperTCPSocket::PepperTCPSocket(
34 PepperMessageFilter* manager, 34 PepperMessageFilter* manager,
35 int32 routing_id, 35 int32 routing_id,
36 uint32 plugin_dispatcher_id, 36 uint32 plugin_dispatcher_id,
37 uint32 socket_id) 37 uint32 socket_id)
38 : manager_(manager), 38 : manager_(manager),
39 routing_id_(routing_id), 39 routing_id_(routing_id),
40 plugin_dispatcher_id_(plugin_dispatcher_id), 40 plugin_dispatcher_id_(plugin_dispatcher_id),
41 socket_id_(socket_id), 41 socket_id_(socket_id),
42 connection_state_(BEFORE_CONNECT), 42 connection_state_(BEFORE_CONNECT),
43 end_of_file_reached_(false), 43 end_of_file_reached_(false) {
44 ALLOW_THIS_IN_INITIALIZER_LIST(connect_callback_(
45 this, &PepperTCPSocket::OnConnectCompleted)),
46 ALLOW_THIS_IN_INITIALIZER_LIST(ssl_handshake_callback_(
47 this, &PepperTCPSocket::OnSSLHandshakeCompleted)),
48 ALLOW_THIS_IN_INITIALIZER_LIST(
49 read_callback_(this, &PepperTCPSocket::OnReadCompleted)),
50 ALLOW_THIS_IN_INITIALIZER_LIST(
51 write_callback_(this, &PepperTCPSocket::OnWriteCompleted)) {
52 DCHECK(manager); 44 DCHECK(manager);
53 } 45 }
54 46
55 PepperTCPSocket::~PepperTCPSocket() { 47 PepperTCPSocket::~PepperTCPSocket() {
56 // Make sure no further callbacks from socket_. 48 // Make sure no further callbacks from socket_.
57 if (socket_.get()) 49 if (socket_.get())
58 socket_->Disconnect(); 50 socket_->Disconnect();
59 } 51 }
60 52
61 void PepperTCPSocket::Connect(const std::string& host, uint16_t port) { 53 void PepperTCPSocket::Connect(const std::string& host, uint16_t port) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 net::SSLClientSocketContext ssl_context; 108 net::SSLClientSocketContext ssl_context;
117 ssl_context.cert_verifier = manager_->GetCertVerifier(); 109 ssl_context.cert_verifier = manager_->GetCertVerifier();
118 socket_.reset(factory->CreateSSLClientSocket( 110 socket_.reset(factory->CreateSSLClientSocket(
119 handle, host_port_pair, manager_->ssl_config(), NULL, ssl_context)); 111 handle, host_port_pair, manager_->ssl_config(), NULL, ssl_context));
120 if (!socket_.get()) { 112 if (!socket_.get()) {
121 LOG(WARNING) << "Failed to create an SSL client socket."; 113 LOG(WARNING) << "Failed to create an SSL client socket.";
122 OnSSLHandshakeCompleted(net::ERR_UNEXPECTED); 114 OnSSLHandshakeCompleted(net::ERR_UNEXPECTED);
123 return; 115 return;
124 } 116 }
125 117
126 int result = socket_->Connect(&ssl_handshake_callback_); 118 int result = socket_->Connect(
119 base::Bind(&PepperTCPSocket::OnSSLHandshakeCompleted,
120 base::Unretained(this)));
127 if (result != net::ERR_IO_PENDING) 121 if (result != net::ERR_IO_PENDING)
128 OnSSLHandshakeCompleted(result); 122 OnSSLHandshakeCompleted(result);
129 } 123 }
130 124
131 void PepperTCPSocket::Read(int32 bytes_to_read) { 125 void PepperTCPSocket::Read(int32 bytes_to_read) {
132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
133 127
134 if (!IsConnected() || end_of_file_reached_ || read_buffer_.get() || 128 if (!IsConnected() || end_of_file_reached_ || read_buffer_.get() ||
135 bytes_to_read <= 0) { 129 bytes_to_read <= 0) {
136 SendReadACKError(); 130 SendReadACKError();
137 return; 131 return;
138 } 132 }
139 133
140 if (bytes_to_read > ppapi::TCPSocketPrivateImpl::kMaxReadSize) { 134 if (bytes_to_read > ppapi::TCPSocketPrivateImpl::kMaxReadSize) {
141 NOTREACHED(); 135 NOTREACHED();
142 bytes_to_read = ppapi::TCPSocketPrivateImpl::kMaxReadSize; 136 bytes_to_read = ppapi::TCPSocketPrivateImpl::kMaxReadSize;
143 } 137 }
144 138
145 read_buffer_ = new net::IOBuffer(bytes_to_read); 139 read_buffer_ = new net::IOBuffer(bytes_to_read);
146 int result = socket_->Read(read_buffer_, bytes_to_read, &read_callback_); 140 int result = socket_->Read(read_buffer_, bytes_to_read,
141 base::Bind(&PepperTCPSocket::OnReadCompleted,
142 base::Unretained(this)));
147 if (result != net::ERR_IO_PENDING) 143 if (result != net::ERR_IO_PENDING)
148 OnReadCompleted(result); 144 OnReadCompleted(result);
149 } 145 }
150 146
151 void PepperTCPSocket::Write(const std::string& data) { 147 void PepperTCPSocket::Write(const std::string& data) {
152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
153 149
154 if (!IsConnected() || write_buffer_.get() || data.empty()) { 150 if (!IsConnected() || write_buffer_.get() || data.empty()) {
155 SendWriteACKError(); 151 SendWriteACKError();
156 return; 152 return;
157 } 153 }
158 154
159 int data_size = data.size(); 155 int data_size = data.size();
160 if (data_size > ppapi::TCPSocketPrivateImpl::kMaxWriteSize) { 156 if (data_size > ppapi::TCPSocketPrivateImpl::kMaxWriteSize) {
161 NOTREACHED(); 157 NOTREACHED();
162 data_size = ppapi::TCPSocketPrivateImpl::kMaxWriteSize; 158 data_size = ppapi::TCPSocketPrivateImpl::kMaxWriteSize;
163 } 159 }
164 160
165 write_buffer_ = new net::IOBuffer(data_size); 161 write_buffer_ = new net::IOBuffer(data_size);
166 memcpy(write_buffer_->data(), data.c_str(), data_size); 162 memcpy(write_buffer_->data(), data.c_str(), data_size);
167 int result = socket_->Write(write_buffer_, data.size(), &write_callback_); 163 int result = socket_->Write(write_buffer_, data.size(),
164 base::Bind(&PepperTCPSocket::OnWriteCompleted,
165 base::Unretained(this)));
168 if (result != net::ERR_IO_PENDING) 166 if (result != net::ERR_IO_PENDING)
169 OnWriteCompleted(result); 167 OnWriteCompleted(result);
170 } 168 }
171 169
172 void PepperTCPSocket::StartConnect(const net::AddressList& addresses) { 170 void PepperTCPSocket::StartConnect(const net::AddressList& addresses) {
173 DCHECK(connection_state_ == CONNECT_IN_PROGRESS); 171 DCHECK(connection_state_ == CONNECT_IN_PROGRESS);
174 172
175 socket_.reset( 173 socket_.reset(
176 new net::TCPClientSocket(addresses, NULL, net::NetLog::Source())); 174 new net::TCPClientSocket(addresses, NULL, net::NetLog::Source()));
177 int result = socket_->Connect(&connect_callback_); 175 int result = socket_->Connect(
176 base::Bind(&PepperTCPSocket::OnConnectCompleted,
177 base::Unretained(this)));
178 if (result != net::ERR_IO_PENDING) 178 if (result != net::ERR_IO_PENDING)
179 OnConnectCompleted(result); 179 OnConnectCompleted(result);
180 } 180 }
181 181
182 void PepperTCPSocket::SendConnectACKError() { 182 void PepperTCPSocket::SendConnectACKError() {
183 manager_->Send(new PpapiMsg_PPBTCPSocket_ConnectACK( 183 manager_->Send(new PpapiMsg_PPBTCPSocket_ConnectACK(
184 routing_id_, plugin_dispatcher_id_, socket_id_, false, 184 routing_id_, plugin_dispatcher_id_, socket_id_, false,
185 NetAddressPrivateImpl::kInvalidNetAddress, 185 NetAddressPrivateImpl::kInvalidNetAddress,
186 NetAddressPrivateImpl::kInvalidNetAddress)); 186 NetAddressPrivateImpl::kInvalidNetAddress));
187 } 187 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 routing_id_, plugin_dispatcher_id_, socket_id_, true, result)); 277 routing_id_, plugin_dispatcher_id_, socket_id_, true, result));
278 } else { 278 } else {
279 SendWriteACKError(); 279 SendWriteACKError();
280 } 280 }
281 write_buffer_ = NULL; 281 write_buffer_ = NULL;
282 } 282 }
283 283
284 bool PepperTCPSocket::IsConnected() const { 284 bool PepperTCPSocket::IsConnected() const {
285 return connection_state_ == CONNECTED || connection_state_ == SSL_CONNECTED; 285 return connection_state_ == CONNECTED || connection_state_ == SSL_CONNECTED;
286 } 286 }
OLDNEW
« no previous file with comments | « content/browser/renderer_host/pepper_tcp_socket.h ('k') | content/browser/renderer_host/pepper_udp_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698