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

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

Issue 2675343002: Server push cancellation: add NetLogs to track cache lookup transaction (Closed)
Patch Set: fix typo Created 3 years, 10 months 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_cache_lookup_manager.h" 5 #include "net/http/http_cache_lookup_manager.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/values.h"
8 #include "net/base/load_flags.h" 9 #include "net/base/load_flags.h"
9 10
10 namespace net { 11 namespace net {
11 12
13 // Returns parameters associated with the start of a server push lookup
14 // transaction.
15 std::unique_ptr<base::Value> NetLogPushLookupTransactionCallback(
16 const NetLogSource& net_log,
17 const ServerPushDelegate::ServerPushHelper* push_helper,
18 NetLogCaptureMode /* capture_mode */) {
19 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
20 net_log.AddToEventParameters(dict.get());
21 dict->SetString("push_url", push_helper->GetURL().possibly_invalid_spec());
22 return std::move(dict);
23 }
24
12 HttpCacheLookupManager::LookupTransaction::LookupTransaction( 25 HttpCacheLookupManager::LookupTransaction::LookupTransaction(
13 std::unique_ptr<ServerPushHelper> server_push_helper) 26 std::unique_ptr<ServerPushHelper> server_push_helper,
27 NetLog* net_log)
14 : push_helper_(std::move(server_push_helper)), 28 : push_helper_(std::move(server_push_helper)),
15 request_(new HttpRequestInfo()), 29 request_(new HttpRequestInfo()),
16 transaction_(nullptr) {} 30 transaction_(nullptr),
31 net_log_(NetLogWithSource::Make(
32 net_log,
33 NetLogSourceType::SERVER_PUSH_LOOKUP_TRANSACTION)) {}
17 34
18 HttpCacheLookupManager::LookupTransaction::~LookupTransaction() {} 35 HttpCacheLookupManager::LookupTransaction::~LookupTransaction() {}
19 36
20 int HttpCacheLookupManager::LookupTransaction::StartLookup( 37 int HttpCacheLookupManager::LookupTransaction::StartLookup(
21 HttpCache* cache, 38 HttpCache* cache,
22 const CompletionCallback& callback, 39 const CompletionCallback& callback,
23 const NetLogWithSource& net_log) { 40 const NetLogWithSource& session_net_log) {
41 net_log_.BeginEvent(NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION,
42 base::Bind(&NetLogPushLookupTransactionCallback,
43 session_net_log.source(), push_helper_.get()));
44
24 request_->url = push_helper_->GetURL(); 45 request_->url = push_helper_->GetURL();
25 request_->method = "GET"; 46 request_->method = "GET";
26 request_->load_flags = LOAD_ONLY_FROM_CACHE | LOAD_SKIP_CACHE_VALIDATION; 47 request_->load_flags = LOAD_ONLY_FROM_CACHE | LOAD_SKIP_CACHE_VALIDATION;
27 cache->CreateTransaction(DEFAULT_PRIORITY, &transaction_); 48 cache->CreateTransaction(DEFAULT_PRIORITY, &transaction_);
28 return transaction_->Start(request_.get(), callback, net_log); 49 return transaction_->Start(request_.get(), callback, net_log_);
29 } 50 }
30 51
31 void HttpCacheLookupManager::LookupTransaction::CancelPush() { 52 void HttpCacheLookupManager::LookupTransaction::OnLookupComplete(int result) {
32 DCHECK(push_helper_.get()); 53 if (result == OK) {
33 push_helper_->Cancel(); 54 DCHECK(push_helper_.get());
55 push_helper_->Cancel();
56 }
57 net_log_.EndEventWithNetErrorCode(
58 NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION, result);
34 } 59 }
35 60
36 HttpCacheLookupManager::HttpCacheLookupManager(HttpCache* http_cache, 61 HttpCacheLookupManager::HttpCacheLookupManager(HttpCache* http_cache)
37 const NetLogWithSource& net_log) 62 : http_cache_(http_cache), weak_factory_(this) {}
38 : net_log_(net_log), http_cache_(http_cache), weak_factory_(this) {}
39 63
40 HttpCacheLookupManager::~HttpCacheLookupManager() {} 64 HttpCacheLookupManager::~HttpCacheLookupManager() {}
41 65
42 void HttpCacheLookupManager::OnPush( 66 void HttpCacheLookupManager::OnPush(
43 std::unique_ptr<ServerPushHelper> push_helper) { 67 std::unique_ptr<ServerPushHelper> push_helper,
68 const NetLogWithSource& session_net_log) {
44 GURL pushed_url = push_helper->GetURL(); 69 GURL pushed_url = push_helper->GetURL();
45 70
46 // There's a pending lookup transaction sent over already. 71 // There's a pending lookup transaction sent over already.
47 if (base::ContainsKey(lookup_transactions_, pushed_url)) 72 if (base::ContainsKey(lookup_transactions_, pushed_url))
48 return; 73 return;
49 74
50 auto lookup = base::MakeUnique<LookupTransaction>(std::move(push_helper)); 75 auto lookup = base::MakeUnique<LookupTransaction>(std::move(push_helper),
76 session_net_log.net_log());
77 // TODO(zhongyi): add events in session net log to log the creation of
78 // LookupTransaction.
51 79
52 int rv = lookup->StartLookup( 80 int rv = lookup->StartLookup(
53 http_cache_, base::Bind(&HttpCacheLookupManager::OnLookupComplete, 81 http_cache_, base::Bind(&HttpCacheLookupManager::OnLookupComplete,
54 weak_factory_.GetWeakPtr(), pushed_url), 82 weak_factory_.GetWeakPtr(), pushed_url),
55 net_log_); 83 session_net_log);
56 84
57 if (rv == ERR_IO_PENDING) 85 if (rv == ERR_IO_PENDING) {
58 lookup_transactions_[pushed_url] = std::move(lookup); 86 lookup_transactions_[pushed_url] = std::move(lookup);
87 } else {
88 lookup->OnLookupComplete(rv);
89 }
59 } 90 }
60 91
61 void HttpCacheLookupManager::OnLookupComplete(const GURL& url, int rv) { 92 void HttpCacheLookupManager::OnLookupComplete(const GURL& url, int rv) {
62 auto it = lookup_transactions_.find(url); 93 auto it = lookup_transactions_.find(url);
63 DCHECK(it != lookup_transactions_.end()); 94 DCHECK(it != lookup_transactions_.end());
64 95
65 if (rv == OK) 96 it->second->OnLookupComplete(rv);
66 it->second->CancelPush();
67 97
68 lookup_transactions_.erase(it); 98 lookup_transactions_.erase(it);
69 } 99 }
70 100
71 } // namespace net 101 } // 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