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

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

Issue 8804006: Reland 8688002: PPB_TCPSocket_Private/PPB_UDPSocket_Private are exposed to Browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed compilation for content_shell_lib 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"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "content/browser/renderer_host/pepper_message_filter.h" 13 #include "content/browser/renderer_host/pepper_message_filter.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 #include "net/base/cert_verifier.h" 15 #include "net/base/cert_verifier.h"
16 #include "net/base/host_port_pair.h" 16 #include "net/base/host_port_pair.h"
17 #include "net/base/host_resolver.h" 17 #include "net/base/host_resolver.h"
18 #include "net/base/io_buffer.h" 18 #include "net/base/io_buffer.h"
19 #include "net/base/ip_endpoint.h" 19 #include "net/base/ip_endpoint.h"
20 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
21 #include "net/base/single_request_host_resolver.h" 21 #include "net/base/single_request_host_resolver.h"
22 #include "net/socket/client_socket_factory.h" 22 #include "net/socket/client_socket_factory.h"
23 #include "net/socket/client_socket_handle.h" 23 #include "net/socket/client_socket_handle.h"
24 #include "net/socket/ssl_client_socket.h" 24 #include "net/socket/ssl_client_socket.h"
25 #include "net/socket/tcp_client_socket.h" 25 #include "net/socket/tcp_client_socket.h"
26 #include "ppapi/proxy/ppapi_messages.h" 26 #include "ppapi/proxy/ppapi_messages.h"
27 #include "ppapi/proxy/ppb_tcp_socket_private_proxy.h"
28 #include "ppapi/shared_impl/private/net_address_private_impl.h" 27 #include "ppapi/shared_impl/private/net_address_private_impl.h"
28 #include "ppapi/shared_impl/private/tcp_socket_private_impl.h"
29 29
30 using content::BrowserThread; 30 using content::BrowserThread;
31 using ppapi::NetAddressPrivateImpl; 31 using ppapi::NetAddressPrivateImpl;
32 32
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),
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 130
131 void PepperTCPSocket::Read(int32 bytes_to_read) { 131 void PepperTCPSocket::Read(int32 bytes_to_read) {
132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
133 133
134 if (!IsConnected() || end_of_file_reached_ || read_buffer_.get() || 134 if (!IsConnected() || end_of_file_reached_ || read_buffer_.get() ||
135 bytes_to_read <= 0) { 135 bytes_to_read <= 0) {
136 SendReadACKError(); 136 SendReadACKError();
137 return; 137 return;
138 } 138 }
139 139
140 if (bytes_to_read > ppapi::proxy::kTCPSocketMaxReadSize) { 140 if (bytes_to_read > ppapi::TCPSocketPrivateImpl::kMaxReadSize) {
141 NOTREACHED(); 141 NOTREACHED();
142 bytes_to_read = ppapi::proxy::kTCPSocketMaxReadSize; 142 bytes_to_read = ppapi::TCPSocketPrivateImpl::kMaxReadSize;
143 } 143 }
144 144
145 read_buffer_ = new net::IOBuffer(bytes_to_read); 145 read_buffer_ = new net::IOBuffer(bytes_to_read);
146 int result = socket_->Read(read_buffer_, bytes_to_read, &read_callback_); 146 int result = socket_->Read(read_buffer_, bytes_to_read, &read_callback_);
147 if (result != net::ERR_IO_PENDING) 147 if (result != net::ERR_IO_PENDING)
148 OnReadCompleted(result); 148 OnReadCompleted(result);
149 } 149 }
150 150
151 void PepperTCPSocket::Write(const std::string& data) { 151 void PepperTCPSocket::Write(const std::string& data) {
152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
153 153
154 if (!IsConnected() || write_buffer_.get() || data.empty()) { 154 if (!IsConnected() || write_buffer_.get() || data.empty()) {
155 SendWriteACKError(); 155 SendWriteACKError();
156 return; 156 return;
157 } 157 }
158 158
159 int data_size = data.size(); 159 int data_size = data.size();
160 if (data_size > ppapi::proxy::kTCPSocketMaxWriteSize) { 160 if (data_size > ppapi::TCPSocketPrivateImpl::kMaxWriteSize) {
161 NOTREACHED(); 161 NOTREACHED();
162 data_size = ppapi::proxy::kTCPSocketMaxWriteSize; 162 data_size = ppapi::TCPSocketPrivateImpl::kMaxWriteSize;
163 } 163 }
164 164
165 write_buffer_ = new net::IOBuffer(data_size); 165 write_buffer_ = new net::IOBuffer(data_size);
166 memcpy(write_buffer_->data(), data.c_str(), data_size); 166 memcpy(write_buffer_->data(), data.c_str(), data_size);
167 int result = socket_->Write(write_buffer_, data.size(), &write_callback_); 167 int result = socket_->Write(write_buffer_, data.size(), &write_callback_);
168 if (result != net::ERR_IO_PENDING) 168 if (result != net::ERR_IO_PENDING)
169 OnWriteCompleted(result); 169 OnWriteCompleted(result);
170 } 170 }
171 171
172 void PepperTCPSocket::StartConnect(const net::AddressList& addresses) { 172 void PepperTCPSocket::StartConnect(const net::AddressList& addresses) {
(...skipping 104 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

Powered by Google App Engine
This is Rietveld 408576698