| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 return disk_cache_.get(); | 280 return disk_cache_.get(); |
| 281 | 281 |
| 282 DCHECK_GE(cache_size_, 0); | 282 DCHECK_GE(cache_size_, 0); |
| 283 if (type_ == MEMORY_CACHE) { | 283 if (type_ == MEMORY_CACHE) { |
| 284 // We may end up with no folder name and no cache if the initialization | 284 // We may end up with no folder name and no cache if the initialization |
| 285 // of the disk cache fails. We want to be sure that what we wanted to have | 285 // of the disk cache fails. We want to be sure that what we wanted to have |
| 286 // was an in-memory cache. | 286 // was an in-memory cache. |
| 287 disk_cache_.reset(disk_cache::CreateInMemoryCacheBackend(cache_size_)); | 287 disk_cache_.reset(disk_cache::CreateInMemoryCacheBackend(cache_size_)); |
| 288 } else if (!disk_cache_dir_.empty()) { | 288 } else if (!disk_cache_dir_.empty()) { |
| 289 disk_cache_.reset(disk_cache::CreateCacheBackend(disk_cache_dir_, true, | 289 disk_cache_.reset(disk_cache::CreateCacheBackend(disk_cache_dir_, true, |
| 290 cache_size_, type_)); | 290 cache_size_, type_)); |
| 291 disk_cache_dir_ = FilePath(); // Reclaim memory. | 291 disk_cache_dir_ = FilePath(); // Reclaim memory. |
| 292 } | 292 } |
| 293 return disk_cache_.get(); | 293 return disk_cache_.get(); |
| 294 } | 294 } |
| 295 | 295 |
| 296 int HttpCache::GetBackend(disk_cache::Backend** backend, | 296 int HttpCache::GetBackend(disk_cache::Backend** backend, |
| 297 CompletionCallback* callback) { | 297 CompletionCallback* callback) { |
| 298 DCHECK(callback != NULL); | 298 DCHECK(callback != NULL); |
| 299 *backend = GetBackend(); | 299 *backend = GetBackend(); |
| 300 return OK; | 300 return OK; |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 } | 800 } |
| 801 | 801 |
| 802 void HttpCache::ProcessPendingQueue(ActiveEntry* entry) { | 802 void HttpCache::ProcessPendingQueue(ActiveEntry* entry) { |
| 803 // Multiple readers may finish with an entry at once, so we want to batch up | 803 // Multiple readers may finish with an entry at once, so we want to batch up |
| 804 // calls to OnProcessPendingQueue. This flag also tells us that we should | 804 // calls to OnProcessPendingQueue. This flag also tells us that we should |
| 805 // not delete the entry before OnProcessPendingQueue runs. | 805 // not delete the entry before OnProcessPendingQueue runs. |
| 806 if (entry->will_process_pending_queue) | 806 if (entry->will_process_pending_queue) |
| 807 return; | 807 return; |
| 808 entry->will_process_pending_queue = true; | 808 entry->will_process_pending_queue = true; |
| 809 | 809 |
| 810 MessageLoop::current()->PostTask(FROM_HERE, | 810 MessageLoop::current()->PostTask( |
| 811 FROM_HERE, |
| 811 task_factory_.NewRunnableMethod(&HttpCache::OnProcessPendingQueue, | 812 task_factory_.NewRunnableMethod(&HttpCache::OnProcessPendingQueue, |
| 812 entry)); | 813 entry)); |
| 813 } | 814 } |
| 814 | 815 |
| 815 void HttpCache::OnProcessPendingQueue(ActiveEntry* entry) { | 816 void HttpCache::OnProcessPendingQueue(ActiveEntry* entry) { |
| 816 entry->will_process_pending_queue = false; | 817 entry->will_process_pending_queue = false; |
| 817 DCHECK(!entry->writer); | 818 DCHECK(!entry->writer); |
| 818 | 819 |
| 819 // If no one is interested in this entry, then we can de-activate it. | 820 // If no one is interested in this entry, then we can de-activate it. |
| 820 if (entry->pending_queue.empty()) { | 821 if (entry->pending_queue.empty()) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 } else { | 902 } else { |
| 902 if (op != WI_CREATE_ENTRY) { | 903 if (op != WI_CREATE_ENTRY) { |
| 903 // Failed Open followed by a Create. | 904 // Failed Open followed by a Create. |
| 904 item->NotifyTransaction(ERR_CACHE_RACE, NULL); | 905 item->NotifyTransaction(ERR_CACHE_RACE, NULL); |
| 905 fail_requests = true; | 906 fail_requests = true; |
| 906 } else { | 907 } else { |
| 907 item->NotifyTransaction(result, entry); | 908 item->NotifyTransaction(result, entry); |
| 908 } | 909 } |
| 909 } | 910 } |
| 910 } else { | 911 } else { |
| 911 if (op == WI_CREATE_ENTRY && result != OK) { | 912 if (op == WI_CREATE_ENTRY && result != OK) { |
| 912 // Failed Create followed by an Open. | 913 // Failed Create followed by an Open. |
| 913 item->NotifyTransaction(ERR_CACHE_RACE, NULL); | 914 item->NotifyTransaction(ERR_CACHE_RACE, NULL); |
| 914 fail_requests = true; | 915 fail_requests = true; |
| 915 } else { | 916 } else { |
| 916 item->NotifyTransaction(result, entry); | 917 item->NotifyTransaction(result, entry); |
| 917 } | 918 } |
| 918 } | 919 } |
| 919 } | 920 } |
| 920 } | 921 } |
| 921 | 922 |
| 922 } // namespace net | 923 } // namespace net |
| OLD | NEW |