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

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

Issue 216473002: Replace DCHECK(BrowserThread::CurrentlyOn) with DCHECK_CURRENTLY_ON in content/browser/renderer_hos… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to r260263 Created 6 years, 8 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 | Annotate | Revision Log
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 DCHECK(manager); 71 DCHECK(manager);
72 } 72 }
73 73
74 PepperTCPSocket::~PepperTCPSocket() { 74 PepperTCPSocket::~PepperTCPSocket() {
75 // Make sure no further callbacks from socket_. 75 // Make sure no further callbacks from socket_.
76 if (socket_) 76 if (socket_)
77 socket_->Disconnect(); 77 socket_->Disconnect();
78 } 78 }
79 79
80 void PepperTCPSocket::Connect(const std::string& host, uint16_t port) { 80 void PepperTCPSocket::Connect(const std::string& host, uint16_t port) {
81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 81 DCHECK_CURRENTLY_ON(BrowserThread::IO);
82 82
83 if (connection_state_ != BEFORE_CONNECT) { 83 if (connection_state_ != BEFORE_CONNECT) {
84 SendConnectACKError(PP_ERROR_FAILED); 84 SendConnectACKError(PP_ERROR_FAILED);
85 return; 85 return;
86 } 86 }
87 87
88 connection_state_ = CONNECT_IN_PROGRESS; 88 connection_state_ = CONNECT_IN_PROGRESS;
89 net::HostResolver::RequestInfo request_info(net::HostPortPair(host, port)); 89 net::HostResolver::RequestInfo request_info(net::HostPortPair(host, port));
90 resolver_.reset( 90 resolver_.reset(
91 new net::SingleRequestHostResolver(manager_->GetHostResolver())); 91 new net::SingleRequestHostResolver(manager_->GetHostResolver()));
92 int net_result = resolver_->Resolve( 92 int net_result = resolver_->Resolve(
93 request_info, 93 request_info,
94 net::DEFAULT_PRIORITY, 94 net::DEFAULT_PRIORITY,
95 &address_list_, 95 &address_list_,
96 base::Bind(&PepperTCPSocket::OnResolveCompleted, base::Unretained(this)), 96 base::Bind(&PepperTCPSocket::OnResolveCompleted, base::Unretained(this)),
97 net::BoundNetLog()); 97 net::BoundNetLog());
98 if (net_result != net::ERR_IO_PENDING) 98 if (net_result != net::ERR_IO_PENDING)
99 OnResolveCompleted(net_result); 99 OnResolveCompleted(net_result);
100 } 100 }
101 101
102 void PepperTCPSocket::ConnectWithNetAddress( 102 void PepperTCPSocket::ConnectWithNetAddress(
103 const PP_NetAddress_Private& net_addr) { 103 const PP_NetAddress_Private& net_addr) {
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 104 DCHECK_CURRENTLY_ON(BrowserThread::IO);
105 105
106 if (connection_state_ != BEFORE_CONNECT) { 106 if (connection_state_ != BEFORE_CONNECT) {
107 SendConnectACKError(PP_ERROR_FAILED); 107 SendConnectACKError(PP_ERROR_FAILED);
108 return; 108 return;
109 } 109 }
110 110
111 net::IPAddressNumber address; 111 net::IPAddressNumber address;
112 int port; 112 int port;
113 if (!NetAddressPrivateImpl::NetAddressToIPEndPoint(net_addr, &address, 113 if (!NetAddressPrivateImpl::NetAddressToIPEndPoint(net_addr, &address,
114 &port)) { 114 &port)) {
115 SendConnectACKError(PP_ERROR_ADDRESS_INVALID); 115 SendConnectACKError(PP_ERROR_ADDRESS_INVALID);
116 return; 116 return;
117 } 117 }
118 118
119 // Copy the single IPEndPoint to address_list_. 119 // Copy the single IPEndPoint to address_list_.
120 address_list_.clear(); 120 address_list_.clear();
121 address_list_.push_back(net::IPEndPoint(address, port)); 121 address_list_.push_back(net::IPEndPoint(address, port));
122 connection_state_ = CONNECT_IN_PROGRESS; 122 connection_state_ = CONNECT_IN_PROGRESS;
123 StartConnect(address_list_); 123 StartConnect(address_list_);
124 } 124 }
125 125
126 void PepperTCPSocket::SSLHandshake( 126 void PepperTCPSocket::SSLHandshake(
127 const std::string& server_name, 127 const std::string& server_name,
128 uint16_t server_port, 128 uint16_t server_port,
129 const std::vector<std::vector<char> >& trusted_certs, 129 const std::vector<std::vector<char> >& trusted_certs,
130 const std::vector<std::vector<char> >& untrusted_certs) { 130 const std::vector<std::vector<char> >& untrusted_certs) {
131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 131 DCHECK_CURRENTLY_ON(BrowserThread::IO);
132 132
133 // Allow to do SSL handshake only if currently the socket has been connected 133 // Allow to do SSL handshake only if currently the socket has been connected
134 // and there isn't pending read or write. 134 // and there isn't pending read or write.
135 // IsConnected() includes the state that SSL handshake has been finished and 135 // IsConnected() includes the state that SSL handshake has been finished and
136 // therefore isn't suitable here. 136 // therefore isn't suitable here.
137 if (connection_state_ != CONNECTED || read_buffer_.get() || 137 if (connection_state_ != CONNECTED || read_buffer_.get() ||
138 write_buffer_base_.get() || write_buffer_.get()) { 138 write_buffer_base_.get() || write_buffer_.get()) {
139 SendSSLHandshakeACK(false); 139 SendSSLHandshakeACK(false);
140 return; 140 return;
141 } 141 }
(...skipping 18 matching lines...) Expand all
160 } 160 }
161 161
162 int net_result = socket_->Connect( 162 int net_result = socket_->Connect(
163 base::Bind(&PepperTCPSocket::OnSSLHandshakeCompleted, 163 base::Bind(&PepperTCPSocket::OnSSLHandshakeCompleted,
164 base::Unretained(this))); 164 base::Unretained(this)));
165 if (net_result != net::ERR_IO_PENDING) 165 if (net_result != net::ERR_IO_PENDING)
166 OnSSLHandshakeCompleted(net_result); 166 OnSSLHandshakeCompleted(net_result);
167 } 167 }
168 168
169 void PepperTCPSocket::Read(int32 bytes_to_read) { 169 void PepperTCPSocket::Read(int32 bytes_to_read) {
170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 170 DCHECK_CURRENTLY_ON(BrowserThread::IO);
171 171
172 if (!IsConnected() || end_of_file_reached_) { 172 if (!IsConnected() || end_of_file_reached_) {
173 SendReadACKError(PP_ERROR_FAILED); 173 SendReadACKError(PP_ERROR_FAILED);
174 return; 174 return;
175 } 175 }
176 176
177 if (read_buffer_.get()) { 177 if (read_buffer_.get()) {
178 SendReadACKError(PP_ERROR_INPROGRESS); 178 SendReadACKError(PP_ERROR_INPROGRESS);
179 return; 179 return;
180 } 180 }
181 181
182 if (bytes_to_read <= 0 || 182 if (bytes_to_read <= 0 ||
183 bytes_to_read > ppapi::TCPSocketShared::kMaxReadSize) { 183 bytes_to_read > ppapi::TCPSocketShared::kMaxReadSize) {
184 SendReadACKError(PP_ERROR_BADARGUMENT); 184 SendReadACKError(PP_ERROR_BADARGUMENT);
185 return; 185 return;
186 } 186 }
187 187
188 read_buffer_ = new net::IOBuffer(bytes_to_read); 188 read_buffer_ = new net::IOBuffer(bytes_to_read);
189 int net_result = socket_->Read( 189 int net_result = socket_->Read(
190 read_buffer_.get(), 190 read_buffer_.get(),
191 bytes_to_read, 191 bytes_to_read,
192 base::Bind(&PepperTCPSocket::OnReadCompleted, base::Unretained(this))); 192 base::Bind(&PepperTCPSocket::OnReadCompleted, base::Unretained(this)));
193 if (net_result != net::ERR_IO_PENDING) 193 if (net_result != net::ERR_IO_PENDING)
194 OnReadCompleted(net_result); 194 OnReadCompleted(net_result);
195 } 195 }
196 196
197 void PepperTCPSocket::Write(const std::string& data) { 197 void PepperTCPSocket::Write(const std::string& data) {
198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 198 DCHECK_CURRENTLY_ON(BrowserThread::IO);
199 199
200 if (!IsConnected()) { 200 if (!IsConnected()) {
201 SendWriteACKError(PP_ERROR_FAILED); 201 SendWriteACKError(PP_ERROR_FAILED);
202 return; 202 return;
203 } 203 }
204 204
205 if (write_buffer_base_.get() || write_buffer_.get()) { 205 if (write_buffer_base_.get() || write_buffer_.get()) {
206 SendWriteACKError(PP_ERROR_INPROGRESS); 206 SendWriteACKError(PP_ERROR_INPROGRESS);
207 return; 207 return;
208 } 208 }
209 209
210 size_t data_size = data.size(); 210 size_t data_size = data.size();
211 if (data_size == 0 || 211 if (data_size == 0 ||
212 data_size > static_cast<size_t>(ppapi::TCPSocketShared::kMaxWriteSize)) { 212 data_size > static_cast<size_t>(ppapi::TCPSocketShared::kMaxWriteSize)) {
213 SendWriteACKError(PP_ERROR_BADARGUMENT); 213 SendWriteACKError(PP_ERROR_BADARGUMENT);
214 return; 214 return;
215 } 215 }
216 216
217 write_buffer_base_ = new net::IOBuffer(data_size); 217 write_buffer_base_ = new net::IOBuffer(data_size);
218 memcpy(write_buffer_base_->data(), data.data(), data_size); 218 memcpy(write_buffer_base_->data(), data.data(), data_size);
219 write_buffer_ = 219 write_buffer_ =
220 new net::DrainableIOBuffer(write_buffer_base_.get(), data_size); 220 new net::DrainableIOBuffer(write_buffer_base_.get(), data_size);
221 DoWrite(); 221 DoWrite();
222 } 222 }
223 223
224 void PepperTCPSocket::SetOption(PP_TCPSocket_Option name, 224 void PepperTCPSocket::SetOption(PP_TCPSocket_Option name,
225 const ppapi::SocketOptionData& value) { 225 const ppapi::SocketOptionData& value) {
226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 226 DCHECK_CURRENTLY_ON(BrowserThread::IO);
227 227
228 if (!IsConnected() || IsSsl()) { 228 if (!IsConnected() || IsSsl()) {
229 SendSetOptionACK(PP_ERROR_FAILED); 229 SendSetOptionACK(PP_ERROR_FAILED);
230 return; 230 return;
231 } 231 }
232 232
233 net::TCPClientSocket* tcp_socket = 233 net::TCPClientSocket* tcp_socket =
234 static_cast<net::TCPClientSocket*>(socket_.get()); 234 static_cast<net::TCPClientSocket*>(socket_.get());
235 DCHECK(tcp_socket); 235 DCHECK(tcp_socket);
236 236
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 518
519 int net_result = socket_->Write( 519 int net_result = socket_->Write(
520 write_buffer_.get(), 520 write_buffer_.get(),
521 write_buffer_->BytesRemaining(), 521 write_buffer_->BytesRemaining(),
522 base::Bind(&PepperTCPSocket::OnWriteCompleted, base::Unretained(this))); 522 base::Bind(&PepperTCPSocket::OnWriteCompleted, base::Unretained(this)));
523 if (net_result != net::ERR_IO_PENDING) 523 if (net_result != net::ERR_IO_PENDING)
524 OnWriteCompleted(net_result); 524 OnWriteCompleted(net_result);
525 } 525 }
526 526
527 } // namespace content 527 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698