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 : push_helper(std::move(server_push_helper)), | |
14 request(new HttpRequestInfo()), | |
15 transaction(nullptr) {} | |
16 | |
17 HttpCacheLookupManager::LookupTransaction::~LookupTransaction() {} | |
18 | |
19 int HttpCacheLookupManager::LookupTransaction::StartLookup( | |
20 HttpCache* cache, | |
21 const CompletionCallback& callback, | |
22 const NetLogWithSource& net_log) { | |
23 request->url = push_helper->GetURL(); | |
24 request->method = "GET"; | |
25 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
| |
26 cache->CreateTransaction(DEFAULT_PRIORITY, &transaction); | |
27 return transaction->Start(request.get(), callback, net_log); | |
28 } | |
29 | |
30 void HttpCacheLookupManager::LookupTransaction::CancelPush() { | |
31 DCHECK(push_helper.get()); | |
32 push_helper->Cancel(); | |
33 } | |
34 | |
35 HttpCacheLookupManager::HttpCacheLookupManager(HttpCache* http_cache, | |
36 const NetLogWithSource& net_log) | |
37 : net_log_(net_log), http_cache_(http_cache), weak_factory_(this) {} | |
38 | |
39 HttpCacheLookupManager::~HttpCacheLookupManager() {} | |
40 | |
41 void HttpCacheLookupManager::OnPush( | |
42 std::unique_ptr<ServerPushHelper> push_helper) { | |
43 GURL pushed_url = push_helper->GetURL(); | |
44 | |
45 // There's a pending lookup transaction sent over already. | |
46 if (base::ContainsKey(lookup_transactions_, pushed_url)) | |
47 return; | |
48 | |
49 auto lookup = base::MakeUnique<LookupTransaction>(std::move(push_helper)); | |
50 | |
51 int rv = lookup->StartLookup( | |
52 http_cache_, base::Bind(&HttpCacheLookupManager::OnLookupComplete, | |
53 weak_factory_.GetWeakPtr(), pushed_url), | |
54 net_log_); | |
55 | |
56 if (rv == ERR_IO_PENDING) | |
57 lookup_transactions_[pushed_url] = std::move(lookup); | |
58 } | |
59 | |
60 void HttpCacheLookupManager::OnLookupComplete(const GURL& url, int rv) { | |
61 auto it = lookup_transactions_.find(url); | |
62 DCHECK(it != lookup_transactions_.end()); | |
63 | |
64 if (rv == OK) | |
65 it->second->CancelPush(); | |
66 | |
67 lookup_transactions_.erase(it); | |
68 } | |
69 | |
70 } // namespace net | |
OLD | NEW |