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

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

Issue 378015: Clear disk cache when the cache is not initialized (Closed)
Patch Set: simple test Created 11 years, 1 month 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
« 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-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 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 LOG(WARNING) << "Invalid byte range found."; 860 LOG(WARNING) << "Invalid byte range found.";
861 effective_load_flags_ |= LOAD_DISABLE_CACHE; 861 effective_load_flags_ |= LOAD_DISABLE_CACHE;
862 partial_.reset(NULL); 862 partial_.reset(NULL);
863 } 863 }
864 } 864 }
865 } 865 }
866 866
867 bool HttpCache::Transaction::ShouldPassThrough() { 867 bool HttpCache::Transaction::ShouldPassThrough() {
868 // We may have a null disk_cache if there is an error we cannot recover from, 868 // We may have a null disk_cache if there is an error we cannot recover from,
869 // like not enough disk space, or sharing violations. 869 // like not enough disk space, or sharing violations.
870 if (!cache_->disk_cache()) 870 if (!cache_->disk_cache_.get())
871 return true; 871 return true;
872 872
873 // When using the record/playback modes, we always use the cache 873 // When using the record/playback modes, we always use the cache
874 // and we never pass through. 874 // and we never pass through.
875 if (cache_->mode() == RECORD || cache_->mode() == PLAYBACK) 875 if (cache_->mode() == RECORD || cache_->mode() == PLAYBACK)
876 return false; 876 return false;
877 877
878 if (effective_load_flags_ & LOAD_DISABLE_CACHE) 878 if (effective_load_flags_ & LOAD_DISABLE_CACHE)
879 return true; 879 return true;
880 880
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after
1635 ProxyService* proxy_service, 1635 ProxyService* proxy_service,
1636 SSLConfigService* ssl_config_service, 1636 SSLConfigService* ssl_config_service,
1637 const FilePath& cache_dir, 1637 const FilePath& cache_dir,
1638 int cache_size) 1638 int cache_size)
1639 : disk_cache_dir_(cache_dir), 1639 : disk_cache_dir_(cache_dir),
1640 mode_(NORMAL), 1640 mode_(NORMAL),
1641 type_(DISK_CACHE), 1641 type_(DISK_CACHE),
1642 network_layer_(HttpNetworkLayer::CreateFactory( 1642 network_layer_(HttpNetworkLayer::CreateFactory(
1643 host_resolver, proxy_service, ssl_config_service)), 1643 host_resolver, proxy_service, ssl_config_service)),
1644 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), 1644 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)),
1645 in_memory_cache_(false),
1646 enable_range_support_(true), 1645 enable_range_support_(true),
1647 cache_size_(cache_size) { 1646 cache_size_(cache_size) {
1648 } 1647 }
1649 1648
1650 HttpCache::HttpCache(HttpNetworkSession* session, 1649 HttpCache::HttpCache(HttpNetworkSession* session,
1651 const FilePath& cache_dir, 1650 const FilePath& cache_dir,
1652 int cache_size) 1651 int cache_size)
1653 : disk_cache_dir_(cache_dir), 1652 : disk_cache_dir_(cache_dir),
1654 mode_(NORMAL), 1653 mode_(NORMAL),
1655 type_(DISK_CACHE), 1654 type_(DISK_CACHE),
1656 network_layer_(HttpNetworkLayer::CreateFactory(session)), 1655 network_layer_(HttpNetworkLayer::CreateFactory(session)),
1657 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), 1656 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)),
1658 in_memory_cache_(false),
1659 enable_range_support_(true), 1657 enable_range_support_(true),
1660 cache_size_(cache_size) { 1658 cache_size_(cache_size) {
1661 } 1659 }
1662 1660
1663 HttpCache::HttpCache(HostResolver* host_resolver, 1661 HttpCache::HttpCache(HostResolver* host_resolver,
1664 ProxyService* proxy_service, 1662 ProxyService* proxy_service,
1665 SSLConfigService* ssl_config_service, 1663 SSLConfigService* ssl_config_service,
1666 int cache_size) 1664 int cache_size)
1667 : mode_(NORMAL), 1665 : mode_(NORMAL),
1668 type_(MEMORY_CACHE), 1666 type_(MEMORY_CACHE),
1669 network_layer_(HttpNetworkLayer::CreateFactory( 1667 network_layer_(HttpNetworkLayer::CreateFactory(
1670 host_resolver, proxy_service, ssl_config_service)), 1668 host_resolver, proxy_service, ssl_config_service)),
1671 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), 1669 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)),
1672 in_memory_cache_(true),
1673 enable_range_support_(true), 1670 enable_range_support_(true),
1674 cache_size_(cache_size) { 1671 cache_size_(cache_size) {
1675 } 1672 }
1676 1673
1677 HttpCache::HttpCache(HttpTransactionFactory* network_layer, 1674 HttpCache::HttpCache(HttpTransactionFactory* network_layer,
1678 disk_cache::Backend* disk_cache) 1675 disk_cache::Backend* disk_cache)
1679 : mode_(NORMAL), 1676 : mode_(NORMAL),
1680 type_(DISK_CACHE), 1677 type_(DISK_CACHE),
1681 network_layer_(network_layer), 1678 network_layer_(network_layer),
1682 disk_cache_(disk_cache), 1679 disk_cache_(disk_cache),
1683 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), 1680 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)),
1684 in_memory_cache_(false),
1685 enable_range_support_(true), 1681 enable_range_support_(true),
1686 cache_size_(0) { 1682 cache_size_(0) {
1687 } 1683 }
1688 1684
1689 HttpCache::~HttpCache() { 1685 HttpCache::~HttpCache() {
1690 // If we have any active entries remaining, then we need to deactivate them. 1686 // If we have any active entries remaining, then we need to deactivate them.
1691 // We may have some pending calls to OnProcessPendingQueue, but since those 1687 // We may have some pending calls to OnProcessPendingQueue, but since those
1692 // won't run (due to our destruction), we can simply ignore the corresponding 1688 // won't run (due to our destruction), we can simply ignore the corresponding
1693 // will_process_pending_queue flag. 1689 // will_process_pending_queue flag.
1694 while (!active_entries_.empty()) { 1690 while (!active_entries_.empty()) {
1695 ActiveEntry* entry = active_entries_.begin()->second; 1691 ActiveEntry* entry = active_entries_.begin()->second;
1696 entry->will_process_pending_queue = false; 1692 entry->will_process_pending_queue = false;
1697 entry->pending_queue.clear(); 1693 entry->pending_queue.clear();
1698 entry->readers.clear(); 1694 entry->readers.clear();
1699 entry->writer = NULL; 1695 entry->writer = NULL;
1700 DeactivateEntry(entry); 1696 DeactivateEntry(entry);
1701 } 1697 }
1702 1698
1703 ActiveEntriesSet::iterator it = doomed_entries_.begin(); 1699 ActiveEntriesSet::iterator it = doomed_entries_.begin();
1704 for (; it != doomed_entries_.end(); ++it) 1700 for (; it != doomed_entries_.end(); ++it)
1705 delete *it; 1701 delete *it;
1706 } 1702 }
1707 1703
1704 disk_cache::Backend* HttpCache::GetBackend() {
1705 if (disk_cache_.get())
1706 return disk_cache_.get();
1707
1708 DCHECK_GE(cache_size_, 0);
1709 if (type_ == MEMORY_CACHE) {
1710 // We may end up with no folder name and no cache if the initialization
1711 // of the disk cache fails. We want to be sure that what we wanted to have
1712 // was an in-memory cache.
1713 disk_cache_.reset(disk_cache::CreateInMemoryCacheBackend(cache_size_));
1714 } else if (!disk_cache_dir_.empty()) {
1715 disk_cache_.reset(disk_cache::CreateCacheBackend(disk_cache_dir_, true,
1716 cache_size_, type_));
1717 disk_cache_dir_ = FilePath(); // Reclaim memory.
1718 }
1719 return disk_cache_.get();
1720 }
1721
1708 int HttpCache::CreateTransaction(scoped_ptr<HttpTransaction>* trans) { 1722 int HttpCache::CreateTransaction(scoped_ptr<HttpTransaction>* trans) {
1709 // Do lazy initialization of disk cache if needed. 1723 // Do lazy initialization of disk cache if needed.
1710 if (!disk_cache_.get()) { 1724 GetBackend();
1711 DCHECK_GE(cache_size_, 0);
1712 if (in_memory_cache_) {
1713 // We may end up with no folder name and no cache if the initialization
1714 // of the disk cache fails. We want to be sure that what we wanted to have
1715 // was an in-memory cache.
1716 disk_cache_.reset(disk_cache::CreateInMemoryCacheBackend(cache_size_));
1717 } else if (!disk_cache_dir_.empty()) {
1718 disk_cache_.reset(disk_cache::CreateCacheBackend(disk_cache_dir_, true,
1719 cache_size_, type_));
1720 disk_cache_dir_ = FilePath(); // Reclaim memory.
1721 }
1722 }
1723 trans->reset(new HttpCache::Transaction(this, enable_range_support_)); 1725 trans->reset(new HttpCache::Transaction(this, enable_range_support_));
1724 return OK; 1726 return OK;
1725 } 1727 }
1726 1728
1727 HttpCache* HttpCache::GetCache() { 1729 HttpCache* HttpCache::GetCache() {
1728 return this; 1730 return this;
1729 } 1731 }
1730 1732
1731 HttpNetworkSession* HttpCache::GetSession() { 1733 HttpNetworkSession* HttpCache::GetSession() {
1732 net::HttpNetworkLayer* network = 1734 net::HttpNetworkLayer* network =
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
2104 static_cast<net::HttpNetworkLayer*>(network_layer_.get()); 2106 static_cast<net::HttpNetworkLayer*>(network_layer_.get());
2105 HttpNetworkSession* session = network->GetSession(); 2107 HttpNetworkSession* session = network->GetSession();
2106 if (session) { 2108 if (session) {
2107 session->tcp_socket_pool()->CloseIdleSockets(); 2109 session->tcp_socket_pool()->CloseIdleSockets();
2108 } 2110 }
2109 } 2111 }
2110 2112
2111 //----------------------------------------------------------------------------- 2113 //-----------------------------------------------------------------------------
2112 2114
2113 } // namespace net 2115 } // 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