OLD | NEW |
---|---|
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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.h" | 5 #include "net/http/http_cache.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 mode_ = NONE; | 455 mode_ = NONE; |
456 } | 456 } |
457 } | 457 } |
458 } | 458 } |
459 | 459 |
460 // if must use cache, then we must fail. this can happen for back/forward | 460 // if must use cache, then we must fail. this can happen for back/forward |
461 // navigations to a page generated via a form post. | 461 // navigations to a page generated via a form post. |
462 if (!(mode_ & READ) && effective_load_flags_ & LOAD_ONLY_FROM_CACHE) | 462 if (!(mode_ & READ) && effective_load_flags_ & LOAD_ONLY_FROM_CACHE) |
463 return ERR_CACHE_MISS; | 463 return ERR_CACHE_MISS; |
464 | 464 |
465 if (mode_ == NONE) | 465 if (mode_ == NONE) { |
466 if (partial_.get()) | |
467 partial_->RestoreHeaders(&custom_request_->extra_headers); | |
466 rv = BeginNetworkRequest(); | 468 rv = BeginNetworkRequest(); |
467 else | 469 } else { |
468 rv = AddToEntry(); | 470 rv = AddToEntry(); |
471 } | |
469 | 472 |
470 // setting this here allows us to check for the existance of a callback_ to | 473 // setting this here allows us to check for the existance of a callback_ to |
471 // determine if we are still inside Start. | 474 // determine if we are still inside Start. |
472 if (rv == ERR_IO_PENDING) | 475 if (rv == ERR_IO_PENDING) |
473 callback_ = callback; | 476 callback_ = callback; |
474 | 477 |
475 return rv; | 478 return rv; |
476 } | 479 } |
477 | 480 |
478 int HttpCache::Transaction::RestartIgnoringLastError( | 481 int HttpCache::Transaction::RestartIgnoringLastError( |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
627 entry = cache_->FindActiveEntry(cache_key_); | 630 entry = cache_->FindActiveEntry(cache_key_); |
628 if (!entry) { | 631 if (!entry) { |
629 LoadLog::BeginEvent(load_log_, LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY); | 632 LoadLog::BeginEvent(load_log_, LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY); |
630 entry = cache_->OpenEntry(cache_key_); | 633 entry = cache_->OpenEntry(cache_key_); |
631 LoadLog::EndEvent(load_log_, LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY); | 634 LoadLog::EndEvent(load_log_, LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY); |
632 if (!entry) { | 635 if (!entry) { |
633 if (mode_ == READ_WRITE) { | 636 if (mode_ == READ_WRITE) { |
634 mode_ = WRITE; | 637 mode_ = WRITE; |
635 } else if (mode_ == UPDATE) { | 638 } else if (mode_ == UPDATE) { |
636 // There is no cache entry to update; proceed without caching. | 639 // There is no cache entry to update; proceed without caching. |
637 mode_ = NONE; | 640 mode_ = NONE; |
eroman
2009/11/03 04:51:28
I expect you need to restore headers here too.
rvargas (doing something else)
2009/11/03 18:28:26
This block requires mode_ to be UPDATE so we don't
| |
638 return BeginNetworkRequest(); | 641 return BeginNetworkRequest(); |
639 } else { | 642 } else { |
640 if (cache_->mode() == PLAYBACK) | 643 if (cache_->mode() == PLAYBACK) |
641 DLOG(INFO) << "Playback Cache Miss: " << request_->url; | 644 DLOG(INFO) << "Playback Cache Miss: " << request_->url; |
642 | 645 |
643 // entry does not exist, and not permitted to create a new entry, so | 646 // entry does not exist, and not permitted to create a new entry, so |
644 // we must fail. | 647 // we must fail. |
645 return HandleResult(ERR_CACHE_MISS); | 648 return HandleResult(ERR_CACHE_MISS); |
646 } | 649 } |
647 } | 650 } |
648 } | 651 } |
649 } | 652 } |
650 | 653 |
651 if (mode_ == WRITE) { | 654 if (mode_ == WRITE) { |
652 DCHECK(!entry); | 655 DCHECK(!entry); |
653 LoadLog::BeginEvent(load_log_, LoadLog::TYPE_HTTP_CACHE_CREATE_ENTRY); | 656 LoadLog::BeginEvent(load_log_, LoadLog::TYPE_HTTP_CACHE_CREATE_ENTRY); |
654 entry = cache_->CreateEntry(cache_key_); | 657 entry = cache_->CreateEntry(cache_key_); |
655 LoadLog::EndEvent(load_log_, LoadLog::TYPE_HTTP_CACHE_CREATE_ENTRY); | 658 LoadLog::EndEvent(load_log_, LoadLog::TYPE_HTTP_CACHE_CREATE_ENTRY); |
656 if (!entry) { | 659 if (!entry) { |
657 DLOG(WARNING) << "unable to create cache entry"; | 660 DLOG(WARNING) << "unable to create cache entry"; |
658 mode_ = NONE; | 661 mode_ = NONE; |
662 if (partial_.get()) | |
663 partial_->RestoreHeaders(&custom_request_->extra_headers); | |
659 return BeginNetworkRequest(); | 664 return BeginNetworkRequest(); |
660 } | 665 } |
661 } | 666 } |
662 | 667 |
663 | 668 |
664 LoadLog::BeginEvent(load_log_, LoadLog::TYPE_HTTP_CACHE_WAITING); | 669 LoadLog::BeginEvent(load_log_, LoadLog::TYPE_HTTP_CACHE_WAITING); |
665 return cache_->AddTransactionToEntry(entry, this); | 670 return cache_->AddTransactionToEntry(entry, this); |
666 } | 671 } |
667 | 672 |
668 int HttpCache::Transaction::EntryAvailable(ActiveEntry* entry) { | 673 int HttpCache::Transaction::EntryAvailable(ActiveEntry* entry) { |
(...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1579 DoneWritingToEntry(true); | 1584 DoneWritingToEntry(true); |
1580 } | 1585 } |
1581 if (reading_ && partial_.get()) { | 1586 if (reading_ && partial_.get()) { |
1582 if (network_trans_.get()) { | 1587 if (network_trans_.get()) { |
1583 result = ReadFromNetwork(read_buf_, read_buf_len_); | 1588 result = ReadFromNetwork(read_buf_, read_buf_len_); |
1584 } else { | 1589 } else { |
1585 result = ReadFromEntry(read_buf_, read_buf_len_); | 1590 result = ReadFromEntry(read_buf_, read_buf_len_); |
1586 } | 1591 } |
1587 if (result >= 0 || result == net::ERR_IO_PENDING) | 1592 if (result >= 0 || result == net::ERR_IO_PENDING) |
1588 return; | 1593 return; |
1589 } else if (partial_.get()) { | 1594 } else if (mode_ != NONE && partial_.get()) { |
1590 // We are about to return the headers for a byte-range request to the | 1595 // We are about to return the headers for a byte-range request to the |
1591 // user, so let's fix them. | 1596 // user, so let's fix them. |
1592 partial_->FixResponseHeaders(response_.headers); | 1597 partial_->FixResponseHeaders(response_.headers); |
1593 } | 1598 } |
1594 } | 1599 } |
1595 } else if (IsCertificateError(result)) { | 1600 } else if (IsCertificateError(result)) { |
1596 const HttpResponseInfo* response = network_trans_->GetResponseInfo(); | 1601 const HttpResponseInfo* response = network_trans_->GetResponseInfo(); |
1597 // If we get a certificate error, then there is a certificate in ssl_info, | 1602 // If we get a certificate error, then there is a certificate in ssl_info, |
1598 // so GetResponseInfo() should never returns NULL here. | 1603 // so GetResponseInfo() should never returns NULL here. |
1599 DCHECK(response); | 1604 DCHECK(response); |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2099 static_cast<net::HttpNetworkLayer*>(network_layer_.get()); | 2104 static_cast<net::HttpNetworkLayer*>(network_layer_.get()); |
2100 HttpNetworkSession* session = network->GetSession(); | 2105 HttpNetworkSession* session = network->GetSession(); |
2101 if (session) { | 2106 if (session) { |
2102 session->tcp_socket_pool()->CloseIdleSockets(); | 2107 session->tcp_socket_pool()->CloseIdleSockets(); |
2103 } | 2108 } |
2104 } | 2109 } |
2105 | 2110 |
2106 //----------------------------------------------------------------------------- | 2111 //----------------------------------------------------------------------------- |
2107 | 2112 |
2108 } // namespace net | 2113 } // namespace net |
OLD | NEW |