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 request->url = push_helper->GetURL(); | |
17 request->method = "GET"; | |
18 request->load_flags = LOAD_ONLY_FROM_CACHE | LOAD_SKIP_CACHE_VALIDATION; | |
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. | |
34 if (lookup_transactions_.find(pushed_url) != lookup_transactions_.end()) | |
35 return; | |
36 | |
37 auto lookup = base::MakeUnique<LookupTransaction>(std::move(push_helper)); | |
38 | |
39 int rv = | |
40 http_cache_->CreateTransaction(DEFAULT_PRIORITY, &lookup->transaction); | |
41 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
| |
42 return; | |
43 | |
44 rv = lookup->transaction->Start( | |
45 lookup->request.get(), | |
46 base::Bind(&HttpCacheLookupManager::OnPushFilteringComplete, | |
47 weak_factory_.GetWeakPtr(), pushed_url), | |
48 net_log_); | |
49 | |
50 if (rv == ERR_IO_PENDING) { | |
51 lookup_transactions_[pushed_url] = std::move(lookup); | |
52 } | |
53 } | |
54 | |
55 void HttpCacheLookupManager::OnPushFilteringComplete(const GURL& url, int rv) { | |
56 auto it = lookup_transactions_.find(url); | |
57 DCHECK(it != lookup_transactions_.end()); | |
58 | |
59 if (rv == OK) | |
60 it->second->push_helper->Cancel(); | |
61 | |
62 lookup_transactions_.erase(it); | |
63 } | |
64 | |
65 } // namespace net | |
OLD | NEW |