OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 pending_ops_.erase(it); | 732 pending_ops_.erase(it); |
733 break; | 733 break; |
734 } | 734 } |
735 } | 735 } |
736 } | 736 } |
737 DCHECK(pending_op->pending_queue.empty()); | 737 DCHECK(pending_op->pending_queue.empty()); |
738 | 738 |
739 delete pending_op; | 739 delete pending_op; |
740 } | 740 } |
741 | 741 |
742 int HttpCache::OpenEntry(const std::string& key, ActiveEntry** entry, | 742 int HttpCache::OpenEntry(const std::string& key, |
| 743 ActiveEntry** entry, |
| 744 disk_cache::Backend::OracleCallback oracle_callback, |
743 Transaction* trans) { | 745 Transaction* trans) { |
744 ActiveEntry* active_entry = FindActiveEntry(key); | 746 ActiveEntry* active_entry = FindActiveEntry(key); |
745 if (active_entry) { | 747 if (active_entry) { |
746 *entry = active_entry; | 748 *entry = active_entry; |
747 return OK; | 749 return OK; |
748 } | 750 } |
749 | 751 |
| 752 // ### store the oracle callback in this case? |
750 std::unique_ptr<WorkItem> item = | 753 std::unique_ptr<WorkItem> item = |
751 base::MakeUnique<WorkItem>(WI_OPEN_ENTRY, trans, entry); | 754 base::MakeUnique<WorkItem>(WI_OPEN_ENTRY, trans, entry); |
752 PendingOp* pending_op = GetPendingOp(key); | 755 PendingOp* pending_op = GetPendingOp(key); |
753 if (pending_op->writer) { | 756 if (pending_op->writer) { |
754 pending_op->pending_queue.push_back(std::move(item)); | 757 pending_op->pending_queue.push_back(std::move(item)); |
755 return ERR_IO_PENDING; | 758 return ERR_IO_PENDING; |
756 } | 759 } |
757 | 760 |
758 DCHECK(pending_op->pending_queue.empty()); | 761 DCHECK(pending_op->pending_queue.empty()); |
759 | 762 |
760 pending_op->writer = std::move(item); | 763 pending_op->writer = std::move(item); |
761 pending_op->callback = base::Bind(&HttpCache::OnPendingOpComplete, | 764 pending_op->callback = base::Bind(&HttpCache::OnPendingOpComplete, |
762 GetWeakPtr(), pending_op); | 765 GetWeakPtr(), pending_op); |
763 | 766 |
764 int rv = disk_cache_->OpenEntry(key, &(pending_op->disk_entry), | 767 int rv; |
765 pending_op->callback); | 768 if (oracle_callback.is_null()) |
| 769 rv = disk_cache_->OpenEntry(key, &(pending_op->disk_entry), |
| 770 pending_op->callback); |
| 771 else |
| 772 rv = disk_cache_->OpenEntryWithOracleByte( |
| 773 key, &(pending_op->disk_entry), oracle_callback, pending_op->callback); |
766 if (rv != ERR_IO_PENDING) { | 774 if (rv != ERR_IO_PENDING) { |
767 pending_op->writer->ClearTransaction(); | 775 pending_op->writer->ClearTransaction(); |
768 pending_op->callback.Run(rv); | 776 pending_op->callback.Run(rv); |
769 } | 777 } |
770 | 778 |
771 return rv; | 779 return rv; |
772 } | 780 } |
773 | 781 |
774 int HttpCache::CreateEntry(const std::string& key, ActiveEntry** entry, | 782 int HttpCache::CreateEntry(const std::string& key, ActiveEntry** entry, |
775 Transaction* trans) { | 783 Transaction* trans) { |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1178 building_backend_ = false; | 1186 building_backend_ = false; |
1179 DeletePendingOp(pending_op); | 1187 DeletePendingOp(pending_op); |
1180 } | 1188 } |
1181 | 1189 |
1182 // The cache may be gone when we return from the callback. | 1190 // The cache may be gone when we return from the callback. |
1183 if (!item->DoCallback(result, disk_cache_.get())) | 1191 if (!item->DoCallback(result, disk_cache_.get())) |
1184 item->NotifyTransaction(result, NULL); | 1192 item->NotifyTransaction(result, NULL); |
1185 } | 1193 } |
1186 | 1194 |
1187 } // namespace net | 1195 } // namespace net |
OLD | NEW |