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

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

Issue 2721933002: HttpCache::Transaction layer allowing parallel validation (Closed)
Patch Set: Initial patch Created 3 years, 9 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
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 "net/http/http_cache_transaction.h" 5 #include "net/http/http_cache_transaction.h"
6 6
7 #include "build/build_config.h" // For OS_POSIX 7 #include "build/build_config.h" // For OS_POSIX
8 8
9 #if defined(OS_POSIX) 9 #if defined(OS_POSIX)
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 truncated_(false), 174 truncated_(false),
175 is_sparse_(false), 175 is_sparse_(false),
176 range_requested_(false), 176 range_requested_(false),
177 handling_206_(false), 177 handling_206_(false),
178 cache_pending_(false), 178 cache_pending_(false),
179 done_reading_(false), 179 done_reading_(false),
180 vary_mismatch_(false), 180 vary_mismatch_(false),
181 couldnt_conditionalize_request_(false), 181 couldnt_conditionalize_request_(false),
182 bypass_lock_for_test_(false), 182 bypass_lock_for_test_(false),
183 fail_conditionalization_for_test_(false), 183 fail_conditionalization_for_test_(false),
184 write_this_response_(false),
184 io_buf_len_(0), 185 io_buf_len_(0),
185 read_offset_(0), 186 read_offset_(0),
186 effective_load_flags_(0), 187 effective_load_flags_(0),
187 write_len_(0), 188 write_len_(0),
188 cache_entry_status_(CacheEntryStatus::ENTRY_UNDEFINED), 189 cache_entry_status_(CacheEntryStatus::ENTRY_UNDEFINED),
189 validation_cause_(VALIDATION_CAUSE_UNDEFINED), 190 validation_cause_(VALIDATION_CAUSE_UNDEFINED),
190 total_received_bytes_(0), 191 total_received_bytes_(0),
191 total_sent_bytes_(0), 192 total_sent_bytes_(0),
192 websocket_handshake_stream_base_create_helper_(NULL), 193 websocket_handshake_stream_base_create_helper_(NULL),
193 weak_factory_(this) { 194 weak_factory_(this) {
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 // CacheWriteResponse* -> TruncateCachedData* -> TruncateCachedMetadata* -> 594 // CacheWriteResponse* -> TruncateCachedData* -> TruncateCachedMetadata* ->
594 // PartialHeadersReceived 595 // PartialHeadersReceived
595 // 596 //
596 // Read(): 597 // Read():
597 // NetworkRead* -> CacheWriteData* 598 // NetworkRead* -> CacheWriteData*
598 // 599 //
599 // 2. Cached entry, no validation: 600 // 2. Cached entry, no validation:
600 // Start(): 601 // Start():
601 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* 602 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse*
602 // -> CacheDispatchValidation -> BeginPartialCacheValidation() -> 603 // -> CacheDispatchValidation -> BeginPartialCacheValidation() ->
603 // BeginCacheValidation() -> SetupEntryForRead() 604 // BeginCacheValidation() -> SetupEntryForRead() -> WaitBeforeRead*
604 // 605 //
605 // Read(): 606 // Read():
606 // CacheReadData* 607 // CacheReadData*
607 // 608 //
608 // 3. Cached entry, validation (304): 609 // 3. Cached entry, validation (304):
609 // Start(): 610 // Start():
610 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* 611 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse*
611 // -> CacheDispatchValidation -> BeginPartialCacheValidation() -> 612 // -> CacheDispatchValidation -> BeginPartialCacheValidation() ->
612 // BeginCacheValidation() -> SendRequest* -> SuccessfulSendRequest -> 613 // BeginCacheValidation() -> SendRequest* -> SuccessfulSendRequest ->
613 // UpdateCachedResponse -> CacheWriteUpdatedResponse* -> 614 // UpdateCachedResponse -> CacheWriteUpdatedResponse* ->
614 // UpdateCachedResponseComplete -> OverwriteCachedResponse -> 615 // UpdateCachedResponseComplete -> OverwriteCachedResponse ->
615 // PartialHeadersReceived 616 // PartialHeadersReceived -> WaitBeforeRead*
616 // 617 //
617 // Read(): 618 // Read():
618 // CacheReadData* 619 // CacheReadData*
619 // 620 //
620 // 4. Cached entry, validation and replace (200): 621 // 4. Cached entry, validation and replace (200):
621 // Start(): 622 // Start():
622 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* 623 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse*
623 // -> CacheDispatchValidation -> BeginPartialCacheValidation() -> 624 // -> CacheDispatchValidation -> BeginPartialCacheValidation() ->
624 // BeginCacheValidation() -> SendRequest* -> SuccessfulSendRequest -> 625 // BeginCacheValidation() -> SendRequest* -> SuccessfulSendRequest ->
625 // OverwriteCachedResponse -> CacheWriteResponse* -> DoTruncateCachedData* -> 626 // OverwriteCachedResponse -> CacheWriteResponse* -> DoTruncateCachedData* ->
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 // BeginPartialCacheValidation() -> BeginCacheValidation() -> 706 // BeginPartialCacheValidation() -> BeginCacheValidation() ->
706 // SetupEntryForRead() 707 // SetupEntryForRead()
707 // 708 //
708 // Read(): 709 // Read():
709 // CacheReadData* 710 // CacheReadData*
710 // 711 //
711 // 14. Cached entry more than 5 minutes old, unused_since_prefetch is true: 712 // 14. Cached entry more than 5 minutes old, unused_since_prefetch is true:
712 // Like examples 2-4, only CacheToggleUnusedSincePrefetch* is inserted between 713 // Like examples 2-4, only CacheToggleUnusedSincePrefetch* is inserted between
713 // CacheReadResponse* and CacheDispatchValidation. 714 // CacheReadResponse* and CacheDispatchValidation.
714 int HttpCache::Transaction::DoLoop(int result) { 715 int HttpCache::Transaction::DoLoop(int result) {
716 int rv = DoLoopImpl(result);
717
718 // If its the end of the Start() state machine, the transaction might have to
719 // wait before it can read from the cache if there is another transaction
720 // writing to the cache currently. This is being done to enable parallelizing
721 // the validation phase of a transaction while another transaction is still
722 // writing the response to the cache.
723 // Checking reading_ will make sure that we do not enter the wait state for
724 // partial requests that have already started reading and re-entered the
725 // start() state machine.
726 if (!reading_ && rv == OK) {
jkarlin 2017/03/07 16:45:42 How many ways can we get here? Can we just call 'r
shivanisha 2017/03/08 21:42:13 There are a lot of conditional paths that can lead
727 next_state_ = STATE_WAIT_BEFORE_READ;
728 rv = DoLoopImpl(rv);
729 }
730
731 if (rv != ERR_IO_PENDING && !callback_.is_null()) {
732 read_buf_ = NULL; // Release the buffer before invoking the callback.
jkarlin 2017/03/07 16:45:42 s/NULL/nullptr/
shivanisha 2017/03/08 21:42:13 done
733 base::ResetAndReturn(&callback_).Run(rv);
734 }
735
736 return rv;
737 }
738
739 int HttpCache::Transaction::DoLoopImpl(int result) {
715 DCHECK(next_state_ != STATE_NONE); 740 DCHECK(next_state_ != STATE_NONE);
716 741
717 int rv = result; 742 int rv = result;
718 do { 743 do {
719 State state = next_state_; 744 State state = next_state_;
720 next_state_ = STATE_NONE; 745 next_state_ = STATE_NONE;
721 switch (state) { 746 switch (state) {
722 case STATE_GET_BACKEND: 747 case STATE_GET_BACKEND:
723 DCHECK_EQ(OK, rv); 748 DCHECK_EQ(OK, rv);
724 rv = DoGetBackend(); 749 rv = DoGetBackend();
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 DCHECK_EQ(OK, rv); 869 DCHECK_EQ(OK, rv);
845 rv = DoPartialHeadersReceived(); 870 rv = DoPartialHeadersReceived();
846 break; 871 break;
847 case STATE_CACHE_READ_METADATA: 872 case STATE_CACHE_READ_METADATA:
848 DCHECK_EQ(OK, rv); 873 DCHECK_EQ(OK, rv);
849 rv = DoCacheReadMetadata(); 874 rv = DoCacheReadMetadata();
850 break; 875 break;
851 case STATE_CACHE_READ_METADATA_COMPLETE: 876 case STATE_CACHE_READ_METADATA_COMPLETE:
852 rv = DoCacheReadMetadataComplete(rv); 877 rv = DoCacheReadMetadataComplete(rv);
853 break; 878 break;
879 case STATE_WAIT_BEFORE_READ:
880 DCHECK_EQ(OK, rv);
881 rv = DoWaitBeforeRead();
882 break;
883 case STATE_WAIT_BEFORE_READ_COMPLETE:
884 rv = DoWaitBeforeReadComplete(rv);
885 break;
854 case STATE_NETWORK_READ: 886 case STATE_NETWORK_READ:
855 DCHECK_EQ(OK, rv); 887 DCHECK_EQ(OK, rv);
856 rv = DoNetworkRead(); 888 rv = DoNetworkRead();
857 break; 889 break;
858 case STATE_NETWORK_READ_COMPLETE: 890 case STATE_NETWORK_READ_COMPLETE:
859 rv = DoNetworkReadComplete(rv); 891 rv = DoNetworkReadComplete(rv);
860 break; 892 break;
861 case STATE_CACHE_READ_DATA: 893 case STATE_CACHE_READ_DATA:
862 DCHECK_EQ(OK, rv); 894 DCHECK_EQ(OK, rv);
863 rv = DoCacheReadData(); 895 rv = DoCacheReadData();
(...skipping 14 matching lines...) Expand all
878 case STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE: 910 case STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE:
879 rv = DoCacheWriteTruncatedResponseComplete(rv); 911 rv = DoCacheWriteTruncatedResponseComplete(rv);
880 break; 912 break;
881 default: 913 default:
882 NOTREACHED() << "bad state"; 914 NOTREACHED() << "bad state";
883 rv = ERR_FAILED; 915 rv = ERR_FAILED;
884 break; 916 break;
885 } 917 }
886 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); 918 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE);
887 919
888 if (rv != ERR_IO_PENDING && !callback_.is_null()) {
889 read_buf_ = NULL; // Release the buffer before invoking the callback.
890 base::ResetAndReturn(&callback_).Run(rv);
891 }
892
893 return rv; 920 return rv;
894 } 921 }
895 922
896 int HttpCache::Transaction::DoGetBackend() { 923 int HttpCache::Transaction::DoGetBackend() {
897 cache_pending_ = true; 924 cache_pending_ = true;
898 next_state_ = STATE_GET_BACKEND_COMPLETE; 925 next_state_ = STATE_GET_BACKEND_COMPLETE;
899 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_GET_BACKEND); 926 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_GET_BACKEND);
900 return cache_->GetBackendForTransaction(this); 927 return cache_->GetBackendForTransaction(this);
901 } 928 }
902 929
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
1490 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_NOT_IN_CACHE); 1517 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_NOT_IN_CACHE);
1491 } 1518 }
1492 1519
1493 // Invalidate any cached GET with a successful PUT or DELETE. 1520 // Invalidate any cached GET with a successful PUT or DELETE.
1494 if (mode_ == WRITE && 1521 if (mode_ == WRITE &&
1495 (request_->method == "PUT" || request_->method == "DELETE")) { 1522 (request_->method == "PUT" || request_->method == "DELETE")) {
1496 if (NonErrorResponse(new_response->headers->response_code())) { 1523 if (NonErrorResponse(new_response->headers->response_code())) {
1497 int ret = cache_->DoomEntry(cache_key_, NULL); 1524 int ret = cache_->DoomEntry(cache_key_, NULL);
1498 DCHECK_EQ(OK, ret); 1525 DCHECK_EQ(OK, ret);
1499 } 1526 }
1500 cache_->DoneWritingToEntry(entry_, true); 1527 cache_->DoneWritingToEntry(entry_, true, this);
1501 entry_ = NULL; 1528 entry_ = NULL;
1502 mode_ = NONE; 1529 mode_ = NONE;
1503 } 1530 }
1504 1531
1505 // Invalidate any cached GET with a successful POST. 1532 // Invalidate any cached GET with a successful POST.
1506 if (!(effective_load_flags_ & LOAD_DISABLE_CACHE) && 1533 if (!(effective_load_flags_ & LOAD_DISABLE_CACHE) &&
1507 request_->method == "POST" && 1534 request_->method == "POST" &&
1508 NonErrorResponse(new_response->headers->response_code())) { 1535 NonErrorResponse(new_response->headers->response_code())) {
1509 cache_->DoomMainEntryForUrl(request_->url); 1536 cache_->DoomMainEntryForUrl(request_->url);
1510 } 1537 }
(...skipping 12 matching lines...) Expand all
1523 if (new_response->headers->response_code() == 304 || handling_206_) { 1550 if (new_response->headers->response_code() == 304 || handling_206_) {
1524 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_VALIDATED); 1551 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_VALIDATED);
1525 next_state_ = STATE_UPDATE_CACHED_RESPONSE; 1552 next_state_ = STATE_UPDATE_CACHED_RESPONSE;
1526 return OK; 1553 return OK;
1527 } 1554 }
1528 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_UPDATED); 1555 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_UPDATED);
1529 mode_ = WRITE; 1556 mode_ = WRITE;
1530 } 1557 }
1531 1558
1532 next_state_ = STATE_OVERWRITE_CACHED_RESPONSE; 1559 next_state_ = STATE_OVERWRITE_CACHED_RESPONSE;
1560
1561 if (!entry_)
1562 return OK;
1563
1564 if (entry_->writer == this && request_->method != "HEAD") {
1565 write_this_response_ = true;
1566 return OK;
1567 }
1568
1569 // Invalidate any current entry with a successful response.
1570 if (new_response->headers->response_code() != 304) {
1571 DCHECK_EQ(entry_->validating_transaction, this);
1572 cache_->OnValidationNoMatch(entry_, this);
1573 entry_ = nullptr;
1574 mode_ = NONE;
1575 return OK;
1576 }
1577
1533 return OK; 1578 return OK;
1534 } 1579 }
1535 1580
1536 // We received 304 or 206 and we want to update the cached response headers. 1581 // We received 304 or 206 and we want to update the cached response headers.
1537 int HttpCache::Transaction::DoUpdateCachedResponse() { 1582 int HttpCache::Transaction::DoUpdateCachedResponse() {
1538 TRACE_EVENT0("io", "HttpCacheTransaction::DoUpdateCachedResponse"); 1583 TRACE_EVENT0("io", "HttpCacheTransaction::DoUpdateCachedResponse");
1539 next_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE; 1584 next_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE;
1540 int rv = OK; 1585 int rv = OK;
1541 // Update the cached response based on the headers and properties of 1586 // Update the cached response based on the headers and properties of
1542 // new_response_. 1587 // new_response_.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1592 DCHECK(!handling_206_); 1637 DCHECK(!handling_206_);
1593 // We got a "not modified" response and already updated the corresponding 1638 // We got a "not modified" response and already updated the corresponding
1594 // cache entry above. 1639 // cache entry above.
1595 // 1640 //
1596 // By closing the cached entry now, we make sure that the 304 rather than 1641 // By closing the cached entry now, we make sure that the 304 rather than
1597 // the cached 200 response, is what will be returned to the user. 1642 // the cached 200 response, is what will be returned to the user.
1598 DoneWritingToEntry(true); 1643 DoneWritingToEntry(true);
1599 } else if (entry_ && !handling_206_) { 1644 } else if (entry_ && !handling_206_) {
1600 DCHECK_EQ(READ_WRITE, mode_); 1645 DCHECK_EQ(READ_WRITE, mode_);
1601 if (!partial_ || partial_->IsLastRange()) { 1646 if (!partial_ || partial_->IsLastRange()) {
1602 cache_->ConvertWriterToReader(entry_); 1647 if (cache_->ConvertWriterToReader(entry_, this))
1603 mode_ = READ; 1648 mode_ = READ;
1604 } 1649 }
1605 // We no longer need the network transaction, so destroy it. 1650 // We no longer need the network transaction, so destroy it.
1606 ResetNetworkTransaction(); 1651 ResetNetworkTransaction();
1607 } else if (entry_ && handling_206_ && truncated_ && 1652 } else if (entry_ && handling_206_ && truncated_ &&
1608 partial_->initial_validation()) { 1653 partial_->initial_validation()) {
1609 // We just finished the validation of a truncated entry, and the server 1654 // We just finished the validation of a truncated entry, and the server
1610 // is willing to resume the operation. Now we go back and start serving 1655 // is willing to resume the operation. Now we go back and start serving
1611 // the first part to the user. 1656 // the first part to the user.
1612 ResetNetworkTransaction(); 1657 ResetNetworkTransaction();
1613 new_response_ = NULL; 1658 new_response_ = NULL;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1729 next_state_ = STATE_CACHE_READ_DATA; 1774 next_state_ = STATE_CACHE_READ_DATA;
1730 } 1775 }
1731 } else if (mode_ != NONE) { 1776 } else if (mode_ != NONE) {
1732 // We are about to return the headers for a byte-range request to the user, 1777 // We are about to return the headers for a byte-range request to the user,
1733 // so let's fix them. 1778 // so let's fix them.
1734 partial_->FixResponseHeaders(response_.headers.get(), true); 1779 partial_->FixResponseHeaders(response_.headers.get(), true);
1735 } 1780 }
1736 return OK; 1781 return OK;
1737 } 1782 }
1738 1783
1784 int HttpCache::Transaction::DoWaitBeforeRead() {
1785 if (!entry_)
1786 return OK;
1787
1788 next_state_ = STATE_WAIT_BEFORE_READ_COMPLETE;
1789
1790 // If this is the writer, give chance to another transaction to start
1791 // validation.
1792 if (write_this_response_) {
jkarlin 2017/03/07 16:45:42 Seems clearer to call entry_->writer == this && re
shivanisha 2017/03/08 21:42:13 Apart from the conditions entry_->writer == this &
1793 cache_->OnValidationMatch(entry_, this, true);
jkarlin 2017/03/07 16:45:42 OnValidationMatch(entry_, this, true /* write_this
shivanisha 2017/03/08 21:42:13 N/A after the code refactoring of OnValidationMatc
1794 return OK;
1795 }
1796
1797 // If the transaction was converted to a reader but not in readers yet, then
1798 // it must be added to the queue.
1799 bool should_wait = false;
1800 if (entry_->writer != this && entry_->validating_transaction != this &&
1801 !entry_->IsReader(this))
1802 should_wait = true;
1803
1804 // Notify cache_ about completed validation so that another transaction can
1805 // start validation.
1806 if (entry_->validating_transaction == this && response_.headers &&
1807 response_.headers->response_code() == 304)
1808 should_wait = true;
1809
1810 if (should_wait)
1811 return cache_->OnValidationMatch(entry_, this, false);
jkarlin 2017/03/07 16:45:42 OnValidationMatch(entry_, this, false /* write_thi
shivanisha 2017/03/08 21:42:13 N/A after the code refactoring of OnValidationMatc
1812
1813 return OK;
1814 }
1815
1816 int HttpCache::Transaction::DoWaitBeforeReadComplete(int rv) {
1817 if (rv == ERR_CACHE_RACE) {
1818 next_state_ = STATE_INIT_ENTRY;
1819 cache_entry_status_ = CacheEntryStatus::ENTRY_UNDEFINED;
1820 entry_ = nullptr;
1821 return OK;
1822 }
1823
1824 if (rv != OK)
1825 return rv;
1826
1827 // If successful then this must be either be the writer or a reader as the
1828 // response must have completely been written to the cache.
1829 if (entry_->writer == this)
1830 return OK;
1831
1832 mode_ = READ;
jkarlin 2017/03/07 16:45:42 I'd have thought that the existing code would have
shivanisha 2017/03/08 21:42:12 Simplified DoWaitBeforeRead to not have an additio
1833 if (network_trans_)
1834 ResetNetworkTransaction();
jkarlin 2017/03/07 16:45:42 Likewise, shouldn't this be taken care of already?
shivanisha 2017/03/08 21:42:13 I am looking into this. I am not sure if the could
1835 return OK;
1836 }
1837
1739 int HttpCache::Transaction::DoCacheReadMetadata() { 1838 int HttpCache::Transaction::DoCacheReadMetadata() {
1740 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadMetadata"); 1839 TRACE_EVENT0("io", "HttpCacheTransaction::DoCacheReadMetadata");
1741 DCHECK(entry_); 1840 DCHECK(entry_);
1742 DCHECK(!response_.metadata.get()); 1841 DCHECK(!response_.metadata.get());
1743 next_state_ = STATE_CACHE_READ_METADATA_COMPLETE; 1842 next_state_ = STATE_CACHE_READ_METADATA_COMPLETE;
1744 1843
1745 response_.metadata = 1844 response_.metadata =
1746 new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex)); 1845 new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex));
1747 1846
1748 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_INFO); 1847 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_INFO);
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
2558 if (partial_) { 2657 if (partial_) {
2559 if (truncated_ || is_sparse_ || !invalid_range_) { 2658 if (truncated_ || is_sparse_ || !invalid_range_) {
2560 // We are going to return the saved response headers to the caller, so 2659 // We are going to return the saved response headers to the caller, so
2561 // we may need to adjust them first. 2660 // we may need to adjust them first.
2562 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; 2661 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED;
2563 return OK; 2662 return OK;
2564 } else { 2663 } else {
2565 partial_.reset(); 2664 partial_.reset();
2566 } 2665 }
2567 } 2666 }
2568 cache_->ConvertWriterToReader(entry_); 2667
2569 mode_ = READ; 2668 // This might or might not be able to add it as an active reader based on
2669 // whether this is the active writer or not. If not, it will be added to a
2670 // wait queue in DoWaitBeforeRead.
2671 if (cache_->ConvertWriterToReader(entry_, this))
jkarlin 2017/03/07 16:45:42 I see, this is why we had to change mode_ = READ i
shivanisha 2017/03/08 21:42:13 Simplified ConvertWriterToReader so it doesn't do
2672 mode_ = READ;
2570 2673
2571 if (request_->method == "HEAD") 2674 if (request_->method == "HEAD")
2572 FixHeadersForHead(); 2675 FixHeadersForHead();
2573 2676
2574 if (entry_->disk_entry->GetDataSize(kMetadataIndex)) 2677 if (entry_->disk_entry->GetDataSize(kMetadataIndex))
2575 next_state_ = STATE_CACHE_READ_METADATA; 2678 next_state_ = STATE_CACHE_READ_METADATA;
2576 return OK; 2679 return OK;
2577 } 2680 }
2578 2681
2579 int HttpCache::Transaction::WriteToEntry(int index, int offset, 2682 int HttpCache::Transaction::WriteToEntry(int index, int offset,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2644 } 2747 }
2645 return OK; 2748 return OK;
2646 } 2749 }
2647 2750
2648 void HttpCache::Transaction::DoneWritingToEntry(bool success) { 2751 void HttpCache::Transaction::DoneWritingToEntry(bool success) {
2649 if (!entry_) 2752 if (!entry_)
2650 return; 2753 return;
2651 2754
2652 RecordHistograms(); 2755 RecordHistograms();
2653 2756
2654 cache_->DoneWritingToEntry(entry_, success); 2757 cache_->DoneWritingToEntry(entry_, success, this);
2655 entry_ = NULL; 2758 entry_ = NULL;
2656 mode_ = NONE; // switch to 'pass through' mode 2759 mode_ = NONE; // switch to 'pass through' mode
2657 } 2760 }
2658 2761
2659 int HttpCache::Transaction::OnCacheReadError(int result, bool restart) { 2762 int HttpCache::Transaction::OnCacheReadError(int result, bool restart) {
2660 DLOG(ERROR) << "ReadData failed: " << result; 2763 DLOG(ERROR) << "ReadData failed: " << result;
2661 const int result_for_histogram = std::max(0, -result); 2764 const int result_for_histogram = std::max(0, -result);
2662 if (restart) { 2765 if (restart) {
2663 UMA_HISTOGRAM_SPARSE_SLOWLY("HttpCache.ReadErrorRestartable", 2766 UMA_HISTOGRAM_SPARSE_SLOWLY("HttpCache.ReadErrorRestartable",
2664 result_for_histogram); 2767 result_for_histogram);
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
3000 default: 3103 default:
3001 NOTREACHED(); 3104 NOTREACHED();
3002 } 3105 }
3003 } 3106 }
3004 3107
3005 void HttpCache::Transaction::OnIOComplete(int result) { 3108 void HttpCache::Transaction::OnIOComplete(int result) {
3006 DoLoop(result); 3109 DoLoop(result);
3007 } 3110 }
3008 3111
3009 } // namespace net 3112 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698