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..1a5debc5caa89850ccf3d99ec6bd14c391ac5a6c |
--- /dev/null |
+++ b/net/http/http_cache_lookup_manager.cc |
@@ -0,0 +1,70 @@ |
+// 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) {} |
+ |
+HttpCacheLookupManager::LookupTransaction::~LookupTransaction() {} |
+ |
+int HttpCacheLookupManager::LookupTransaction::StartLookup( |
+ HttpCache* cache, |
+ const CompletionCallback& callback, |
+ const NetLogWithSource& net_log) { |
+ request->url = push_helper->GetURL(); |
+ request->method = "GET"; |
+ request->load_flags = LOAD_ONLY_FROM_CACHE | LOAD_SKIP_CACHE_VALIDATION; |
jkarlin
2016/11/21 14:40:41
So, if the resource is in the cache (valid or not)
Zhongyi Shi
2016/11/22 00:09:29
Yup, we want to cancel the server push if the url
|
+ cache->CreateTransaction(DEFAULT_PRIORITY, &transaction); |
+ return transaction->Start(request.get(), callback, net_log); |
+} |
+ |
+void HttpCacheLookupManager::LookupTransaction::CancelPush() { |
+ DCHECK(push_helper.get()); |
+ push_helper->Cancel(); |
+} |
+ |
+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 (base::ContainsKey(lookup_transactions_, pushed_url)) |
+ return; |
+ |
+ auto lookup = base::MakeUnique<LookupTransaction>(std::move(push_helper)); |
+ |
+ int rv = lookup->StartLookup( |
+ http_cache_, base::Bind(&HttpCacheLookupManager::OnLookupComplete, |
+ weak_factory_.GetWeakPtr(), pushed_url), |
+ net_log_); |
+ |
+ if (rv == ERR_IO_PENDING) |
+ lookup_transactions_[pushed_url] = std::move(lookup); |
+} |
+ |
+void HttpCacheLookupManager::OnLookupComplete(const GURL& url, int rv) { |
+ auto it = lookup_transactions_.find(url); |
+ DCHECK(it != lookup_transactions_.end()); |
+ |
+ if (rv == OK) |
+ it->second->CancelPush(); |
+ |
+ lookup_transactions_.erase(it); |
+} |
+ |
+} // namespace net |