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; |
| 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 (lookup_transactions_.find(pushed_url) != lookup_transactions_.end()) |
| 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 |
| 61 void HttpCacheLookupManager::OnLookupComplete(const GURL& url, int rv) { |
| 62 auto it = lookup_transactions_.find(url); |
| 63 DCHECK(it != lookup_transactions_.end()); |
| 64 |
| 65 if (rv == OK) |
| 66 it->second->CancelPush(); |
| 67 |
| 68 lookup_transactions_.erase(it); |
| 69 } |
| 70 |
| 71 } // namespace net |
OLD | NEW |