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

Unified Diff: net/http/http_cache_lookup_manager.cc

Issue 2503473004: Server push cancellation: add a new class HttpCacheLookupManager which implements ServerPushDelegate (Closed)
Patch Set: address rch's comments 1 Created 4 years, 1 month 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_lookup_manager.cc
diff --git a/net/http/http_cache_lookup_manager.cc b/net/http/http_cache_lookup_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..582e6a46d0ca9c97c020b53d42acc8aa6cf00559
--- /dev/null
+++ b/net/http/http_cache_lookup_manager.cc
@@ -0,0 +1,65 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/http/http_cache_lookup_manager.h"
+
+#include "net/base/load_flags.h"
+
+namespace net {
+
+HttpCacheLookupManager::LookupTransaction::LookupTransaction(
+ std::unique_ptr<ServerPushHelper> server_push_helper)
+ : push_helper(std::move(server_push_helper)),
+ request(new HttpRequestInfo()),
+ transaction(nullptr) {
+ request->url = push_helper->GetURL();
+ request->method = "GET";
+ request->load_flags = LOAD_ONLY_FROM_CACHE | LOAD_SKIP_CACHE_VALIDATION;
+}
+
+HttpCacheLookupManager::LookupTransaction::~LookupTransaction() {}
+
+HttpCacheLookupManager::HttpCacheLookupManager(HttpCache* http_cache,
+ const NetLogWithSource& net_log)
+ : net_log_(net_log), http_cache_(http_cache), weak_factory_(this) {}
+
+HttpCacheLookupManager::~HttpCacheLookupManager() {}
+
+void HttpCacheLookupManager::OnPush(
+ std::unique_ptr<ServerPushHelper> push_helper) {
+ GURL pushed_url = push_helper->GetURL();
+
+ // There's a pending lookup transaction sent over already.
+ if (lookup_transactions_.find(pushed_url) != lookup_transactions_.end())
+ return;
+
+ auto lookup = base::MakeUnique<LookupTransaction>(std::move(push_helper));
+
+ int rv =
+ http_cache_->CreateTransaction(DEFAULT_PRIORITY, &lookup->transaction);
+ if (rv != OK)
Ryan Hamilton 2016/11/17 22:47:24 Can this return ERR_IO_PENDING? It looks like no.
Zhongyi Shi 2016/11/18 20:34:19 Actually, the only response from CreateTransaction
+ return;
+
+ rv = lookup->transaction->Start(
+ lookup->request.get(),
+ base::Bind(&HttpCacheLookupManager::OnPushFilteringComplete,
+ weak_factory_.GetWeakPtr(), pushed_url),
+ net_log_);
+
+ if (rv == ERR_IO_PENDING) {
+ lookup_transactions_[pushed_url] = std::move(lookup);
+ }
+}
+
+void HttpCacheLookupManager::OnPushFilteringComplete(const GURL& url, int rv) {
+ auto it = lookup_transactions_.find(url);
+ DCHECK(it != lookup_transactions_.end());
+
+ if (rv == OK)
+ it->second->push_helper->Cancel();
+
+ lookup_transactions_.erase(it);
+}
+
+} // namespace net

Powered by Google App Engine
This is Rietveld 408576698