| 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 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 | 10 |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 if (!backend_factory_.get()) | 438 if (!backend_factory_.get()) |
| 439 return ERR_FAILED; | 439 return ERR_FAILED; |
| 440 | 440 |
| 441 building_backend_ = true; | 441 building_backend_ = true; |
| 442 | 442 |
| 443 scoped_ptr<WorkItem> item(new WorkItem(WI_CREATE_BACKEND, NULL, callback, | 443 scoped_ptr<WorkItem> item(new WorkItem(WI_CREATE_BACKEND, NULL, callback, |
| 444 backend)); | 444 backend)); |
| 445 | 445 |
| 446 // This is the only operation that we can do that is not related to any given | 446 // This is the only operation that we can do that is not related to any given |
| 447 // entry, so we use an empty key for it. | 447 // entry, so we use an empty key for it. |
| 448 PendingOp* pending_op = GetPendingOp(""); | 448 PendingOp* pending_op = GetPendingOp(std::string()); |
| 449 if (pending_op->writer) { | 449 if (pending_op->writer) { |
| 450 if (!callback.is_null()) | 450 if (!callback.is_null()) |
| 451 pending_op->pending_queue.push_back(item.release()); | 451 pending_op->pending_queue.push_back(item.release()); |
| 452 return ERR_IO_PENDING; | 452 return ERR_IO_PENDING; |
| 453 } | 453 } |
| 454 | 454 |
| 455 DCHECK(pending_op->pending_queue.empty()); | 455 DCHECK(pending_op->pending_queue.empty()); |
| 456 | 456 |
| 457 pending_op->writer = item.release(); | 457 pending_op->writer = item.release(); |
| 458 pending_op->callback = base::Bind(&HttpCache::OnPendingOpComplete, | 458 pending_op->callback = base::Bind(&HttpCache::OnPendingOpComplete, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 470 | 470 |
| 471 int HttpCache::GetBackendForTransaction(Transaction* trans) { | 471 int HttpCache::GetBackendForTransaction(Transaction* trans) { |
| 472 if (disk_cache_.get()) | 472 if (disk_cache_.get()) |
| 473 return OK; | 473 return OK; |
| 474 | 474 |
| 475 if (!building_backend_) | 475 if (!building_backend_) |
| 476 return ERR_FAILED; | 476 return ERR_FAILED; |
| 477 | 477 |
| 478 WorkItem* item = new WorkItem( | 478 WorkItem* item = new WorkItem( |
| 479 WI_CREATE_BACKEND, trans, net::CompletionCallback(), NULL); | 479 WI_CREATE_BACKEND, trans, net::CompletionCallback(), NULL); |
| 480 PendingOp* pending_op = GetPendingOp(""); | 480 PendingOp* pending_op = GetPendingOp(std::string()); |
| 481 DCHECK(pending_op->writer); | 481 DCHECK(pending_op->writer); |
| 482 pending_op->pending_queue.push_back(item); | 482 pending_op->pending_queue.push_back(item); |
| 483 return ERR_IO_PENDING; | 483 return ERR_IO_PENDING; |
| 484 } | 484 } |
| 485 | 485 |
| 486 // Generate a key that can be used inside the cache. | 486 // Generate a key that can be used inside the cache. |
| 487 std::string HttpCache::GenerateCacheKey(const HttpRequestInfo* request) { | 487 std::string HttpCache::GenerateCacheKey(const HttpRequestInfo* request) { |
| 488 // Strip out the reference, username, and password sections of the URL. | 488 // Strip out the reference, username, and password sections of the URL. |
| 489 std::string url = HttpUtil::SpecForRequest(request->url); | 489 std::string url = HttpUtil::SpecForRequest(request->url); |
| 490 | 490 |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 void HttpCache::RemovePendingTransaction(Transaction* trans) { | 889 void HttpCache::RemovePendingTransaction(Transaction* trans) { |
| 890 ActiveEntriesMap::const_iterator i = active_entries_.find(trans->key()); | 890 ActiveEntriesMap::const_iterator i = active_entries_.find(trans->key()); |
| 891 bool found = false; | 891 bool found = false; |
| 892 if (i != active_entries_.end()) | 892 if (i != active_entries_.end()) |
| 893 found = RemovePendingTransactionFromEntry(i->second, trans); | 893 found = RemovePendingTransactionFromEntry(i->second, trans); |
| 894 | 894 |
| 895 if (found) | 895 if (found) |
| 896 return; | 896 return; |
| 897 | 897 |
| 898 if (building_backend_) { | 898 if (building_backend_) { |
| 899 PendingOpsMap::const_iterator j = pending_ops_.find(""); | 899 PendingOpsMap::const_iterator j = pending_ops_.find(std::string()); |
| 900 if (j != pending_ops_.end()) | 900 if (j != pending_ops_.end()) |
| 901 found = RemovePendingTransactionFromPendingOp(j->second, trans); | 901 found = RemovePendingTransactionFromPendingOp(j->second, trans); |
| 902 | 902 |
| 903 if (found) | 903 if (found) |
| 904 return; | 904 return; |
| 905 } | 905 } |
| 906 | 906 |
| 907 PendingOpsMap::const_iterator j = pending_ops_.find(trans->key()); | 907 PendingOpsMap::const_iterator j = pending_ops_.find(trans->key()); |
| 908 if (j != pending_ops_.end()) | 908 if (j != pending_ops_.end()) |
| 909 found = RemovePendingTransactionFromPendingOp(j->second, trans); | 909 found = RemovePendingTransactionFromPendingOp(j->second, trans); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 building_backend_ = false; | 1127 building_backend_ = false; |
| 1128 DeletePendingOp(pending_op); | 1128 DeletePendingOp(pending_op); |
| 1129 } | 1129 } |
| 1130 | 1130 |
| 1131 // The cache may be gone when we return from the callback. | 1131 // The cache may be gone when we return from the callback. |
| 1132 if (!item->DoCallback(result, backend)) | 1132 if (!item->DoCallback(result, backend)) |
| 1133 item->NotifyTransaction(result, NULL); | 1133 item->NotifyTransaction(result, NULL); |
| 1134 } | 1134 } |
| 1135 | 1135 |
| 1136 } // namespace net | 1136 } // namespace net |
| OLD | NEW |