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

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

Issue 15829004: Update net/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: license twerk Created 7 years, 6 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
« no previous file with comments | « net/http/http_cache.cc ('k') | net/http/http_cache_unittest.cc » ('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 (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" 7 #include "build/build_config.h"
8 8
9 #if defined(OS_POSIX) 9 #if defined(OS_POSIX)
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 353
354 if (rv == ERR_IO_PENDING) 354 if (rv == ERR_IO_PENDING)
355 callback_ = callback; 355 callback_ = callback;
356 356
357 return rv; 357 return rv;
358 } 358 }
359 359
360 int HttpCache::Transaction::RestartWithAuth( 360 int HttpCache::Transaction::RestartWithAuth(
361 const AuthCredentials& credentials, 361 const AuthCredentials& credentials,
362 const CompletionCallback& callback) { 362 const CompletionCallback& callback) {
363 DCHECK(auth_response_.headers); 363 DCHECK(auth_response_.headers.get());
364 DCHECK(!callback.is_null()); 364 DCHECK(!callback.is_null());
365 365
366 // Ensure that we only have one asynchronous call at a time. 366 // Ensure that we only have one asynchronous call at a time.
367 DCHECK(callback_.is_null()); 367 DCHECK(callback_.is_null());
368 368
369 if (!cache_) 369 if (!cache_)
370 return ERR_UNEXPECTED; 370 return ERR_UNEXPECTED;
371 371
372 // Clear the intermediate response since we are going to start over. 372 // Clear the intermediate response since we are going to start over.
373 auth_response_ = HttpResponseInfo(); 373 auth_response_ = HttpResponseInfo();
(...skipping 19 matching lines...) Expand all
393 DCHECK(!callback.is_null()); 393 DCHECK(!callback.is_null());
394 394
395 DCHECK(callback_.is_null()); 395 DCHECK(callback_.is_null());
396 396
397 if (!cache_) 397 if (!cache_)
398 return ERR_UNEXPECTED; 398 return ERR_UNEXPECTED;
399 399
400 // If we have an intermediate auth response at this point, then it means the 400 // If we have an intermediate auth response at this point, then it means the
401 // user wishes to read the network response (the error page). If there is a 401 // user wishes to read the network response (the error page). If there is a
402 // previous response in the cache then we should leave it intact. 402 // previous response in the cache then we should leave it intact.
403 if (auth_response_.headers && mode_ != NONE) { 403 if (auth_response_.headers.get() && mode_ != NONE) {
404 UpdateTransactionPattern(PATTERN_NOT_COVERED); 404 UpdateTransactionPattern(PATTERN_NOT_COVERED);
405 DCHECK(mode_ & WRITE); 405 DCHECK(mode_ & WRITE);
406 DoneWritingToEntry(mode_ == READ_WRITE); 406 DoneWritingToEntry(mode_ == READ_WRITE);
407 mode_ = NONE; 407 mode_ = NONE;
408 } 408 }
409 409
410 reading_ = true; 410 reading_ = true;
411 int rv; 411 int rv;
412 412
413 switch (mode_) { 413 switch (mode_) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 if (cache_ && entry_) { 457 if (cache_ && entry_) {
458 DCHECK(reading_); 458 DCHECK(reading_);
459 DCHECK_NE(mode_, UPDATE); 459 DCHECK_NE(mode_, UPDATE);
460 if (mode_ & WRITE) 460 if (mode_ & WRITE)
461 DoneWritingToEntry(true); 461 DoneWritingToEntry(true);
462 } 462 }
463 } 463 }
464 464
465 const HttpResponseInfo* HttpCache::Transaction::GetResponseInfo() const { 465 const HttpResponseInfo* HttpCache::Transaction::GetResponseInfo() const {
466 // Null headers means we encountered an error or haven't a response yet 466 // Null headers means we encountered an error or haven't a response yet
467 if (auth_response_.headers) 467 if (auth_response_.headers.get())
468 return &auth_response_; 468 return &auth_response_;
469 return (response_.headers || response_.ssl_info.cert || 469 return (response_.headers.get() || response_.ssl_info.cert.get() ||
470 response_.cert_request_info) ? &response_ : NULL; 470 response_.cert_request_info.get())
471 ? &response_
472 : NULL;
471 } 473 }
472 474
473 LoadState HttpCache::Transaction::GetLoadState() const { 475 LoadState HttpCache::Transaction::GetLoadState() const {
474 LoadState state = GetWriterLoadState(); 476 LoadState state = GetWriterLoadState();
475 if (state != LOAD_STATE_WAITING_FOR_CACHE) 477 if (state != LOAD_STATE_WAITING_FOR_CACHE)
476 return state; 478 return state;
477 479
478 if (cache_) 480 if (cache_)
479 return cache_->GetLoadStateForPendingTransaction(this); 481 return cache_->GetLoadStateForPendingTransaction(this);
480 482
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 DCHECK(!new_response_); 913 DCHECK(!new_response_);
912 const HttpResponseInfo* new_response = network_trans_->GetResponseInfo(); 914 const HttpResponseInfo* new_response = network_trans_->GetResponseInfo();
913 915
914 if (new_response->headers->response_code() == 401 || 916 if (new_response->headers->response_code() == 401 ||
915 new_response->headers->response_code() == 407) { 917 new_response->headers->response_code() == 407) {
916 auth_response_ = *new_response; 918 auth_response_ = *new_response;
917 return OK; 919 return OK;
918 } 920 }
919 921
920 new_response_ = new_response; 922 new_response_ = new_response;
921 if (!ValidatePartialResponse() && !auth_response_.headers) { 923 if (!ValidatePartialResponse() && !auth_response_.headers.get()) {
922 // Something went wrong with this request and we have to restart it. 924 // Something went wrong with this request and we have to restart it.
923 // If we have an authentication response, we are exposed to weird things 925 // If we have an authentication response, we are exposed to weird things
924 // hapenning if the user cancels the authentication before we receive 926 // hapenning if the user cancels the authentication before we receive
925 // the new response. 927 // the new response.
926 UpdateTransactionPattern(PATTERN_NOT_COVERED); 928 UpdateTransactionPattern(PATTERN_NOT_COVERED);
927 response_ = HttpResponseInfo(); 929 response_ = HttpResponseInfo();
928 ResetNetworkTransaction(); 930 ResetNetworkTransaction();
929 new_response_ = NULL; 931 new_response_ = NULL;
930 next_state_ = STATE_SEND_REQUEST; 932 next_state_ = STATE_SEND_REQUEST;
931 return OK; 933 return OK;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 mode_ = WRITE; 977 mode_ = WRITE;
976 } 978 }
977 979
978 next_state_ = STATE_OVERWRITE_CACHED_RESPONSE; 980 next_state_ = STATE_OVERWRITE_CACHED_RESPONSE;
979 return OK; 981 return OK;
980 } 982 }
981 983
982 int HttpCache::Transaction::DoNetworkRead() { 984 int HttpCache::Transaction::DoNetworkRead() {
983 ReportNetworkActionStart(); 985 ReportNetworkActionStart();
984 next_state_ = STATE_NETWORK_READ_COMPLETE; 986 next_state_ = STATE_NETWORK_READ_COMPLETE;
985 return network_trans_->Read(read_buf_, io_buf_len_, io_callback_); 987 return network_trans_->Read(read_buf_.get(), io_buf_len_, io_callback_);
986 } 988 }
987 989
988 int HttpCache::Transaction::DoNetworkReadComplete(int result) { 990 int HttpCache::Transaction::DoNetworkReadComplete(int result) {
989 DCHECK(mode_ & WRITE || mode_ == NONE); 991 DCHECK(mode_ & WRITE || mode_ == NONE);
990 992
991 ReportNetworkActionFinish(); 993 ReportNetworkActionFinish();
992 994
993 if (!cache_) 995 if (!cache_)
994 return ERR_UNEXPECTED; 996 return ERR_UNEXPECTED;
995 997
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 1233
1232 return BeginCacheValidation(); 1234 return BeginCacheValidation();
1233 } 1235 }
1234 1236
1235 // We received 304 or 206 and we want to update the cached response headers. 1237 // We received 304 or 206 and we want to update the cached response headers.
1236 int HttpCache::Transaction::DoUpdateCachedResponse() { 1238 int HttpCache::Transaction::DoUpdateCachedResponse() {
1237 next_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE; 1239 next_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE;
1238 int rv = OK; 1240 int rv = OK;
1239 // Update cached response based on headers in new_response. 1241 // Update cached response based on headers in new_response.
1240 // TODO(wtc): should we update cached certificate (response_.ssl_info), too? 1242 // TODO(wtc): should we update cached certificate (response_.ssl_info), too?
1241 response_.headers->Update(*new_response_->headers); 1243 response_.headers->Update(*new_response_->headers.get());
1242 response_.response_time = new_response_->response_time; 1244 response_.response_time = new_response_->response_time;
1243 response_.request_time = new_response_->request_time; 1245 response_.request_time = new_response_->request_time;
1244 response_.network_accessed = new_response_->network_accessed; 1246 response_.network_accessed = new_response_->network_accessed;
1245 1247
1246 if (response_.headers->HasHeaderValue("cache-control", "no-store")) { 1248 if (response_.headers->HasHeaderValue("cache-control", "no-store")) {
1247 if (!entry_->doomed) { 1249 if (!entry_->doomed) {
1248 int ret = cache_->DoomEntry(cache_key_, NULL); 1250 int ret = cache_->DoomEntry(cache_key_, NULL);
1249 DCHECK_EQ(OK, ret); 1251 DCHECK_EQ(OK, ret);
1250 } 1252 }
1251 } else { 1253 } else {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 } 1296 }
1295 1297
1296 int HttpCache::Transaction::DoOverwriteCachedResponse() { 1298 int HttpCache::Transaction::DoOverwriteCachedResponse() {
1297 if (mode_ & READ) { 1299 if (mode_ & READ) {
1298 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; 1300 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED;
1299 return OK; 1301 return OK;
1300 } 1302 }
1301 1303
1302 // We change the value of Content-Length for partial content. 1304 // We change the value of Content-Length for partial content.
1303 if (handling_206_ && partial_.get()) 1305 if (handling_206_ && partial_.get())
1304 partial_->FixContentLength(new_response_->headers); 1306 partial_->FixContentLength(new_response_->headers.get());
1305 1307
1306 response_ = *new_response_; 1308 response_ = *new_response_;
1307 1309
1308 if (handling_206_ && !CanResume(false)) { 1310 if (handling_206_ && !CanResume(false)) {
1309 // There is no point in storing this resource because it will never be used. 1311 // There is no point in storing this resource because it will never be used.
1310 DoneWritingToEntry(false); 1312 DoneWritingToEntry(false);
1311 if (partial_.get()) 1313 if (partial_.get())
1312 partial_->FixResponseHeaders(response_.headers, true); 1314 partial_->FixResponseHeaders(response_.headers.get(), true);
1313 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; 1315 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED;
1314 return OK; 1316 return OK;
1315 } 1317 }
1316 1318
1317 target_state_ = STATE_TRUNCATE_CACHED_DATA; 1319 target_state_ = STATE_TRUNCATE_CACHED_DATA;
1318 next_state_ = truncated_ ? STATE_CACHE_WRITE_TRUNCATED_RESPONSE : 1320 next_state_ = truncated_ ? STATE_CACHE_WRITE_TRUNCATED_RESPONSE :
1319 STATE_CACHE_WRITE_RESPONSE; 1321 STATE_CACHE_WRITE_RESPONSE;
1320 return OK; 1322 return OK;
1321 } 1323 }
1322 1324
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 1387
1386 if (reading_) { 1388 if (reading_) {
1387 if (network_trans_.get()) { 1389 if (network_trans_.get()) {
1388 next_state_ = STATE_NETWORK_READ; 1390 next_state_ = STATE_NETWORK_READ;
1389 } else { 1391 } else {
1390 next_state_ = STATE_CACHE_READ_DATA; 1392 next_state_ = STATE_CACHE_READ_DATA;
1391 } 1393 }
1392 } else if (mode_ != NONE) { 1394 } else if (mode_ != NONE) {
1393 // We are about to return the headers for a byte-range request to the user, 1395 // We are about to return the headers for a byte-range request to the user,
1394 // so let's fix them. 1396 // so let's fix them.
1395 partial_->FixResponseHeaders(response_.headers, true); 1397 partial_->FixResponseHeaders(response_.headers.get(), true);
1396 } 1398 }
1397 return OK; 1399 return OK;
1398 } 1400 }
1399 1401
1400 int HttpCache::Transaction::DoCacheReadResponse() { 1402 int HttpCache::Transaction::DoCacheReadResponse() {
1401 DCHECK(entry_); 1403 DCHECK(entry_);
1402 next_state_ = STATE_CACHE_READ_RESPONSE_COMPLETE; 1404 next_state_ = STATE_CACHE_READ_RESPONSE_COMPLETE;
1403 1405
1404 io_buf_len_ = entry_->disk_entry->GetDataSize(kResponseInfoIndex); 1406 io_buf_len_ = entry_->disk_entry->GetDataSize(kResponseInfoIndex);
1405 read_buf_ = new IOBuffer(io_buf_len_); 1407 read_buf_ = new IOBuffer(io_buf_len_);
1406 1408
1407 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO); 1409 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO);
1408 ReportCacheActionStart(); 1410 ReportCacheActionStart();
1409 return ResetCacheIOStart( 1411 return ResetCacheIOStart(entry_->disk_entry->ReadData(
1410 entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_, 1412 kResponseInfoIndex, 0, read_buf_.get(), io_buf_len_, io_callback_));
1411 io_buf_len_, io_callback_));
1412 } 1413 }
1413 1414
1414 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { 1415 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) {
1415 ReportCacheActionFinish(); 1416 ReportCacheActionFinish();
1416 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); 1417 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result);
1417 if (result != io_buf_len_ || 1418 if (result != io_buf_len_ ||
1418 !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, 1419 !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_,
1419 &response_, &truncated_)) { 1420 &response_, &truncated_)) {
1420 return OnCacheReadError(result, true); 1421 return OnCacheReadError(result, true);
1421 } 1422 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 // Balance the AddRef from WriteResponseInfoToEntry. 1490 // Balance the AddRef from WriteResponseInfoToEntry.
1490 if (result != io_buf_len_) { 1491 if (result != io_buf_len_) {
1491 DLOG(ERROR) << "failed to write response info to cache"; 1492 DLOG(ERROR) << "failed to write response info to cache";
1492 DoneWritingToEntry(false); 1493 DoneWritingToEntry(false);
1493 } 1494 }
1494 return OK; 1495 return OK;
1495 } 1496 }
1496 1497
1497 int HttpCache::Transaction::DoCacheReadMetadata() { 1498 int HttpCache::Transaction::DoCacheReadMetadata() {
1498 DCHECK(entry_); 1499 DCHECK(entry_);
1499 DCHECK(!response_.metadata); 1500 DCHECK(!response_.metadata.get());
1500 next_state_ = STATE_CACHE_READ_METADATA_COMPLETE; 1501 next_state_ = STATE_CACHE_READ_METADATA_COMPLETE;
1501 1502
1502 response_.metadata = 1503 response_.metadata =
1503 new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex)); 1504 new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex));
1504 1505
1505 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO); 1506 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO);
1506 ReportCacheActionStart(); 1507 ReportCacheActionStart();
1507 return ResetCacheIOStart( 1508 return ResetCacheIOStart(
1508 entry_->disk_entry->ReadData(kMetadataIndex, 0, response_.metadata, 1509 entry_->disk_entry->ReadData(kMetadataIndex,
1510 0,
1511 response_.metadata.get(),
1509 response_.metadata->size(), 1512 response_.metadata->size(),
1510 io_callback_)); 1513 io_callback_));
1511 } 1514 }
1512 1515
1513 int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) { 1516 int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) {
1514 ReportCacheActionFinish(); 1517 ReportCacheActionFinish();
1515 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); 1518 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result);
1516 if (result != response_.metadata->size()) 1519 if (result != response_.metadata->size())
1517 return OnCacheReadError(result, false); 1520 return OnCacheReadError(result, false);
1518 return OK; 1521 return OK;
(...skipping 16 matching lines...) Expand all
1535 } 1538 }
1536 1539
1537 int HttpCache::Transaction::DoCacheReadData() { 1540 int HttpCache::Transaction::DoCacheReadData() {
1538 DCHECK(entry_); 1541 DCHECK(entry_);
1539 next_state_ = STATE_CACHE_READ_DATA_COMPLETE; 1542 next_state_ = STATE_CACHE_READ_DATA_COMPLETE;
1540 1543
1541 if (net_log_.IsLoggingAllEvents()) 1544 if (net_log_.IsLoggingAllEvents())
1542 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_DATA); 1545 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_DATA);
1543 ReportCacheActionStart(); 1546 ReportCacheActionStart();
1544 if (partial_.get()) { 1547 if (partial_.get()) {
1545 return ResetCacheIOStart( 1548 return ResetCacheIOStart(partial_->CacheRead(
1546 partial_->CacheRead(entry_->disk_entry, read_buf_, io_buf_len_, 1549 entry_->disk_entry, read_buf_.get(), io_buf_len_, io_callback_));
1547 io_callback_));
1548 } 1550 }
1549 1551
1550 return ResetCacheIOStart( 1552 return ResetCacheIOStart(entry_->disk_entry->ReadData(kResponseContentIndex,
1551 entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_, 1553 read_offset_,
1552 read_buf_, io_buf_len_, io_callback_)); 1554 read_buf_.get(),
1555 io_buf_len_,
1556 io_callback_));
1553 } 1557 }
1554 1558
1555 int HttpCache::Transaction::DoCacheReadDataComplete(int result) { 1559 int HttpCache::Transaction::DoCacheReadDataComplete(int result) {
1556 ReportCacheActionFinish(); 1560 ReportCacheActionFinish();
1557 if (net_log_.IsLoggingAllEvents()) { 1561 if (net_log_.IsLoggingAllEvents()) {
1558 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_DATA, 1562 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_DATA,
1559 result); 1563 result);
1560 } 1564 }
1561 1565
1562 if (!cache_) 1566 if (!cache_)
(...skipping 21 matching lines...) Expand all
1584 int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { 1588 int HttpCache::Transaction::DoCacheWriteData(int num_bytes) {
1585 next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE; 1589 next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE;
1586 write_len_ = num_bytes; 1590 write_len_ = num_bytes;
1587 if (entry_) { 1591 if (entry_) {
1588 if (net_log_.IsLoggingAllEvents()) 1592 if (net_log_.IsLoggingAllEvents())
1589 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA); 1593 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA);
1590 ReportCacheActionStart(); 1594 ReportCacheActionStart();
1591 } 1595 }
1592 1596
1593 return ResetCacheIOStart( 1597 return ResetCacheIOStart(
1594 AppendResponseDataToEntry(read_buf_, num_bytes, io_callback_)); 1598 AppendResponseDataToEntry(read_buf_.get(), num_bytes, io_callback_));
1595 } 1599 }
1596 1600
1597 int HttpCache::Transaction::DoCacheWriteDataComplete(int result) { 1601 int HttpCache::Transaction::DoCacheWriteDataComplete(int result) {
1598 if (entry_) { 1602 if (entry_) {
1599 ReportCacheActionFinish(); 1603 ReportCacheActionFinish();
1600 if (net_log_.IsLoggingAllEvents()) { 1604 if (net_log_.IsLoggingAllEvents()) {
1601 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, 1605 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA,
1602 result); 1606 result);
1603 } 1607 }
1604 } 1608 }
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 request_ = custom_request_.get(); 1864 request_ = custom_request_.get();
1861 } 1865 }
1862 1866
1863 return ValidateEntryHeadersAndContinue(); 1867 return ValidateEntryHeadersAndContinue();
1864 } 1868 }
1865 1869
1866 // This should only be called once per request. 1870 // This should only be called once per request.
1867 int HttpCache::Transaction::ValidateEntryHeadersAndContinue() { 1871 int HttpCache::Transaction::ValidateEntryHeadersAndContinue() {
1868 DCHECK(mode_ == READ_WRITE); 1872 DCHECK(mode_ == READ_WRITE);
1869 1873
1870 if (!partial_->UpdateFromStoredHeaders(response_.headers, entry_->disk_entry, 1874 if (!partial_->UpdateFromStoredHeaders(
1871 truncated_)) { 1875 response_.headers.get(), entry_->disk_entry, truncated_)) {
1872 return DoRestartPartialRequest(); 1876 return DoRestartPartialRequest();
1873 } 1877 }
1874 1878
1875 if (response_.headers->response_code() == 206) 1879 if (response_.headers->response_code() == 206)
1876 is_sparse_ = true; 1880 is_sparse_ = true;
1877 1881
1878 if (!partial_->IsRequestedRangeOK()) { 1882 if (!partial_->IsRequestedRangeOK()) {
1879 // The stored data is fine, but the request may be invalid. 1883 // The stored data is fine, but the request may be invalid.
1880 invalid_range_ = true; 1884 invalid_range_ = true;
1881 } 1885 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1955 bool HttpCache::Transaction::RequiresValidation() { 1959 bool HttpCache::Transaction::RequiresValidation() {
1956 // TODO(darin): need to do more work here: 1960 // TODO(darin): need to do more work here:
1957 // - make sure we have a matching request method 1961 // - make sure we have a matching request method
1958 // - watch out for cached responses that depend on authentication 1962 // - watch out for cached responses that depend on authentication
1959 1963
1960 // In playback mode, nothing requires validation. 1964 // In playback mode, nothing requires validation.
1961 if (cache_->mode() == net::HttpCache::PLAYBACK) 1965 if (cache_->mode() == net::HttpCache::PLAYBACK)
1962 return false; 1966 return false;
1963 1967
1964 if (response_.vary_data.is_valid() && 1968 if (response_.vary_data.is_valid() &&
1965 !response_.vary_data.MatchesRequest(*request_, *response_.headers)) { 1969 !response_.vary_data.MatchesRequest(*request_,
1970 *response_.headers.get())) {
1966 vary_mismatch_ = true; 1971 vary_mismatch_ = true;
1967 return true; 1972 return true;
1968 } 1973 }
1969 1974
1970 if (effective_load_flags_ & LOAD_PREFERRING_CACHE) 1975 if (effective_load_flags_ & LOAD_PREFERRING_CACHE)
1971 return false; 1976 return false;
1972 1977
1973 if (effective_load_flags_ & LOAD_VALIDATE_CACHE) 1978 if (effective_load_flags_ & LOAD_VALIDATE_CACHE)
1974 return true; 1979 return true;
1975 1980
1976 if (request_->method == "PUT" || request_->method == "DELETE") 1981 if (request_->method == "PUT" || request_->method == "DELETE")
1977 return true; 1982 return true;
1978 1983
1979 if (response_.headers->RequiresValidation( 1984 if (response_.headers->RequiresValidation(
1980 response_.request_time, response_.response_time, Time::Now())) { 1985 response_.request_time, response_.response_time, Time::Now())) {
1981 return true; 1986 return true;
1982 } 1987 }
1983 1988
1984 return false; 1989 return false;
1985 } 1990 }
1986 1991
1987 bool HttpCache::Transaction::ConditionalizeRequest() { 1992 bool HttpCache::Transaction::ConditionalizeRequest() {
1988 DCHECK(response_.headers); 1993 DCHECK(response_.headers.get());
1989 1994
1990 if (request_->method == "PUT" || request_->method == "DELETE") 1995 if (request_->method == "PUT" || request_->method == "DELETE")
1991 return false; 1996 return false;
1992 1997
1993 // This only makes sense for cached 200 or 206 responses. 1998 // This only makes sense for cached 200 or 206 responses.
1994 if (response_.headers->response_code() != 200 && 1999 if (response_.headers->response_code() != 200 &&
1995 response_.headers->response_code() != 206) { 2000 response_.headers->response_code() != 206) {
1996 return false; 2001 return false;
1997 } 2002 }
1998 2003
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
2067 // 2072 //
2068 // If the server is simply telling us that the resource has changed, we delete 2073 // If the server is simply telling us that the resource has changed, we delete
2069 // the cached entry and restart the request as the caller intended (by returning 2074 // the cached entry and restart the request as the caller intended (by returning
2070 // false from this method). However, we may not be able to do that at any point, 2075 // false from this method). However, we may not be able to do that at any point,
2071 // for instance if we already returned the headers to the user. 2076 // for instance if we already returned the headers to the user.
2072 // 2077 //
2073 // WARNING: Whenever this code returns false, it has to make sure that the next 2078 // WARNING: Whenever this code returns false, it has to make sure that the next
2074 // time it is called it will return true so that we don't keep retrying the 2079 // time it is called it will return true so that we don't keep retrying the
2075 // request. 2080 // request.
2076 bool HttpCache::Transaction::ValidatePartialResponse() { 2081 bool HttpCache::Transaction::ValidatePartialResponse() {
2077 const HttpResponseHeaders* headers = new_response_->headers; 2082 const HttpResponseHeaders* headers = new_response_->headers.get();
2078 int response_code = headers->response_code(); 2083 int response_code = headers->response_code();
2079 bool partial_response = (response_code == 206); 2084 bool partial_response = (response_code == 206);
2080 handling_206_ = false; 2085 handling_206_ = false;
2081 2086
2082 if (!entry_ || request_->method != "GET") 2087 if (!entry_ || request_->method != "GET")
2083 return true; 2088 return true;
2084 2089
2085 if (invalid_range_) { 2090 if (invalid_range_) {
2086 // We gave up trying to match this request with the stored data. If the 2091 // We gave up trying to match this request with the stored data. If the
2087 // server is ok with the request, delete the entry, otherwise just ignore 2092 // server is ok with the request, delete the entry, otherwise just ignore
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
2177 else if (mode_ & READ && entry_) 2182 else if (mode_ & READ && entry_)
2178 cache_->DoneReadingFromEntry(entry_, this); 2183 cache_->DoneReadingFromEntry(entry_, this);
2179 2184
2180 partial_.reset(NULL); 2185 partial_.reset(NULL);
2181 entry_ = NULL; 2186 entry_ = NULL;
2182 mode_ = NONE; 2187 mode_ = NONE;
2183 } 2188 }
2184 2189
2185 void HttpCache::Transaction::FailRangeRequest() { 2190 void HttpCache::Transaction::FailRangeRequest() {
2186 response_ = *new_response_; 2191 response_ = *new_response_;
2187 partial_->FixResponseHeaders(response_.headers, false); 2192 partial_->FixResponseHeaders(response_.headers.get(), false);
2188 } 2193 }
2189 2194
2190 int HttpCache::Transaction::SetupEntryForRead() { 2195 int HttpCache::Transaction::SetupEntryForRead() {
2191 if (network_trans_) 2196 if (network_trans_)
2192 ResetNetworkTransaction(); 2197 ResetNetworkTransaction();
2193 if (partial_.get()) { 2198 if (partial_.get()) {
2194 if (truncated_ || is_sparse_ || !invalid_range_) { 2199 if (truncated_ || is_sparse_ || !invalid_range_) {
2195 // We are going to return the saved response headers to the caller, so 2200 // We are going to return the saved response headers to the caller, so
2196 // we may need to adjust them first. 2201 // we may need to adjust them first.
2197 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; 2202 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2268 bool skip_transient_headers = (cache_->mode() != RECORD); 2273 bool skip_transient_headers = (cache_->mode() != RECORD);
2269 2274
2270 if (truncated) 2275 if (truncated)
2271 DCHECK_EQ(200, response_.headers->response_code()); 2276 DCHECK_EQ(200, response_.headers->response_code());
2272 2277
2273 scoped_refptr<PickledIOBuffer> data(new PickledIOBuffer()); 2278 scoped_refptr<PickledIOBuffer> data(new PickledIOBuffer());
2274 response_.Persist(data->pickle(), skip_transient_headers, truncated); 2279 response_.Persist(data->pickle(), skip_transient_headers, truncated);
2275 data->Done(); 2280 data->Done();
2276 2281
2277 io_buf_len_ = data->pickle()->size(); 2282 io_buf_len_ = data->pickle()->size();
2278 return ResetCacheIOStart( 2283 return ResetCacheIOStart(entry_->disk_entry->WriteData(
2279 entry_->disk_entry->WriteData(kResponseInfoIndex, 0, data, 2284 kResponseInfoIndex, 0, data.get(), io_buf_len_, io_callback_, true));
2280 io_buf_len_, io_callback_, true));
2281 } 2285 }
2282 2286
2283 int HttpCache::Transaction::AppendResponseDataToEntry( 2287 int HttpCache::Transaction::AppendResponseDataToEntry(
2284 IOBuffer* data, int data_len, const CompletionCallback& callback) { 2288 IOBuffer* data, int data_len, const CompletionCallback& callback) {
2285 if (!entry_ || !data_len) 2289 if (!entry_ || !data_len)
2286 return data_len; 2290 return data_len;
2287 2291
2288 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); 2292 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex);
2289 return WriteToEntry(kResponseContentIndex, current_size, data, data_len, 2293 return WriteToEntry(kResponseContentIndex, current_size, data, data_len,
2290 callback); 2294 callback);
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
2591 void HttpCache::Transaction::ResetNetworkTransaction() { 2595 void HttpCache::Transaction::ResetNetworkTransaction() {
2592 DCHECK(!old_network_trans_load_timing_); 2596 DCHECK(!old_network_trans_load_timing_);
2593 DCHECK(network_trans_); 2597 DCHECK(network_trans_);
2594 LoadTimingInfo load_timing; 2598 LoadTimingInfo load_timing;
2595 if (network_trans_->GetLoadTimingInfo(&load_timing)) 2599 if (network_trans_->GetLoadTimingInfo(&load_timing))
2596 old_network_trans_load_timing_.reset(new LoadTimingInfo(load_timing)); 2600 old_network_trans_load_timing_.reset(new LoadTimingInfo(load_timing));
2597 network_trans_.reset(); 2601 network_trans_.reset();
2598 } 2602 }
2599 2603
2600 } // namespace net 2604 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_cache.cc ('k') | net/http/http_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698