OLD | NEW |
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 "net/cert_net/nss_ocsp.h" | 5 #include "net/cert_net/nss_ocsp.h" |
6 | 6 |
7 #include <certt.h> | 7 #include <certt.h> |
8 #include <certdb.h> | 8 #include <certdb.h> |
9 #include <nspr.h> | 9 #include <nspr.h> |
10 #include <nss.h> | 10 #include <nss.h> |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 DCHECK_EQ(request_.get(), request); | 292 DCHECK_EQ(request_.get(), request); |
293 DCHECK_EQ(base::MessageLoopForIO::current(), io_loop_); | 293 DCHECK_EQ(base::MessageLoopForIO::current(), io_loop_); |
294 | 294 |
295 if (!redirect_info.new_url.SchemeIs("http")) { | 295 if (!redirect_info.new_url.SchemeIs("http")) { |
296 // Prevent redirects to non-HTTP schemes, including HTTPS. This matches | 296 // Prevent redirects to non-HTTP schemes, including HTTPS. This matches |
297 // the initial check in OCSPServerSession::CreateRequest(). | 297 // the initial check in OCSPServerSession::CreateRequest(). |
298 CancelURLRequest(); | 298 CancelURLRequest(); |
299 } | 299 } |
300 } | 300 } |
301 | 301 |
302 void OnResponseStarted(URLRequest* request, int net_error) override { | 302 void OnResponseStarted(URLRequest* request) override { |
303 DCHECK_EQ(request_.get(), request); | 303 DCHECK_EQ(request_.get(), request); |
304 DCHECK_EQ(base::MessageLoopForIO::current(), io_loop_); | 304 DCHECK_EQ(base::MessageLoopForIO::current(), io_loop_); |
305 DCHECK_NE(ERR_IO_PENDING, net_error); | |
306 | 305 |
307 int bytes_read = 0; | 306 int bytes_read = 0; |
308 if (net_error == OK) { | 307 if (request->status().is_success()) { |
309 response_code_ = request_->GetResponseCode(); | 308 response_code_ = request_->GetResponseCode(); |
310 response_headers_ = request_->response_headers(); | 309 response_headers_ = request_->response_headers(); |
311 response_headers_->GetMimeType(&response_content_type_); | 310 response_headers_->GetMimeType(&response_content_type_); |
312 bytes_read = request_->Read(buffer_.get(), kRecvBufferSize); | 311 request_->Read(buffer_.get(), kRecvBufferSize, &bytes_read); |
313 } | 312 } |
314 OnReadCompleted(request_.get(), bytes_read); | 313 OnReadCompleted(request_.get(), bytes_read); |
315 } | 314 } |
316 | 315 |
317 void OnReadCompleted(URLRequest* request, int bytes_read) override { | 316 void OnReadCompleted(URLRequest* request, int bytes_read) override { |
318 DCHECK_EQ(request_.get(), request); | 317 DCHECK_EQ(request_.get(), request); |
319 DCHECK_EQ(base::MessageLoopForIO::current(), io_loop_); | 318 DCHECK_EQ(base::MessageLoopForIO::current(), io_loop_); |
320 | 319 |
321 while (bytes_read > 0) { | 320 do { |
| 321 if (!request_->status().is_success() || bytes_read <= 0) |
| 322 break; |
322 data_.append(buffer_->data(), bytes_read); | 323 data_.append(buffer_->data(), bytes_read); |
323 bytes_read = request_->Read(buffer_.get(), kRecvBufferSize); | 324 } while (request_->Read(buffer_.get(), kRecvBufferSize, &bytes_read)); |
324 } | |
325 | 325 |
326 if (bytes_read != ERR_IO_PENDING) { | 326 if (!request_->status().is_io_pending()) { |
327 request_.reset(); | 327 request_.reset(); |
328 g_ocsp_io_loop.Get().RemoveRequest(this); | 328 g_ocsp_io_loop.Get().RemoveRequest(this); |
329 { | 329 { |
330 base::AutoLock autolock(lock_); | 330 base::AutoLock autolock(lock_); |
331 finished_ = true; | 331 finished_ = true; |
332 io_loop_ = NULL; | 332 io_loop_ = NULL; |
333 } | 333 } |
334 cv_.Signal(); | 334 cv_.Signal(); |
335 Release(); // Balanced with StartURLRequest(). | 335 Release(); // Balanced with StartURLRequest(). |
336 } | 336 } |
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 void SetURLRequestContextForNSSHttpIO(URLRequestContext* request_context) { | 964 void SetURLRequestContextForNSSHttpIO(URLRequestContext* request_context) { |
965 pthread_mutex_lock(&g_request_context_lock); | 965 pthread_mutex_lock(&g_request_context_lock); |
966 if (request_context) { | 966 if (request_context) { |
967 DCHECK(!g_request_context); | 967 DCHECK(!g_request_context); |
968 } | 968 } |
969 g_request_context = request_context; | 969 g_request_context = request_context; |
970 pthread_mutex_unlock(&g_request_context_lock); | 970 pthread_mutex_unlock(&g_request_context_lock); |
971 } | 971 } |
972 | 972 |
973 } // namespace net | 973 } // namespace net |
OLD | NEW |