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

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: address eroman's comments 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
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().spec());
eroman 2017/02/10 23:57:47 [optional] Consider using |possibly_invalid_spec()
Zhongyi Shi 2017/02/11 02:21:10 Done.
22 return std::move(dict);
23 }
24
25 std::unique_ptr<base::Value> NetLogServerPushLookupCompleteCallback(
eroman 2017/02/10 23:57:47 [optional] You can remove this function and use Ne
Zhongyi Shi 2017/02/11 02:21:10 Done.
26 bool found_in_cache,
27 NetLogCaptureMode /* capture_mode */) {
28 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
29 dict->SetBoolean("found_in_cache", found_in_cache);
30 return std::move(dict);
31 }
32
12 HttpCacheLookupManager::LookupTransaction::LookupTransaction( 33 HttpCacheLookupManager::LookupTransaction::LookupTransaction(
13 std::unique_ptr<ServerPushHelper> server_push_helper) 34 std::unique_ptr<ServerPushHelper> server_push_helper,
35 NetLog* net_log)
14 : push_helper_(std::move(server_push_helper)), 36 : push_helper_(std::move(server_push_helper)),
15 request_(new HttpRequestInfo()), 37 request_(new HttpRequestInfo()),
16 transaction_(nullptr) {} 38 transaction_(nullptr),
39 net_log_(NetLogWithSource::Make(
40 net_log,
41 NetLogSourceType::SERVER_PUSH_LOOKUP_TRANSACTION)) {}
17 42
18 HttpCacheLookupManager::LookupTransaction::~LookupTransaction() {} 43 HttpCacheLookupManager::LookupTransaction::~LookupTransaction() {}
19 44
20 int HttpCacheLookupManager::LookupTransaction::StartLookup( 45 int HttpCacheLookupManager::LookupTransaction::StartLookup(
21 HttpCache* cache, 46 HttpCache* cache,
22 const CompletionCallback& callback, 47 const CompletionCallback& callback,
23 const NetLogWithSource& net_log) { 48 const NetLogWithSource& source_net_log) {
49 net_log_.BeginEvent(NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION,
50 base::Bind(&NetLogPushLookupTransactionCallback,
51 source_net_log.source(), push_helper_.get()));
52
24 request_->url = push_helper_->GetURL(); 53 request_->url = push_helper_->GetURL();
25 request_->method = "GET"; 54 request_->method = "GET";
26 request_->load_flags = LOAD_ONLY_FROM_CACHE | LOAD_SKIP_CACHE_VALIDATION; 55 request_->load_flags = LOAD_ONLY_FROM_CACHE | LOAD_SKIP_CACHE_VALIDATION;
27 cache->CreateTransaction(DEFAULT_PRIORITY, &transaction_); 56 cache->CreateTransaction(DEFAULT_PRIORITY, &transaction_);
28 return transaction_->Start(request_.get(), callback, net_log); 57 return transaction_->Start(request_.get(), callback, net_log_);
29 } 58 }
30 59
31 void HttpCacheLookupManager::LookupTransaction::CancelPush() { 60 void HttpCacheLookupManager::LookupTransaction::OnLookupComplete(
32 DCHECK(push_helper_.get()); 61 bool found_in_cache) {
33 push_helper_->Cancel(); 62 net_log_.AddEvent(
63 NetLogEventType::SERVER_PUSH_LOOKUP_COMPLETE,
eroman 2017/02/10 23:57:47 Seems like we can remove this event, and instead p
Zhongyi Shi 2017/02/11 02:21:10 Thanks for the pointer, this greatly simplified th
64 base::Bind(&NetLogServerPushLookupCompleteCallback, found_in_cache));
65 if (found_in_cache) {
66 DCHECK(push_helper_.get());
67 push_helper_->Cancel();
68 }
69 net_log_.EndEvent(NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION);
34 } 70 }
35 71
36 HttpCacheLookupManager::HttpCacheLookupManager(HttpCache* http_cache, 72 HttpCacheLookupManager::HttpCacheLookupManager(HttpCache* http_cache,
37 const NetLogWithSource& net_log) 73 NetLog* net_log)
38 : net_log_(net_log), http_cache_(http_cache), weak_factory_(this) {} 74 : net_log_(net_log), http_cache_(http_cache), weak_factory_(this) {}
39 75
40 HttpCacheLookupManager::~HttpCacheLookupManager() {} 76 HttpCacheLookupManager::~HttpCacheLookupManager() {}
41 77
42 void HttpCacheLookupManager::OnPush( 78 void HttpCacheLookupManager::OnPush(
43 std::unique_ptr<ServerPushHelper> push_helper) { 79 std::unique_ptr<ServerPushHelper> push_helper,
80 const NetLogWithSource& source_net_log) {
44 GURL pushed_url = push_helper->GetURL(); 81 GURL pushed_url = push_helper->GetURL();
45 82
46 // There's a pending lookup transaction sent over already. 83 // There's a pending lookup transaction sent over already.
47 if (base::ContainsKey(lookup_transactions_, pushed_url)) 84 if (base::ContainsKey(lookup_transactions_, pushed_url))
48 return; 85 return;
49 86
50 auto lookup = base::MakeUnique<LookupTransaction>(std::move(push_helper)); 87 auto lookup =
88 base::MakeUnique<LookupTransaction>(std::move(push_helper), net_log_);
eroman 2017/02/10 23:57:47 [optional] It is also common practice to add a bre
Zhongyi Shi 2017/02/11 02:21:10 Yup, I did plan to add this in a follow-up CL afte
51 89
52 int rv = lookup->StartLookup( 90 int rv = lookup->StartLookup(
53 http_cache_, base::Bind(&HttpCacheLookupManager::OnLookupComplete, 91 http_cache_, base::Bind(&HttpCacheLookupManager::OnLookupComplete,
54 weak_factory_.GetWeakPtr(), pushed_url), 92 weak_factory_.GetWeakPtr(), pushed_url),
55 net_log_); 93 source_net_log);
56 94
57 if (rv == ERR_IO_PENDING) 95 if (rv == ERR_IO_PENDING) {
58 lookup_transactions_[pushed_url] = std::move(lookup); 96 lookup_transactions_[pushed_url] = std::move(lookup);
97 } else {
98 lookup->OnLookupComplete(rv == OK);
eroman 2017/02/10 23:57:47 [optional] Have you considered making the paramete
Zhongyi Shi 2017/02/11 02:21:10 Done.
99 }
59 } 100 }
60 101
61 void HttpCacheLookupManager::OnLookupComplete(const GURL& url, int rv) { 102 void HttpCacheLookupManager::OnLookupComplete(const GURL& url, int rv) {
62 auto it = lookup_transactions_.find(url); 103 auto it = lookup_transactions_.find(url);
63 DCHECK(it != lookup_transactions_.end()); 104 DCHECK(it != lookup_transactions_.end());
64 105
65 if (rv == OK) 106 it->second->OnLookupComplete(rv == OK);
66 it->second->CancelPush();
67 107
68 lookup_transactions_.erase(it); 108 lookup_transactions_.erase(it);
69 } 109 }
70 110
71 } // namespace net 111 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698