OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 | 8 |
9 #if defined(OS_POSIX) | 9 #if defined(OS_POSIX) |
10 #include <unistd.h> | 10 #include <unistd.h> |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 mode_(NONE), | 102 mode_(NONE), |
103 target_state_(STATE_NONE), | 103 target_state_(STATE_NONE), |
104 reading_(false), | 104 reading_(false), |
105 invalid_range_(false), | 105 invalid_range_(false), |
106 enable_range_support_(enable_range_support), | 106 enable_range_support_(enable_range_support), |
107 truncated_(false), | 107 truncated_(false), |
108 server_responded_206_(false), | 108 server_responded_206_(false), |
109 cache_pending_(false), | 109 cache_pending_(false), |
110 read_offset_(0), | 110 read_offset_(0), |
111 effective_load_flags_(0), | 111 effective_load_flags_(0), |
| 112 write_len_(0), |
112 final_upload_progress_(0), | 113 final_upload_progress_(0), |
113 ALLOW_THIS_IN_INITIALIZER_LIST( | 114 ALLOW_THIS_IN_INITIALIZER_LIST( |
114 io_callback_(this, &Transaction::OnIOComplete)), | 115 io_callback_(this, &Transaction::OnIOComplete)), |
115 ALLOW_THIS_IN_INITIALIZER_LIST( | 116 ALLOW_THIS_IN_INITIALIZER_LIST( |
116 cache_callback_(new CancelableCompletionCallback<Transaction>( | 117 cache_callback_(new CancelableCompletionCallback<Transaction>( |
117 this, &Transaction::OnIOComplete))), | 118 this, &Transaction::OnIOComplete))), |
118 ALLOW_THIS_IN_INITIALIZER_LIST( | 119 ALLOW_THIS_IN_INITIALIZER_LIST( |
119 write_headers_callback_(new CancelableCompletionCallback<Transaction>( | 120 write_headers_callback_(new CancelableCompletionCallback<Transaction>( |
120 this, &Transaction::OnIOComplete))) { | 121 this, &Transaction::OnIOComplete))) { |
121 COMPILE_ASSERT(HttpCache::Transaction::kNumValidationHeaders == | 122 COMPILE_ASSERT(HttpCache::Transaction::kNumValidationHeaders == |
(...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 read_offset_ += result; | 1168 read_offset_ += result; |
1168 } else if (result == 0) { // End of file. | 1169 } else if (result == 0) { // End of file. |
1169 cache_->DoneReadingFromEntry(entry_, this); | 1170 cache_->DoneReadingFromEntry(entry_, this); |
1170 entry_ = NULL; | 1171 entry_ = NULL; |
1171 } | 1172 } |
1172 return result; | 1173 return result; |
1173 } | 1174 } |
1174 | 1175 |
1175 int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { | 1176 int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { |
1176 next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE; | 1177 next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE; |
| 1178 write_len_ = num_bytes; |
1177 cache_callback_->AddRef(); // Balanced in DoCacheWriteDataComplete. | 1179 cache_callback_->AddRef(); // Balanced in DoCacheWriteDataComplete. |
1178 | 1180 |
1179 return AppendResponseDataToEntry(read_buf_, num_bytes, cache_callback_); | 1181 return AppendResponseDataToEntry(read_buf_, num_bytes, cache_callback_); |
1180 } | 1182 } |
1181 | 1183 |
1182 int HttpCache::Transaction::DoCacheWriteDataComplete(int result) { | 1184 int HttpCache::Transaction::DoCacheWriteDataComplete(int result) { |
1183 // Balance the AddRef from DoCacheWriteData. | 1185 // Balance the AddRef from DoCacheWriteData. |
1184 cache_callback_->Release(); | 1186 cache_callback_->Release(); |
1185 if (!cache_) | 1187 if (!cache_) |
1186 return ERR_UNEXPECTED; | 1188 return ERR_UNEXPECTED; |
1187 | 1189 |
1188 if (result < 0) | 1190 if (result != write_len_) { |
1189 return result; | 1191 DLOG(ERROR) << "failed to write response data to cache"; |
| 1192 DoneWritingToEntry(false); |
| 1193 |
| 1194 // We want to ignore errors writing to disk and just keep reading from |
| 1195 // the network. |
| 1196 result = write_len_; |
| 1197 } |
1190 | 1198 |
1191 if (partial_.get()) { | 1199 if (partial_.get()) { |
1192 // This may be the last request. | 1200 // This may be the last request. |
1193 if (!(result == 0 && !truncated_ && | 1201 if (!(result == 0 && !truncated_ && |
1194 (partial_->IsLastRange() || mode_ == WRITE))) | 1202 (partial_->IsLastRange() || mode_ == WRITE))) |
1195 return DoPartialNetworkReadCompleted(result); | 1203 return DoPartialNetworkReadCompleted(result); |
1196 } | 1204 } |
1197 | 1205 |
1198 if (result == 0) // End of file. | 1206 if (result == 0) // End of file. |
1199 DoneWritingToEntry(true); | 1207 DoneWritingToEntry(true); |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1718 if (!entry_) | 1726 if (!entry_) |
1719 return data_len; | 1727 return data_len; |
1720 | 1728 |
1721 int rv = 0; | 1729 int rv = 0; |
1722 if (!partial_.get() || !data_len) { | 1730 if (!partial_.get() || !data_len) { |
1723 rv = entry_->disk_entry->WriteData(index, offset, data, data_len, callback, | 1731 rv = entry_->disk_entry->WriteData(index, offset, data, data_len, callback, |
1724 true); | 1732 true); |
1725 } else { | 1733 } else { |
1726 rv = partial_->CacheWrite(entry_->disk_entry, data, data_len, callback); | 1734 rv = partial_->CacheWrite(entry_->disk_entry, data, data_len, callback); |
1727 } | 1735 } |
1728 | |
1729 if (rv != ERR_IO_PENDING && rv != data_len) { | |
1730 DLOG(ERROR) << "failed to write response data to cache"; | |
1731 DoneWritingToEntry(false); | |
1732 | |
1733 // We want to ignore errors writing to disk and just keep reading from | |
1734 // the network. | |
1735 rv = data_len; | |
1736 } | |
1737 return rv; | 1736 return rv; |
1738 } | 1737 } |
1739 | 1738 |
1740 int HttpCache::Transaction::WriteResponseInfoToEntry(bool truncated) { | 1739 int HttpCache::Transaction::WriteResponseInfoToEntry(bool truncated) { |
1741 next_state_ = STATE_CACHE_WRITE_RESPONSE_COMPLETE; | 1740 next_state_ = STATE_CACHE_WRITE_RESPONSE_COMPLETE; |
1742 if (!entry_) | 1741 if (!entry_) |
1743 return OK; | 1742 return OK; |
1744 | 1743 |
1745 // Do not cache no-store content (unless we are record mode). Do not cache | 1744 // Do not cache no-store content (unless we are record mode). Do not cache |
1746 // content with cert errors either. This is to prevent not reporting net | 1745 // content with cert errors either. This is to prevent not reporting net |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1870 // |value| goes from 0 to 63. Actually, the max value should be 47 (0x2f) | 1869 // |value| goes from 0 to 63. Actually, the max value should be 47 (0x2f) |
1871 // but we'll see. | 1870 // but we'll see. |
1872 UMA_HISTOGRAM_ENUMERATION("HttpCache.ResponseHeaders", value, 65); | 1871 UMA_HISTOGRAM_ENUMERATION("HttpCache.ResponseHeaders", value, 65); |
1873 } | 1872 } |
1874 | 1873 |
1875 void HttpCache::Transaction::OnIOComplete(int result) { | 1874 void HttpCache::Transaction::OnIOComplete(int result) { |
1876 DoLoop(result); | 1875 DoLoop(result); |
1877 } | 1876 } |
1878 | 1877 |
1879 } // namespace net | 1878 } // namespace net |
OLD | NEW |