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

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

Issue 8688002: PPB_TCPSocket_Private/PPB_UDPSocket_Private are exposed to Browser (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added PPAPI_IN_PROCESS TCP and UDP tests. 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
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" 27 #include "ppapi/proxy/ppb_tcp_socket_private_proxy.h"
yzshen1 2011/11/30 21:11:04 Remove this one.
ygorshenin 2011/12/01 10:58:31 Done.
28 #include "ppapi/shared_impl/private/net_address_private_impl.h" 28 #include "ppapi/shared_impl/private/net_address_private_impl.h"
29 #include "ppapi/shared_impl/tcp_socket_impl.h"
29 30
30 using content::BrowserThread; 31 using content::BrowserThread;
31 using ppapi::NetAddressPrivateImpl; 32 using ppapi::NetAddressPrivateImpl;
32 33
33 PepperTCPSocket::PepperTCPSocket( 34 PepperTCPSocket::PepperTCPSocket(
34 PepperMessageFilter* manager, 35 PepperMessageFilter* manager,
35 int32 routing_id, 36 int32 routing_id,
36 uint32 plugin_dispatcher_id, 37 uint32 plugin_dispatcher_id,
37 uint32 socket_id) 38 uint32 socket_id)
38 : manager_(manager), 39 : manager_(manager),
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 131
131 void PepperTCPSocket::Read(int32 bytes_to_read) { 132 void PepperTCPSocket::Read(int32 bytes_to_read) {
132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
133 134
134 if (!IsConnected() || end_of_file_reached_ || read_buffer_.get() || 135 if (!IsConnected() || end_of_file_reached_ || read_buffer_.get() ||
135 bytes_to_read <= 0) { 136 bytes_to_read <= 0) {
136 SendReadACKError(); 137 SendReadACKError();
137 return; 138 return;
138 } 139 }
139 140
140 if (bytes_to_read > ppapi::proxy::kTCPSocketMaxReadSize) { 141 if (bytes_to_read > ppapi::TCPSocketImpl::kMaxReadSize) {
141 NOTREACHED(); 142 NOTREACHED();
142 bytes_to_read = ppapi::proxy::kTCPSocketMaxReadSize; 143 bytes_to_read = ppapi::TCPSocketImpl::kMaxReadSize;
143 } 144 }
144 145
145 read_buffer_ = new net::IOBuffer(bytes_to_read); 146 read_buffer_ = new net::IOBuffer(bytes_to_read);
146 int result = socket_->Read(read_buffer_, bytes_to_read, &read_callback_); 147 int result = socket_->Read(read_buffer_, bytes_to_read, &read_callback_);
147 if (result != net::ERR_IO_PENDING) 148 if (result != net::ERR_IO_PENDING)
148 OnReadCompleted(result); 149 OnReadCompleted(result);
149 } 150 }
150 151
151 void PepperTCPSocket::Write(const std::string& data) { 152 void PepperTCPSocket::Write(const std::string& data) {
152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
153 154
154 if (!IsConnected() || write_buffer_.get() || data.empty()) { 155 if (!IsConnected() || write_buffer_.get() || data.empty()) {
155 SendWriteACKError(); 156 SendWriteACKError();
156 return; 157 return;
157 } 158 }
158 159
159 int data_size = data.size(); 160 int data_size = data.size();
160 if (data_size > ppapi::proxy::kTCPSocketMaxWriteSize) { 161 if (data_size > ppapi::TCPSocketImpl::kMaxWriteSize) {
161 NOTREACHED(); 162 NOTREACHED();
162 data_size = ppapi::proxy::kTCPSocketMaxWriteSize; 163 data_size = ppapi::TCPSocketImpl::kMaxWriteSize;
163 } 164 }
164 165
165 write_buffer_ = new net::IOBuffer(data_size); 166 write_buffer_ = new net::IOBuffer(data_size);
166 memcpy(write_buffer_->data(), data.c_str(), data_size); 167 memcpy(write_buffer_->data(), data.c_str(), data_size);
167 int result = socket_->Write(write_buffer_, data.size(), &write_callback_); 168 int result = socket_->Write(write_buffer_, data.size(), &write_callback_);
168 if (result != net::ERR_IO_PENDING) 169 if (result != net::ERR_IO_PENDING)
169 OnWriteCompleted(result); 170 OnWriteCompleted(result);
170 } 171 }
171 172
172 void PepperTCPSocket::StartConnect(const net::AddressList& addresses) { 173 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)); 278 routing_id_, plugin_dispatcher_id_, socket_id_, true, result));
278 } else { 279 } else {
279 SendWriteACKError(); 280 SendWriteACKError();
280 } 281 }
281 write_buffer_ = NULL; 282 write_buffer_ = NULL;
282 } 283 }
283 284
284 bool PepperTCPSocket::IsConnected() const { 285 bool PepperTCPSocket::IsConnected() const {
285 return connection_state_ == CONNECTED || connection_state_ == SSL_CONNECTED; 286 return connection_state_ == CONNECTED || connection_state_ == SSL_CONNECTED;
286 } 287 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698