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

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

Issue 11787007: Race Create vs SendRequest on cache misses. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: lose a race Created 7 years, 10 months 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 | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/pending_create_entry.cc ('k') | net/net.gyp » ('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) 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 12 matching lines...) Expand all
23 #include "base/pickle.h" 23 #include "base/pickle.h"
24 #include "base/stl_util.h" 24 #include "base/stl_util.h"
25 #include "base/string_number_conversions.h" 25 #include "base/string_number_conversions.h"
26 #include "base/string_util.h" 26 #include "base/string_util.h"
27 #include "base/stringprintf.h" 27 #include "base/stringprintf.h"
28 #include "net/base/io_buffer.h" 28 #include "net/base/io_buffer.h"
29 #include "net/base/load_flags.h" 29 #include "net/base/load_flags.h"
30 #include "net/base/net_errors.h" 30 #include "net/base/net_errors.h"
31 #include "net/base/upload_data_stream.h" 31 #include "net/base/upload_data_stream.h"
32 #include "net/disk_cache/disk_cache.h" 32 #include "net/disk_cache/disk_cache.h"
33 #include "net/disk_cache/pending_create_entry.h"
33 #include "net/http/http_cache_transaction.h" 34 #include "net/http/http_cache_transaction.h"
34 #include "net/http/http_network_layer.h" 35 #include "net/http/http_network_layer.h"
35 #include "net/http/http_network_session.h" 36 #include "net/http/http_network_session.h"
36 #include "net/http/http_request_info.h" 37 #include "net/http/http_request_info.h"
37 #include "net/http/http_response_headers.h" 38 #include "net/http/http_response_headers.h"
38 #include "net/http/http_response_info.h" 39 #include "net/http/http_response_info.h"
39 #include "net/http/http_util.h" 40 #include "net/http/http_util.h"
40 41
41 namespace net { 42 namespace net {
42 43
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 if (rv != ERR_IO_PENDING) { 705 if (rv != ERR_IO_PENDING) {
705 item->ClearTransaction(); 706 item->ClearTransaction();
706 pending_op->callback.Run(rv); 707 pending_op->callback.Run(rv);
707 } 708 }
708 709
709 return rv; 710 return rv;
710 } 711 }
711 712
712 int HttpCache::CreateEntry(const std::string& key, ActiveEntry** entry, 713 int HttpCache::CreateEntry(const std::string& key, ActiveEntry** entry,
713 Transaction* trans) { 714 Transaction* trans) {
714 DCHECK(!FindActiveEntry(key)); 715 if (FindActiveEntry(key)) {
716 return ERR_CACHE_RACE;
717 }
715 718
716 WorkItem* item = new WorkItem(WI_CREATE_ENTRY, trans, entry); 719 WorkItem* item = new WorkItem(WI_CREATE_ENTRY, trans, entry);
717 PendingOp* pending_op = GetPendingOp(key); 720 PendingOp* pending_op = GetPendingOp(key);
718 if (pending_op->writer) { 721 if (pending_op->writer) {
719 pending_op->pending_queue.push_back(item); 722 pending_op->pending_queue.push_back(item);
720 return ERR_IO_PENDING; 723 return ERR_IO_PENDING;
721 } 724 }
722 725
723 DCHECK(pending_op->pending_queue.empty()); 726 DCHECK(pending_op->pending_queue.empty());
724 727
725 pending_op->writer = item; 728 pending_op->writer = item;
726 pending_op->callback = base::Bind(&HttpCache::OnPendingOpComplete, 729 pending_op->callback = base::Bind(&HttpCache::OnPendingOpComplete,
727 AsWeakPtr(), pending_op); 730 AsWeakPtr(), pending_op);
728 731
729 int rv = disk_cache_->CreateEntry(key, &(pending_op->disk_entry), 732 int rv = disk_cache::PendingCreateEntry(disk_cache_.get(), key,
730 pending_op->callback); 733 &(pending_op->disk_entry));
731 if (rv != ERR_IO_PENDING) { 734 if (rv != ERR_IO_PENDING) {
732 item->ClearTransaction(); 735 item->ClearTransaction();
733 pending_op->callback.Run(rv); 736 pending_op->callback.Run(rv);
734 } 737 }
735 738
736 return rv; 739 return rv;
737 } 740 }
738 741
739 void HttpCache::DestroyEntry(ActiveEntry* entry) { 742 void HttpCache::DestroyEntry(ActiveEntry* entry) {
740 if (entry->doomed) { 743 if (entry->doomed) {
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 building_backend_ = false; 1119 building_backend_ = false;
1117 DeletePendingOp(pending_op); 1120 DeletePendingOp(pending_op);
1118 } 1121 }
1119 1122
1120 // The cache may be gone when we return from the callback. 1123 // The cache may be gone when we return from the callback.
1121 if (!item->DoCallback(result, backend)) 1124 if (!item->DoCallback(result, backend))
1122 item->NotifyTransaction(result, NULL); 1125 item->NotifyTransaction(result, NULL);
1123 } 1126 }
1124 1127
1125 } // namespace net 1128 } // namespace net
OLDNEW
« no previous file with comments | « net/disk_cache/pending_create_entry.cc ('k') | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698