OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "net/http/http_cache_lookup_manager.h" | |
6 | |
7 #include "net/base/load_flags.h" | |
8 | |
9 namespace net { | |
10 | |
11 HttpCacheLookupManager::LookupTransaction::LookupTransaction( | |
12 std::unique_ptr<ServerPushHelper> server_push_helper) | |
13 : transaction(nullptr) { | |
14 push_helper = std::move(server_push_helper); | |
15 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.
| |
16 request->url = push_helper->GetURL(); | |
17 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
| |
18 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
| |
19 } | |
20 | |
21 HttpCacheLookupManager::LookupTransaction::~LookupTransaction() {} | |
22 | |
23 HttpCacheLookupManager::HttpCacheLookupManager(HttpCache* http_cache, | |
24 const NetLogWithSource& net_log) | |
25 : net_log_(net_log), http_cache_(http_cache), weak_factory_(this) {} | |
26 | |
27 HttpCacheLookupManager::~HttpCacheLookupManager() {} | |
28 | |
29 void HttpCacheLookupManager::OnPush( | |
30 std::unique_ptr<ServerPushHelper> push_helper) { | |
31 GURL pushed_url = push_helper->GetURL(); | |
32 | |
33 // There's a pending lookup transaction sent over already, cancel this one. | |
34 if (lookup_transactions_.find(pushed_url) != lookup_transactions_.end()) | |
35 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
| |
36 | |
37 std::unique_ptr<LookupTransaction> lookup_transaction( | |
38 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.
| |
39 int rv = http_cache_->CreateTransaction(DEFAULT_PRIORITY, | |
40 &lookup_transaction->transaction); | |
41 if (rv != OK) | |
42 return; | |
43 | |
44 HttpTransaction* trans_ptr = lookup_transaction->transaction.get(); | |
45 HttpRequestInfo* request_ptr = lookup_transaction->request.get(); | |
46 | |
47 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
| |
48 | |
49 rv = trans_ptr->Start( | |
50 request_ptr, base::Bind(&HttpCacheLookupManager::OnPushFilteringComplete, | |
51 weak_factory_.GetWeakPtr(), pushed_url), | |
52 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.
| |
53 | |
54 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.
| |
55 lookup_transactions_.erase(pushed_url); | |
56 } | |
57 } | |
58 | |
59 void HttpCacheLookupManager::OnPushFilteringComplete(const GURL& url, int rv) { | |
60 auto it = lookup_transactions_.find(url); | |
61 DCHECK(it != lookup_transactions_.end()); | |
62 | |
63 if (rv == OK) | |
64 it->second->push_helper->Cancel(); | |
65 | |
66 lookup_transactions_.erase(it); | |
67 } | |
68 | |
69 } // namespace net | |
OLD | NEW |