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..3de8cade56ea51c59fa22b711ba1ab6fe12a0548 |
--- /dev/null |
+++ b/net/http/http_cache_lookup_manager.cc |
@@ -0,0 +1,69 @@ |
+// 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) |
+ : transaction(nullptr) { |
+ push_helper = std::move(server_push_helper); |
+ request.reset(new HttpRequestInfo()); |
Ryan Hamilton
2016/11/15 23:16:06
nit: you can do both of these in the initializer l
Zhongyi Shi
2016/11/16 21:04:42
Done.
|
+ request->url = push_helper->GetURL(); |
+ request->method = "GET"; |
Ryan Hamilton
2016/11/15 23:16:06
Is GET the only method which can be pushed?
Zhongyi Shi
2016/11/16 21:04:42
I believe both "GET" and "HEAD" can be pushed for
|
+ request->load_flags = LOAD_ONLY_FROM_CACHE | LOAD_SKIP_CACHE_VALIDATION; |
Ryan Hamilton
2016/11/15 23:16:06
I'm not super familiar with all the details of the
Zhongyi Shi
2016/11/16 21:04:42
Cauz this is the step 1: we only want to check whe
Ryan Hamilton
2016/11/17 22:47:24
Ah! I wasn't actually sure what validation meant t
|
+} |
+ |
+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, cancel this one. |
+ if (lookup_transactions_.find(pushed_url) != lookup_transactions_.end()) |
+ return; |
Ryan Hamilton
2016/11/15 23:16:06
Why does simply returning cancel this push? Is tha
Zhongyi Shi
2016/11/16 21:04:42
Sorry for the confusion, I meant to say cancel sen
|
+ |
+ std::unique_ptr<LookupTransaction> lookup_transaction( |
+ new LookupTransaction(std::move(push_helper))); |
Ryan Hamilton
2016/11/15 23:16:06
nit: auto lookup = base::MakeUnique<LookupTransact
Zhongyi Shi
2016/11/16 21:04:42
Done.
|
+ int rv = http_cache_->CreateTransaction(DEFAULT_PRIORITY, |
+ &lookup_transaction->transaction); |
+ if (rv != OK) |
+ return; |
+ |
+ HttpTransaction* trans_ptr = lookup_transaction->transaction.get(); |
+ HttpRequestInfo* request_ptr = lookup_transaction->request.get(); |
+ |
+ lookup_transactions_[pushed_url] = std::move(lookup_transaction); |
Ryan Hamilton
2016/11/15 23:16:06
Perhaps this should only be done if Start returns
Zhongyi Shi
2016/11/16 21:04:42
Ah, good suggestion! I then could skip storing in
|
+ |
+ rv = trans_ptr->Start( |
+ request_ptr, base::Bind(&HttpCacheLookupManager::OnPushFilteringComplete, |
+ weak_factory_.GetWeakPtr(), pushed_url), |
+ net_log_); |
Ryan Hamilton
2016/11/15 23:16:05
I think it might be simpler to move all of this lo
Zhongyi Shi
2016/11/16 21:04:42
It's hard because in that case we will have the ma
Ryan Hamilton
2016/11/17 22:47:24
I may totally be missing the problem you're thinki
Zhongyi Shi
2016/11/18 20:34:19
Acknowledged.
|
+ |
+ if (rv == ERR_CACHE_MISS) { |
Ryan Hamilton
2016/11/15 23:16:06
What if start returns some other error?
Zhongyi Shi
2016/11/16 21:04:42
I think wither ERR_IO_PENDING or ERR_CACHE_MISS. E
Ryan Hamilton
2016/11/17 22:47:24
I think that makes sense. The callback will only b
Zhongyi Shi
2016/11/18 20:34:19
Acknowledged.
|
+ lookup_transactions_.erase(pushed_url); |
+ } |
+} |
+ |
+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 |