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

Unified 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: move it into the disk cache Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: net/http/http_cache.cc
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc
index d7461193762e31baf6c9c7608f1cc7ce345b9235..798756a7aa5e7e07520a37428162a5e455000fd4 100644
--- a/net/http/http_cache.cc
+++ b/net/http/http_cache.cc
@@ -30,6 +30,7 @@
#include "net/base/net_errors.h"
#include "net/base/upload_data_stream.h"
#include "net/disk_cache/disk_cache.h"
+#include "net/disk_cache/pending_create_entry.h"
#include "net/http/http_cache_transaction.h"
#include "net/http/http_network_layer.h"
#include "net/http/http_network_session.h"
@@ -102,7 +103,6 @@ struct HttpCache::PendingOp {
enum WorkItemOperation {
WI_CREATE_BACKEND,
WI_OPEN_ENTRY,
- WI_CREATE_ENTRY,
WI_DOOM_ENTRY
};
@@ -712,27 +712,10 @@ int HttpCache::OpenEntry(const std::string& key, ActiveEntry** entry,
int HttpCache::CreateEntry(const std::string& key, ActiveEntry** entry,
Transaction* trans) {
DCHECK(!FindActiveEntry(key));
-
- WorkItem* item = new WorkItem(WI_CREATE_ENTRY, trans, entry);
- PendingOp* pending_op = GetPendingOp(key);
- if (pending_op->writer) {
- pending_op->pending_queue.push_back(item);
- return ERR_IO_PENDING;
- }
-
- DCHECK(pending_op->pending_queue.empty());
-
- pending_op->writer = item;
- pending_op->callback = base::Bind(&HttpCache::OnPendingOpComplete,
- AsWeakPtr(), pending_op);
-
- int rv = disk_cache_->CreateEntry(key, &(pending_op->disk_entry),
- pending_op->callback);
- if (rv != ERR_IO_PENDING) {
- item->ClearTransaction();
- pending_op->callback.Run(rv);
- }
-
+ disk_cache::Entry* new_entry;
+ int rv = disk_cache::PendingCreateEntry(disk_cache_.get(), key, &new_entry);
rvargas (doing something else) 2013/01/23 22:04:09 why is this not calling CreateEntry?. I mean, if y
gavinp 2013/01/24 07:38:10 Good point. And if we want to do A/B tests (and we
+ if (rv == net::OK)
+ *entry = ActivateEntry(new_entry);
return rv;
}
@@ -1000,8 +983,6 @@ void HttpCache::OnIOComplete(int result, PendingOp* pending_op) {
entry = ActivateEntry(pending_op->disk_entry);
} else {
// The writer transaction is gone.
- if (op == WI_CREATE_ENTRY)
- pending_op->disk_entry->Doom();
pending_op->disk_entry->Close();
pending_op->disk_entry = NULL;
fail_requests = true;
@@ -1043,28 +1024,7 @@ void HttpCache::OnIOComplete(int result, PendingOp* pending_op) {
continue;
}
- if (item->operation() == WI_CREATE_ENTRY) {
- if (result == OK) {
- // A second Create request, but the first request succeeded.
- item->NotifyTransaction(ERR_CACHE_CREATE_FAILURE, NULL);
- } else {
- if (op != WI_CREATE_ENTRY) {
- // Failed Open followed by a Create.
- item->NotifyTransaction(ERR_CACHE_RACE, NULL);
- fail_requests = true;
- } else {
- item->NotifyTransaction(result, entry);
- }
- }
- } else {
- if (op == WI_CREATE_ENTRY && result != OK) {
- // Failed Create followed by an Open.
- item->NotifyTransaction(ERR_CACHE_RACE, NULL);
- fail_requests = true;
- } else {
- item->NotifyTransaction(result, entry);
- }
- }
+ item->NotifyTransaction(result, entry);
}
}

Powered by Google App Engine
This is Rietveld 408576698