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

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

Issue 49027: Disk cache: First pass to make it possible to have... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_cache.h ('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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 10
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 // When in record mode, we want to NEVER load from the cache. 576 // When in record mode, we want to NEVER load from the cache.
577 // The reason for this is beacuse we save the Set-Cookie headers 577 // The reason for this is beacuse we save the Set-Cookie headers
578 // (intentionally). If we read from the cache, we replay them 578 // (intentionally). If we read from the cache, we replay them
579 // prematurely. 579 // prematurely.
580 if (cache_->mode() == RECORD) 580 if (cache_->mode() == RECORD)
581 effective_load_flags_ |= LOAD_BYPASS_CACHE; 581 effective_load_flags_ |= LOAD_BYPASS_CACHE;
582 582
583 // If HttpCache has type MEDIA make sure LOAD_ENABLE_DOWNLOAD_FILE is set, 583 // If HttpCache has type MEDIA make sure LOAD_ENABLE_DOWNLOAD_FILE is set,
584 // otherwise make sure LOAD_ENABLE_DOWNLOAD_FILE is not set when HttpCache 584 // otherwise make sure LOAD_ENABLE_DOWNLOAD_FILE is not set when HttpCache
585 // has type other than MEDIA. 585 // has type other than MEDIA.
586 if (cache_->type() == HttpCache::MEDIA) { 586 if (cache_->type() == MEDIA_CACHE) {
587 DCHECK(effective_load_flags_ & LOAD_ENABLE_DOWNLOAD_FILE); 587 DCHECK(effective_load_flags_ & LOAD_ENABLE_DOWNLOAD_FILE);
588 } else { 588 } else {
589 DCHECK(!(effective_load_flags_ & LOAD_ENABLE_DOWNLOAD_FILE)); 589 DCHECK(!(effective_load_flags_ & LOAD_ENABLE_DOWNLOAD_FILE));
590 } 590 }
591 591
592 // Some headers imply load flags. The order here is significant. 592 // Some headers imply load flags. The order here is significant.
593 // 593 //
594 // LOAD_DISABLE_CACHE : no cache read or write 594 // LOAD_DISABLE_CACHE : no cache read or write
595 // LOAD_BYPASS_CACHE : no cache read 595 // LOAD_BYPASS_CACHE : no cache read
596 // LOAD_VALIDATE_CACHE : no cache read unless validation 596 // LOAD_VALIDATE_CACHE : no cache read unless validation
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 } 775 }
776 776
777 int HttpCache::Transaction::ReadResponseInfoFromEntry() { 777 int HttpCache::Transaction::ReadResponseInfoFromEntry() {
778 DCHECK(entry_); 778 DCHECK(entry_);
779 779
780 if (!HttpCache::ReadResponseInfo(entry_->disk_entry, &response_)) 780 if (!HttpCache::ReadResponseInfo(entry_->disk_entry, &response_))
781 return ERR_FAILED; 781 return ERR_FAILED;
782 782
783 // If the cache object is used for media file, we want the file handle of 783 // If the cache object is used for media file, we want the file handle of
784 // response data. 784 // response data.
785 if (cache_->type() == HttpCache::MEDIA) { 785 if (cache_->type() == MEDIA_CACHE) {
786 response_.response_data_file = 786 response_.response_data_file =
787 entry_->disk_entry->GetPlatformFile(kResponseContentIndex); 787 entry_->disk_entry->GetPlatformFile(kResponseContentIndex);
788 } 788 }
789 789
790 return OK; 790 return OK;
791 } 791 }
792 792
793 void HttpCache::Transaction::WriteToEntry(int index, int offset, 793 void HttpCache::Transaction::WriteToEntry(int index, int offset,
794 IOBuffer* data, int data_len) { 794 IOBuffer* data, int data_len) {
795 if (!entry_) 795 if (!entry_)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 849
850 // If the cache is for media files, we try to prepare the response data 850 // If the cache is for media files, we try to prepare the response data
851 // file as an external file and truncate it afterwards. 851 // file as an external file and truncate it afterwards.
852 // Recipient of ResponseInfo should judge from |response_.response_data_file| 852 // Recipient of ResponseInfo should judge from |response_.response_data_file|
853 // to tell whether an external file of response data is available for reading 853 // to tell whether an external file of response data is available for reading
854 // or not. 854 // or not.
855 // TODO(hclam): we should prepare the target stream as extern file only 855 // TODO(hclam): we should prepare the target stream as extern file only
856 // if we get a valid response from server, i.e. 200. We don't want empty 856 // if we get a valid response from server, i.e. 200. We don't want empty
857 // cache files for redirection or external files for erroneous requests. 857 // cache files for redirection or external files for erroneous requests.
858 response_.response_data_file = base::kInvalidPlatformFileValue; 858 response_.response_data_file = base::kInvalidPlatformFileValue;
859 if (cache_->type() == HttpCache::MEDIA) { 859 if (cache_->type() == MEDIA_CACHE) {
860 response_.response_data_file = 860 response_.response_data_file =
861 entry_->disk_entry->UseExternalFile(kResponseContentIndex); 861 entry_->disk_entry->UseExternalFile(kResponseContentIndex);
862 } 862 }
863 863
864 // Truncate the stream. 864 // Truncate the stream.
865 WriteToEntry(kResponseContentIndex, 0, NULL, 0); 865 WriteToEntry(kResponseContentIndex, 0, NULL, 0);
866 } 866 }
867 867
868 void HttpCache::Transaction::DoneWritingToEntry(bool success) { 868 void HttpCache::Transaction::DoneWritingToEntry(bool success) {
869 if (!entry_) 869 if (!entry_)
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 HandleResult(result); 970 HandleResult(result);
971 } 971 }
972 972
973 //----------------------------------------------------------------------------- 973 //-----------------------------------------------------------------------------
974 974
975 HttpCache::HttpCache(ProxyService* proxy_service, 975 HttpCache::HttpCache(ProxyService* proxy_service,
976 const std::wstring& cache_dir, 976 const std::wstring& cache_dir,
977 int cache_size) 977 int cache_size)
978 : disk_cache_dir_(cache_dir), 978 : disk_cache_dir_(cache_dir),
979 mode_(NORMAL), 979 mode_(NORMAL),
980 type_(COMMON), 980 type_(DISK_CACHE),
981 network_layer_(HttpNetworkLayer::CreateFactory(proxy_service)), 981 network_layer_(HttpNetworkLayer::CreateFactory(proxy_service)),
982 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), 982 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)),
983 in_memory_cache_(false), 983 in_memory_cache_(false),
984 cache_size_(cache_size) { 984 cache_size_(cache_size) {
985 } 985 }
986 986
987 HttpCache::HttpCache(HttpNetworkSession* session, 987 HttpCache::HttpCache(HttpNetworkSession* session,
988 const std::wstring& cache_dir, 988 const std::wstring& cache_dir,
989 int cache_size) 989 int cache_size)
990 : disk_cache_dir_(cache_dir), 990 : disk_cache_dir_(cache_dir),
991 mode_(NORMAL), 991 mode_(NORMAL),
992 type_(COMMON), 992 type_(DISK_CACHE),
993 network_layer_(HttpNetworkLayer::CreateFactory(session)), 993 network_layer_(HttpNetworkLayer::CreateFactory(session)),
994 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), 994 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)),
995 in_memory_cache_(false), 995 in_memory_cache_(false),
996 cache_size_(cache_size) { 996 cache_size_(cache_size) {
997 } 997 }
998 998
999 HttpCache::HttpCache(ProxyService* proxy_service, int cache_size) 999 HttpCache::HttpCache(ProxyService* proxy_service, int cache_size)
1000 : mode_(NORMAL), 1000 : mode_(NORMAL),
1001 type_(COMMON), 1001 type_(MEMORY_CACHE),
1002 network_layer_(HttpNetworkLayer::CreateFactory(proxy_service)), 1002 network_layer_(HttpNetworkLayer::CreateFactory(proxy_service)),
1003 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), 1003 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)),
1004 in_memory_cache_(true), 1004 in_memory_cache_(true),
1005 cache_size_(cache_size) { 1005 cache_size_(cache_size) {
1006 } 1006 }
1007 1007
1008 HttpCache::HttpCache(HttpTransactionFactory* network_layer, 1008 HttpCache::HttpCache(HttpTransactionFactory* network_layer,
1009 disk_cache::Backend* disk_cache) 1009 disk_cache::Backend* disk_cache)
1010 : mode_(NORMAL), 1010 : mode_(NORMAL),
1011 type_(COMMON), 1011 type_(DISK_CACHE),
1012 network_layer_(network_layer), 1012 network_layer_(network_layer),
1013 disk_cache_(disk_cache), 1013 disk_cache_(disk_cache),
1014 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), 1014 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)),
1015 in_memory_cache_(false), 1015 in_memory_cache_(false),
1016 cache_size_(0) { 1016 cache_size_(0) {
1017 } 1017 }
1018 1018
1019 HttpCache::~HttpCache() { 1019 HttpCache::~HttpCache() {
1020 // If we have any active entries remaining, then we need to deactivate them. 1020 // If we have any active entries remaining, then we need to deactivate them.
1021 // We may have some pending calls to OnProcessPendingQueue, but since those 1021 // We may have some pending calls to OnProcessPendingQueue, but since those
(...skipping 17 matching lines...) Expand all
1039 // Do lazy initialization of disk cache if needed. 1039 // Do lazy initialization of disk cache if needed.
1040 if (!disk_cache_.get()) { 1040 if (!disk_cache_.get()) {
1041 DCHECK(cache_size_ >= 0); 1041 DCHECK(cache_size_ >= 0);
1042 if (in_memory_cache_) { 1042 if (in_memory_cache_) {
1043 // We may end up with no folder name and no cache if the initialization 1043 // We may end up with no folder name and no cache if the initialization
1044 // of the disk cache fails. We want to be sure that what we wanted to have 1044 // of the disk cache fails. We want to be sure that what we wanted to have
1045 // was an in-memory cache. 1045 // was an in-memory cache.
1046 disk_cache_.reset(disk_cache::CreateInMemoryCacheBackend(cache_size_)); 1046 disk_cache_.reset(disk_cache::CreateInMemoryCacheBackend(cache_size_));
1047 } else if (!disk_cache_dir_.empty()) { 1047 } else if (!disk_cache_dir_.empty()) {
1048 disk_cache_.reset(disk_cache::CreateCacheBackend(disk_cache_dir_, true, 1048 disk_cache_.reset(disk_cache::CreateCacheBackend(disk_cache_dir_, true,
1049 cache_size_)); 1049 cache_size_, type_));
1050 disk_cache_dir_.clear(); // Reclaim memory. 1050 disk_cache_dir_.clear(); // Reclaim memory.
1051 } 1051 }
1052 } 1052 }
1053 return new HttpCache::Transaction(this); 1053 return new HttpCache::Transaction(this);
1054 } 1054 }
1055 1055
1056 HttpCache* HttpCache::GetCache() { 1056 HttpCache* HttpCache::GetCache() {
1057 return this; 1057 return this;
1058 } 1058 }
1059 1059
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
1477 return; // have to wait 1477 return; // have to wait
1478 1478
1479 entry->pending_queue.erase(entry->pending_queue.begin()); 1479 entry->pending_queue.erase(entry->pending_queue.begin());
1480 1480
1481 AddTransactionToEntry(entry, next); 1481 AddTransactionToEntry(entry, next);
1482 } 1482 }
1483 1483
1484 //----------------------------------------------------------------------------- 1484 //-----------------------------------------------------------------------------
1485 1485
1486 } // namespace net 1486 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_cache.h ('k') | net/http/http_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698