| 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" |
| 11 | 11 |
| 12 #if defined(OS_POSIX) | 12 #if defined(OS_POSIX) |
| 13 #include <unistd.h> | 13 #include <unistd.h> |
| 14 #endif | 14 #endif |
| 15 | 15 |
| 16 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
| 17 #include "base/pickle.h" | 17 #include "base/pickle.h" |
| 18 #include "base/ref_counted.h" | 18 #include "base/ref_counted.h" |
| 19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 20 #include "base/time.h" | 20 #include "base/time.h" |
| 21 #include "net/base/io_buffer.h" | 21 #include "net/base/io_buffer.h" |
| 22 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
| 23 #include "net/base/load_log.h" |
| 23 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 24 #include "net/base/ssl_cert_request_info.h" | 25 #include "net/base/ssl_cert_request_info.h" |
| 25 #include "net/disk_cache/disk_cache.h" | 26 #include "net/disk_cache/disk_cache.h" |
| 26 #include "net/http/http_network_layer.h" | 27 #include "net/http/http_network_layer.h" |
| 27 #include "net/http/http_network_session.h" | 28 #include "net/http/http_network_session.h" |
| 28 #include "net/http/http_request_info.h" | 29 #include "net/http/http_request_info.h" |
| 29 #include "net/http/http_response_headers.h" | 30 #include "net/http/http_response_headers.h" |
| 30 #include "net/http/http_response_info.h" | 31 #include "net/http/http_response_info.h" |
| 31 #include "net/http/http_transaction.h" | 32 #include "net/http/http_transaction.h" |
| 32 #include "net/http/http_util.h" | 33 #include "net/http/http_util.h" |
| (...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 ActiveEntry* entry = NULL; | 629 ActiveEntry* entry = NULL; |
| 629 | 630 |
| 630 if (revoked()) | 631 if (revoked()) |
| 631 return ERR_UNEXPECTED; | 632 return ERR_UNEXPECTED; |
| 632 | 633 |
| 633 if (mode_ == WRITE) { | 634 if (mode_ == WRITE) { |
| 634 cache_->DoomEntry(cache_key_); | 635 cache_->DoomEntry(cache_key_); |
| 635 } else { | 636 } else { |
| 636 entry = cache_->FindActiveEntry(cache_key_); | 637 entry = cache_->FindActiveEntry(cache_key_); |
| 637 if (!entry) { | 638 if (!entry) { |
| 639 LoadLog::BeginEvent(load_log_, LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY); |
| 638 entry = cache_->OpenEntry(cache_key_); | 640 entry = cache_->OpenEntry(cache_key_); |
| 641 LoadLog::EndEvent(load_log_, LoadLog::TYPE_HTTP_CACHE_OPEN_ENTRY); |
| 639 if (!entry) { | 642 if (!entry) { |
| 640 if (mode_ == READ_WRITE) { | 643 if (mode_ == READ_WRITE) { |
| 641 mode_ = WRITE; | 644 mode_ = WRITE; |
| 642 } else if (mode_ == UPDATE) { | 645 } else if (mode_ == UPDATE) { |
| 643 // There is no cache entry to update; proceed without caching. | 646 // There is no cache entry to update; proceed without caching. |
| 644 mode_ = NONE; | 647 mode_ = NONE; |
| 645 return BeginNetworkRequest(); | 648 return BeginNetworkRequest(); |
| 646 } else { | 649 } else { |
| 647 if (cache_->mode() == PLAYBACK) | 650 if (cache_->mode() == PLAYBACK) |
| 648 DLOG(INFO) << "Playback Cache Miss: " << request_->url; | 651 DLOG(INFO) << "Playback Cache Miss: " << request_->url; |
| 649 | 652 |
| 650 // entry does not exist, and not permitted to create a new entry, so | 653 // entry does not exist, and not permitted to create a new entry, so |
| 651 // we must fail. | 654 // we must fail. |
| 652 return HandleResult(ERR_CACHE_MISS); | 655 return HandleResult(ERR_CACHE_MISS); |
| 653 } | 656 } |
| 654 } | 657 } |
| 655 } | 658 } |
| 656 } | 659 } |
| 657 | 660 |
| 658 if (mode_ == WRITE) { | 661 if (mode_ == WRITE) { |
| 659 DCHECK(!entry); | 662 DCHECK(!entry); |
| 663 LoadLog::BeginEvent(load_log_, LoadLog::TYPE_HTTP_CACHE_CREATE_ENTRY); |
| 660 entry = cache_->CreateEntry(cache_key_); | 664 entry = cache_->CreateEntry(cache_key_); |
| 665 LoadLog::EndEvent(load_log_, LoadLog::TYPE_HTTP_CACHE_CREATE_ENTRY); |
| 661 if (!entry) { | 666 if (!entry) { |
| 662 DLOG(WARNING) << "unable to create cache entry"; | 667 DLOG(WARNING) << "unable to create cache entry"; |
| 663 mode_ = NONE; | 668 mode_ = NONE; |
| 664 return BeginNetworkRequest(); | 669 return BeginNetworkRequest(); |
| 665 } | 670 } |
| 666 } | 671 } |
| 667 | 672 |
| 673 |
| 674 LoadLog::BeginEvent(load_log_, LoadLog::TYPE_HTTP_CACHE_WAITING); |
| 668 return cache_->AddTransactionToEntry(entry, this); | 675 return cache_->AddTransactionToEntry(entry, this); |
| 669 } | 676 } |
| 670 | 677 |
| 671 int HttpCache::Transaction::EntryAvailable(ActiveEntry* entry) { | 678 int HttpCache::Transaction::EntryAvailable(ActiveEntry* entry) { |
| 679 LoadLog::EndEvent(load_log_, LoadLog::TYPE_HTTP_CACHE_WAITING); |
| 680 |
| 672 // We now have access to the cache entry. | 681 // We now have access to the cache entry. |
| 673 // | 682 // |
| 674 // o if we are the writer for the transaction, then we can start the network | 683 // o if we are the writer for the transaction, then we can start the network |
| 675 // transaction. | 684 // transaction. |
| 676 // | 685 // |
| 677 // o if we are a reader for the transaction, then we can start reading the | 686 // o if we are a reader for the transaction, then we can start reading the |
| 678 // cache entry. | 687 // cache entry. |
| 679 // | 688 // |
| 680 // o if we can read or write, then we should check if the cache entry needs | 689 // o if we can read or write, then we should check if the cache entry needs |
| 681 // to be validated and then issue a network request if needed or just read | 690 // to be validated and then issue a network request if needed or just read |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1266 rv = DoCacheReadCompleted(rv); | 1275 rv = DoCacheReadCompleted(rv); |
| 1267 } else if (rv != ERR_IO_PENDING) { | 1276 } else if (rv != ERR_IO_PENDING) { |
| 1268 cache_read_callback_->Release(); | 1277 cache_read_callback_->Release(); |
| 1269 } | 1278 } |
| 1270 return rv; | 1279 return rv; |
| 1271 } | 1280 } |
| 1272 | 1281 |
| 1273 int HttpCache::Transaction::ReadResponseInfoFromEntry() { | 1282 int HttpCache::Transaction::ReadResponseInfoFromEntry() { |
| 1274 DCHECK(entry_); | 1283 DCHECK(entry_); |
| 1275 | 1284 |
| 1276 if (!HttpCache::ReadResponseInfo(entry_->disk_entry, &response_, &truncated_)) | 1285 LoadLog::BeginEvent(load_log_, LoadLog::TYPE_HTTP_CACHE_READ_INFO); |
| 1277 return ERR_CACHE_READ_FAILURE; | 1286 bool read_ok = |
| 1278 return OK; | 1287 HttpCache::ReadResponseInfo(entry_->disk_entry, &response_, &truncated_); |
| 1288 LoadLog::EndEvent(load_log_, LoadLog::TYPE_HTTP_CACHE_READ_INFO); |
| 1289 |
| 1290 return read_ok ? OK : ERR_CACHE_READ_FAILURE; |
| 1279 } | 1291 } |
| 1280 | 1292 |
| 1281 void HttpCache::Transaction::WriteToEntry(int index, int offset, | 1293 void HttpCache::Transaction::WriteToEntry(int index, int offset, |
| 1282 IOBuffer* data, int data_len) { | 1294 IOBuffer* data, int data_len) { |
| 1283 if (!entry_) | 1295 if (!entry_) |
| 1284 return; | 1296 return; |
| 1285 | 1297 |
| 1286 int rv = 0; | 1298 int rv = 0; |
| 1287 if (!partial_.get() || !data_len) { | 1299 if (!partial_.get() || !data_len) { |
| 1288 rv = entry_->disk_entry->WriteData(index, offset, data, data_len, NULL, | 1300 rv = entry_->disk_entry->WriteData(index, offset, data, data_len, NULL, |
| (...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2108 static_cast<net::HttpNetworkLayer*>(network_layer_.get()); | 2120 static_cast<net::HttpNetworkLayer*>(network_layer_.get()); |
| 2109 HttpNetworkSession* session = network->GetSession(); | 2121 HttpNetworkSession* session = network->GetSession(); |
| 2110 if (session) { | 2122 if (session) { |
| 2111 session->tcp_socket_pool()->CloseIdleSockets(); | 2123 session->tcp_socket_pool()->CloseIdleSockets(); |
| 2112 } | 2124 } |
| 2113 } | 2125 } |
| 2114 | 2126 |
| 2115 //----------------------------------------------------------------------------- | 2127 //----------------------------------------------------------------------------- |
| 2116 | 2128 |
| 2117 } // namespace net | 2129 } // namespace net |
| OLD | NEW |