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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: net/http/http_cache_lookup_manager.cc
diff --git a/net/http/http_cache_lookup_manager.cc b/net/http/http_cache_lookup_manager.cc
index d4d8a2e023e2de5a99a0a548d4a3187959a0c7b7..b48be1a07fe68af04a2335d19cb05664a96bc47a 100644
--- a/net/http/http_cache_lookup_manager.cc
+++ b/net/http/http_cache_lookup_manager.cc
@@ -5,65 +5,105 @@
#include "net/http/http_cache_lookup_manager.h"
#include "base/memory/ptr_util.h"
+#include "base/values.h"
#include "net/base/load_flags.h"
namespace net {
+// Returns parameters associated with the start of a server push lookup
+// transaction.
+std::unique_ptr<base::Value> NetLogPushLookupTransactionCallback(
+ const NetLogSource& net_log,
+ const ServerPushDelegate::ServerPushHelper* push_helper,
+ NetLogCaptureMode /* capture_mode */) {
+ std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
+ net_log.AddToEventParameters(dict.get());
+ 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.
+ return std::move(dict);
+}
+
+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.
+ bool found_in_cache,
+ NetLogCaptureMode /* capture_mode */) {
+ std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
+ dict->SetBoolean("found_in_cache", found_in_cache);
+ return std::move(dict);
+}
+
HttpCacheLookupManager::LookupTransaction::LookupTransaction(
- std::unique_ptr<ServerPushHelper> server_push_helper)
+ std::unique_ptr<ServerPushHelper> server_push_helper,
+ NetLog* net_log)
: push_helper_(std::move(server_push_helper)),
request_(new HttpRequestInfo()),
- transaction_(nullptr) {}
+ transaction_(nullptr),
+ net_log_(NetLogWithSource::Make(
+ net_log,
+ NetLogSourceType::SERVER_PUSH_LOOKUP_TRANSACTION)) {}
HttpCacheLookupManager::LookupTransaction::~LookupTransaction() {}
int HttpCacheLookupManager::LookupTransaction::StartLookup(
HttpCache* cache,
const CompletionCallback& callback,
- const NetLogWithSource& net_log) {
+ const NetLogWithSource& source_net_log) {
+ net_log_.BeginEvent(NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION,
+ base::Bind(&NetLogPushLookupTransactionCallback,
+ source_net_log.source(), push_helper_.get()));
+
request_->url = push_helper_->GetURL();
request_->method = "GET";
request_->load_flags = LOAD_ONLY_FROM_CACHE | LOAD_SKIP_CACHE_VALIDATION;
cache->CreateTransaction(DEFAULT_PRIORITY, &transaction_);
- return transaction_->Start(request_.get(), callback, net_log);
+ return transaction_->Start(request_.get(), callback, net_log_);
}
-void HttpCacheLookupManager::LookupTransaction::CancelPush() {
- DCHECK(push_helper_.get());
- push_helper_->Cancel();
+void HttpCacheLookupManager::LookupTransaction::OnLookupComplete(
+ bool found_in_cache) {
+ net_log_.AddEvent(
+ 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
+ base::Bind(&NetLogServerPushLookupCompleteCallback, found_in_cache));
+ if (found_in_cache) {
+ DCHECK(push_helper_.get());
+ push_helper_->Cancel();
+ }
+ net_log_.EndEvent(NetLogEventType::SERVER_PUSH_LOOKUP_TRANSACTION);
}
HttpCacheLookupManager::HttpCacheLookupManager(HttpCache* http_cache,
- const NetLogWithSource& net_log)
+ NetLog* net_log)
: net_log_(net_log), http_cache_(http_cache), weak_factory_(this) {}
HttpCacheLookupManager::~HttpCacheLookupManager() {}
void HttpCacheLookupManager::OnPush(
- std::unique_ptr<ServerPushHelper> push_helper) {
+ std::unique_ptr<ServerPushHelper> push_helper,
+ const NetLogWithSource& source_net_log) {
GURL pushed_url = push_helper->GetURL();
// There's a pending lookup transaction sent over already.
if (base::ContainsKey(lookup_transactions_, pushed_url))
return;
- auto lookup = base::MakeUnique<LookupTransaction>(std::move(push_helper));
+ auto lookup =
+ 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
int rv = lookup->StartLookup(
http_cache_, base::Bind(&HttpCacheLookupManager::OnLookupComplete,
weak_factory_.GetWeakPtr(), pushed_url),
- net_log_);
+ source_net_log);
- if (rv == ERR_IO_PENDING)
+ if (rv == ERR_IO_PENDING) {
lookup_transactions_[pushed_url] = std::move(lookup);
+ } else {
+ 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.
+ }
}
void HttpCacheLookupManager::OnLookupComplete(const GURL& url, int rv) {
auto it = lookup_transactions_.find(url);
DCHECK(it != lookup_transactions_.end());
- if (rv == OK)
- it->second->CancelPush();
+ it->second->OnLookupComplete(rv == OK);
lookup_transactions_.erase(it);
}

Powered by Google App Engine
This is Rietveld 408576698