Chromium Code Reviews| OLD | NEW |
|---|---|
| 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& source, | |
| 17 std::string push_url, | |
| 18 NetLogCaptureMode /* capture_mode */) { | |
| 19 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | |
| 20 if (source.IsValid()) | |
| 21 source.AddToEventParameters(dict.get()); | |
| 22 dict->SetString("push_url", push_url); | |
| 23 return std::move(dict); | |
| 24 } | |
| 25 | |
| 12 HttpCacheLookupManager::LookupTransaction::LookupTransaction( | 26 HttpCacheLookupManager::LookupTransaction::LookupTransaction( |
| 13 std::unique_ptr<ServerPushHelper> server_push_helper) | 27 std::unique_ptr<ServerPushHelper> server_push_helper, |
| 28 NetLog* net_log) | |
| 14 : push_helper_(std::move(server_push_helper)), | 29 : push_helper_(std::move(server_push_helper)), |
| 15 request_(new HttpRequestInfo()), | 30 request_(new HttpRequestInfo()), |
| 16 transaction_(nullptr) {} | 31 transaction_(nullptr), |
| 32 net_log_( | |
| 33 NetLogWithSource::Make(net_log, | |
| 34 NetLogSourceType::PUSH_LOOKUP_TRANSACTION)) {} | |
| 17 | 35 |
| 18 HttpCacheLookupManager::LookupTransaction::~LookupTransaction() {} | 36 HttpCacheLookupManager::LookupTransaction::~LookupTransaction() { |
| 37 net_log_.EndEvent(NetLogEventType::PUSH_LOOKUP_TRANSACTION); | |
| 38 } | |
| 19 | 39 |
| 20 int HttpCacheLookupManager::LookupTransaction::StartLookup( | 40 int HttpCacheLookupManager::LookupTransaction::StartLookup( |
| 21 HttpCache* cache, | 41 HttpCache* cache, |
| 22 const CompletionCallback& callback, | 42 const CompletionCallback& callback, |
| 23 const NetLogWithSource& net_log) { | 43 const NetLogWithSource& source) { |
| 44 net_log_.BeginEvent( | |
| 45 NetLogEventType::PUSH_LOOKUP_TRANSACTION, | |
| 46 base::Bind(&NetLogPushLookupTransactionCallback, source.source(), | |
| 47 push_helper_->GetURL().spec())); | |
| 48 | |
| 24 request_->url = push_helper_->GetURL(); | 49 request_->url = push_helper_->GetURL(); |
| 25 request_->method = "GET"; | 50 request_->method = "GET"; |
| 26 request_->load_flags = LOAD_ONLY_FROM_CACHE | LOAD_SKIP_CACHE_VALIDATION; | 51 request_->load_flags = LOAD_ONLY_FROM_CACHE | LOAD_SKIP_CACHE_VALIDATION; |
| 27 cache->CreateTransaction(DEFAULT_PRIORITY, &transaction_); | 52 cache->CreateTransaction(DEFAULT_PRIORITY, &transaction_); |
| 28 return transaction_->Start(request_.get(), callback, net_log); | 53 return transaction_->Start(request_.get(), callback, net_log_); |
| 29 } | 54 } |
| 30 | 55 |
| 31 void HttpCacheLookupManager::LookupTransaction::CancelPush() { | 56 void HttpCacheLookupManager::LookupTransaction::CancelPush() { |
| 57 net_log_.AddEvent(NetLogEventType::PUSH_FOUND_IN_CACHE); | |
|
Ryan Hamilton
2017/02/06 23:34:55
I realize that CancelPush() is called from OnLooku
Zhongyi Shi
2017/02/07 00:00:24
Well, in this CL, each push lookup transaction wil
Ryan Hamilton
2017/02/07 00:10:49
Oh, I see. I missed that CancelPush and OnLookupCo
Zhongyi Shi
2017/02/07 06:01:08
That's a good idea! Done. Now we should always log
| |
| 32 DCHECK(push_helper_.get()); | 58 DCHECK(push_helper_.get()); |
| 33 push_helper_->Cancel(); | 59 push_helper_->Cancel(); |
| 34 } | 60 } |
| 35 | 61 |
| 36 HttpCacheLookupManager::HttpCacheLookupManager(HttpCache* http_cache, | 62 HttpCacheLookupManager::HttpCacheLookupManager(HttpCache* http_cache, |
| 37 const NetLogWithSource& net_log) | 63 NetLog* net_log) |
| 38 : net_log_(net_log), http_cache_(http_cache), weak_factory_(this) {} | 64 : net_log_(net_log), http_cache_(http_cache), weak_factory_(this) {} |
| 39 | 65 |
| 40 HttpCacheLookupManager::~HttpCacheLookupManager() {} | 66 HttpCacheLookupManager::~HttpCacheLookupManager() {} |
| 41 | 67 |
| 42 void HttpCacheLookupManager::OnPush( | 68 void HttpCacheLookupManager::OnPush( |
| 43 std::unique_ptr<ServerPushHelper> push_helper) { | 69 std::unique_ptr<ServerPushHelper> push_helper, |
| 70 const NetLogWithSource& source) { | |
| 44 GURL pushed_url = push_helper->GetURL(); | 71 GURL pushed_url = push_helper->GetURL(); |
| 45 | 72 |
| 46 // There's a pending lookup transaction sent over already. | 73 // There's a pending lookup transaction sent over already. |
| 47 if (base::ContainsKey(lookup_transactions_, pushed_url)) | 74 if (base::ContainsKey(lookup_transactions_, pushed_url)) |
| 48 return; | 75 return; |
| 49 | 76 |
| 50 auto lookup = base::MakeUnique<LookupTransaction>(std::move(push_helper)); | 77 auto lookup = |
| 78 base::MakeUnique<LookupTransaction>(std::move(push_helper), net_log_); | |
| 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 source); |
| 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); |
| 59 } | 87 } |
| 60 | 88 |
| 61 void HttpCacheLookupManager::OnLookupComplete(const GURL& url, int rv) { | 89 void HttpCacheLookupManager::OnLookupComplete(const GURL& url, int rv) { |
| 62 auto it = lookup_transactions_.find(url); | 90 auto it = lookup_transactions_.find(url); |
| 63 DCHECK(it != lookup_transactions_.end()); | 91 DCHECK(it != lookup_transactions_.end()); |
| 64 | 92 |
| 65 if (rv == OK) | 93 if (rv == OK) |
| 66 it->second->CancelPush(); | 94 it->second->CancelPush(); |
| 67 | 95 |
| 68 lookup_transactions_.erase(it); | 96 lookup_transactions_.erase(it); |
| 69 } | 97 } |
| 70 | 98 |
| 71 } // namespace net | 99 } // namespace net |
| OLD | NEW |