| 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 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 | 10 |
| (...skipping 1715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1726 active_entries_[key] = entry; | 1726 active_entries_[key] = entry; |
| 1727 return entry; | 1727 return entry; |
| 1728 } | 1728 } |
| 1729 | 1729 |
| 1730 #if defined(OS_WIN) | 1730 #if defined(OS_WIN) |
| 1731 #pragma optimize("", off) | 1731 #pragma optimize("", off) |
| 1732 #pragma warning(disable:4748) | 1732 #pragma warning(disable:4748) |
| 1733 #endif | 1733 #endif |
| 1734 // Avoid optimizing local_entry out of the code. | 1734 // Avoid optimizing local_entry out of the code. |
| 1735 void HttpCache::DeactivateEntry(ActiveEntry* entry) { | 1735 void HttpCache::DeactivateEntry(ActiveEntry* entry) { |
| 1736 std::string key = entry->disk_entry->GetKey(); |
| 1737 if (key.empty()) |
| 1738 return SlowDeactivateEntry(entry); |
| 1739 |
| 1736 // TODO(rvargas): remove this code and go back to DCHECKS once we find out | 1740 // TODO(rvargas): remove this code and go back to DCHECKS once we find out |
| 1737 // why are we crashing. I'm just trying to gather more info for bug 3931. | 1741 // why are we crashing. I'm just trying to gather more info for bug 3931. |
| 1738 ActiveEntry local_entry = *entry; | 1742 ActiveEntry local_entry = *entry; |
| 1739 size_t readers_size = local_entry.readers.size(); | 1743 size_t readers_size = local_entry.readers.size(); |
| 1740 size_t pending_size = local_entry.pending_queue.size(); | 1744 size_t pending_size = local_entry.pending_queue.size(); |
| 1741 | 1745 |
| 1742 std::string key = entry->disk_entry->GetKey(); | |
| 1743 ActiveEntriesMap::iterator it = active_entries_.find(key); | 1746 ActiveEntriesMap::iterator it = active_entries_.find(key); |
| 1744 if (it == active_entries_.end() || it->second != entry || | 1747 if (it == active_entries_.end() || it->second != entry || |
| 1745 local_entry.will_process_pending_queue || local_entry.doomed || | 1748 local_entry.will_process_pending_queue || local_entry.doomed || |
| 1746 local_entry.writer || readers_size || pending_size || deleted_) { | 1749 local_entry.writer || readers_size || pending_size || deleted_) { |
| 1747 bool local_mem_flag = in_memory_cache_; | 1750 bool local_mem_flag = in_memory_cache_; |
| 1748 ActiveEntriesSet::iterator it2 = doomed_entries_.find(entry); | 1751 ActiveEntriesSet::iterator it2 = doomed_entries_.find(entry); |
| 1749 char local_key[64]; | 1752 char local_key[64]; |
| 1750 int key_length = key.size(); | 1753 int key_length = key.size(); |
| 1751 base::strlcpy(local_key, key.c_str(), sizeof(local_key)); | 1754 base::strlcpy(local_key, key.c_str(), sizeof(local_key)); |
| 1752 CHECK(it2 == doomed_entries_.end()); | 1755 CHECK(it2 == doomed_entries_.end()); |
| 1753 CHECK(!deleted_); | 1756 CHECK(!deleted_); |
| 1754 CHECK(local_mem_flag); | 1757 CHECK(local_mem_flag); |
| 1755 CHECK(key_length); | 1758 CHECK(key_length); |
| 1756 CHECK(false); | 1759 CHECK(false); |
| 1757 } | 1760 } |
| 1758 | 1761 |
| 1759 active_entries_.erase(it); | 1762 active_entries_.erase(it); |
| 1760 delete entry; | 1763 delete entry; |
| 1761 | 1764 |
| 1762 // Avoid closing the disk_entry again on the destructor. | 1765 // Avoid closing the disk_entry again on the destructor. |
| 1763 local_entry.disk_entry = NULL; | 1766 local_entry.disk_entry = NULL; |
| 1764 } | 1767 } |
| 1765 #if defined(OS_WIN) | 1768 #if defined(OS_WIN) |
| 1766 #pragma warning(default:4748) | 1769 #pragma warning(default:4748) |
| 1767 #pragma optimize("", on) | 1770 #pragma optimize("", on) |
| 1768 #endif | 1771 #endif |
| 1769 | 1772 |
| 1773 // We don't know this entry's key so we have to find it without it. |
| 1774 void HttpCache::SlowDeactivateEntry(ActiveEntry* entry) { |
| 1775 for (ActiveEntriesMap::iterator it = active_entries_.begin(); |
| 1776 it != active_entries_.end(); ++it) { |
| 1777 if (it->second == entry) { |
| 1778 active_entries_.erase(it); |
| 1779 delete entry; |
| 1780 break; |
| 1781 } |
| 1782 } |
| 1783 } |
| 1784 |
| 1770 int HttpCache::AddTransactionToEntry(ActiveEntry* entry, Transaction* trans) { | 1785 int HttpCache::AddTransactionToEntry(ActiveEntry* entry, Transaction* trans) { |
| 1771 DCHECK(entry); | 1786 DCHECK(entry); |
| 1772 | 1787 |
| 1773 // We implement a basic reader/writer lock for the disk cache entry. If | 1788 // We implement a basic reader/writer lock for the disk cache entry. If |
| 1774 // there is already a writer, then everyone has to wait for the writer to | 1789 // there is already a writer, then everyone has to wait for the writer to |
| 1775 // finish before they can access the cache entry. There can be multiple | 1790 // finish before they can access the cache entry. There can be multiple |
| 1776 // readers. | 1791 // readers. |
| 1777 // | 1792 // |
| 1778 // NOTE: If the transaction can only write, then the entry should not be in | 1793 // NOTE: If the transaction can only write, then the entry should not be in |
| 1779 // use (since any existing entry should have already been doomed). | 1794 // use (since any existing entry should have already been doomed). |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1946 static_cast<net::HttpNetworkLayer*>(network_layer_.get()); | 1961 static_cast<net::HttpNetworkLayer*>(network_layer_.get()); |
| 1947 HttpNetworkSession* session = network->GetSession(); | 1962 HttpNetworkSession* session = network->GetSession(); |
| 1948 if (session) { | 1963 if (session) { |
| 1949 session->connection_pool()->CloseIdleSockets(); | 1964 session->connection_pool()->CloseIdleSockets(); |
| 1950 } | 1965 } |
| 1951 } | 1966 } |
| 1952 | 1967 |
| 1953 //----------------------------------------------------------------------------- | 1968 //----------------------------------------------------------------------------- |
| 1954 | 1969 |
| 1955 } // namespace net | 1970 } // namespace net |
| OLD | NEW |