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

Side by Side Diff: net/http/http_transaction_test_util.cc

Issue 2721933002: HttpCache::Transaction layer allowing parallel validation (Closed)
Patch Set: Feedback addressed Created 3 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
« no previous file with comments | « net/http/http_transaction_test_util.h ('k') | net/http/mock_http_cache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/http/http_transaction_test_util.h" 5 #include "net/http/http_transaction_test_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <unordered_map> 8 #include <unordered_map>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 // static 402 // static
403 const int64_t MockNetworkTransaction::kTotalSentBytes = 100; 403 const int64_t MockNetworkTransaction::kTotalSentBytes = 100;
404 404
405 int MockNetworkTransaction::StartInternal(const HttpRequestInfo* request, 405 int MockNetworkTransaction::StartInternal(const HttpRequestInfo* request,
406 const CompletionCallback& callback, 406 const CompletionCallback& callback,
407 const NetLogWithSource& net_log) { 407 const NetLogWithSource& net_log) {
408 const MockTransaction* t = FindMockTransaction(request->url); 408 const MockTransaction* t = FindMockTransaction(request->url);
409 if (!t) 409 if (!t)
410 return ERR_FAILED; 410 return ERR_FAILED;
411 411
412 if (!before_network_start_callback_.is_null()) {
413 bool defer = false;
414 before_network_start_callback_.Run(&defer);
415 if (defer)
416 return net::ERR_IO_PENDING;
417 }
418
419 test_mode_ = t->test_mode; 412 test_mode_ = t->test_mode;
420 413
421 // Return immediately if we're returning an error. 414 // Return immediately if we're returning an error.
422 if (OK != t->return_code) { 415 if (OK != t->return_code) {
423 if (test_mode_ & TEST_MODE_SYNC_NET_START) 416 if (test_mode_ & TEST_MODE_SYNC_NET_START)
424 return t->return_code; 417 return t->return_code;
425 CallbackLater(callback, t->return_code); 418 CallbackLater(callback, t->return_code);
426 return ERR_IO_PENDING; 419 return ERR_IO_PENDING;
427 } 420 }
428 421
(...skipping 30 matching lines...) Expand all
459 response_.ssl_info.connection_status = t->ssl_connection_status; 452 response_.ssl_info.connection_status = t->ssl_connection_status;
460 data_ = resp_data; 453 data_ = resp_data;
461 content_length_ = response_.headers->GetContentLength(); 454 content_length_ = response_.headers->GetContentLength();
462 455
463 if (net_log.net_log()) 456 if (net_log.net_log())
464 socket_log_id_ = net_log.net_log()->NextID(); 457 socket_log_id_ = net_log.net_log()->NextID();
465 458
466 if (request_->load_flags & LOAD_PREFETCH) 459 if (request_->load_flags & LOAD_PREFETCH)
467 response_.unused_since_prefetch = true; 460 response_.unused_since_prefetch = true;
468 461
462 // Pause and resume.
463 if (!before_network_start_callback_.is_null()) {
464 bool defer = false;
465 before_network_start_callback_.Run(&defer);
466 if (defer) {
467 callback_ = callback;
468 return net::ERR_IO_PENDING;
469 }
470 }
471
469 if (test_mode_ & TEST_MODE_SYNC_NET_START) 472 if (test_mode_ & TEST_MODE_SYNC_NET_START)
470 return OK; 473 return OK;
471 474
472 CallbackLater(callback, OK); 475 CallbackLater(callback, OK);
473 return ERR_IO_PENDING; 476 return ERR_IO_PENDING;
474 } 477 }
475 478
476 void MockNetworkTransaction::SetBeforeNetworkStartCallback( 479 void MockNetworkTransaction::SetBeforeNetworkStartCallback(
477 const BeforeNetworkStartCallback& callback) { 480 const BeforeNetworkStartCallback& callback) {
478 before_network_start_callback_ = callback; 481 before_network_start_callback_ = callback;
479 } 482 }
480 483
481 void MockNetworkTransaction::SetBeforeHeadersSentCallback( 484 void MockNetworkTransaction::SetBeforeHeadersSentCallback(
482 const BeforeHeadersSentCallback& callback) {} 485 const BeforeHeadersSentCallback& callback) {}
483 486
484 int MockNetworkTransaction::ResumeNetworkStart() { 487 int MockNetworkTransaction::ResumeNetworkStart() {
485 // Should not get here. 488 DCHECK(!callback_.is_null());
486 return ERR_FAILED; 489 CallbackLater(callback_, OK);
490 return ERR_IO_PENDING;
491 }
492
493 // static
494 void MockNetworkTransaction::DeferNetworkStart(bool* defer) {
Randy Smith (Not in Mondays) 2017/04/11 19:56:45 nit, suggestion: This function seems trivial enoug
shivanisha 2017/04/12 16:46:03 done
495 *defer = true;
487 } 496 }
488 497
489 void MockNetworkTransaction::GetConnectionAttempts( 498 void MockNetworkTransaction::GetConnectionAttempts(
490 ConnectionAttempts* out) const { 499 ConnectionAttempts* out) const {
491 NOTIMPLEMENTED(); 500 NOTIMPLEMENTED();
492 } 501 }
493 502
494 void MockNetworkTransaction::CallbackLater(const CompletionCallback& callback, 503 void MockNetworkTransaction::CallbackLater(const CompletionCallback& callback,
495 int result) { 504 int result) {
496 base::ThreadTaskRunnerHandle::Get()->PostTask( 505 base::ThreadTaskRunnerHandle::Get()->PostTask(
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 content.append(buf->data(), rv); 587 content.append(buf->data(), rv);
579 else if (rv < 0) 588 else if (rv < 0)
580 return rv; 589 return rv;
581 } while (rv > 0); 590 } while (rv > 0);
582 591
583 result->swap(content); 592 result->swap(content);
584 return OK; 593 return OK;
585 } 594 }
586 595
587 } // namespace net 596 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_transaction_test_util.h ('k') | net/http/mock_http_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698