Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(576)

Side by Side Diff: net/http/http_cache_lookup_manager.cc

Issue 2503473004: Server push cancellation: add a new class HttpCacheLookupManager which implements ServerPushDelegate (Closed)
Patch Set: Merge branch 'master' of https://chromium.googlesource.com/chromium/src into SPC_CacheLookupDelegate Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_cache_lookup_manager.h ('k') | net/http/http_cache_lookup_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 (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
OLDNEW
« no previous file with comments | « net/http/http_cache_lookup_manager.h ('k') | net/http/http_cache_lookup_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698