diff options
author | mmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-13 22:03:42 +0000 |
---|---|---|
committer | mmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-13 22:03:42 +0000 |
commit | 55b8a6c1bbdd2e2523c1204105348657325f86b7 (patch) | |
tree | f45cc52aa5033f763322225671d92814eecd64db | |
parent | 632864601350d88399859df6ab877c844c018d38 (diff) | |
download | chromium_src-55b8a6c1bbdd2e2523c1204105348657325f86b7.zip chromium_src-55b8a6c1bbdd2e2523c1204105348657325f86b7.tar.gz chromium_src-55b8a6c1bbdd2e2523c1204105348657325f86b7.tar.bz2 |
NetLogEventParameter to Callback refactoring 6.
Get rid of all uses of NetLogEventParameters in net/url_request.
R=eroman@chromium.org
BUG=126243
Review URL: https://chromiumcodereview.appspot.com/10532121
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141981 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | net/url_request/url_request.cc | 21 | ||||
-rw-r--r-- | net/url_request/url_request_http_job.cc | 16 | ||||
-rw-r--r-- | net/url_request/url_request_job.cc | 8 | ||||
-rw-r--r-- | net/url_request/url_request_throttler_entry.cc | 44 | ||||
-rw-r--r-- | net/url_request/url_request_throttler_manager.cc | 10 |
5 files changed, 40 insertions, 59 deletions
diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc index efc83c9..33cb827 100644 --- a/net/url_request/url_request.cc +++ b/net/url_request/url_request.cc @@ -422,8 +422,9 @@ void URLRequest::BeforeRequestComplete(int error) { SetUnblockedOnDelegate(); if (error != OK) { + std::string source("delegate"); net_log_.AddEvent(NetLog::TYPE_CANCELLED, - make_scoped_refptr(new NetLogStringParameter("source", "delegate"))); + NetLog::StringCallback("source", &source)); StartJob(new URLRequestErrorJob(this, error)); } else if (!delegate_redirect_url_.is_empty()) { GURL new_url; @@ -566,10 +567,11 @@ void URLRequest::NotifyReceivedRedirect(const GURL& location, } void URLRequest::NotifyResponseStarted() { - scoped_refptr<NetLog::EventParameters> params; + int net_error = OK; if (!status_.is_success()) - params = new NetLogIntegerParameter("net_error", status_.error()); - net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_START_JOB, params); + net_error = status_.error(); + net_log_.EndEventWithNetErrorCode(NetLog::TYPE_URL_REQUEST_START_JOB, + net_error); URLRequestJob* job = URLRequestJobManager::GetInstance()->MaybeInterceptResponse(this); @@ -633,7 +635,7 @@ void URLRequest::PrepareToRestart() { // Close the current URL_REQUEST_START_JOB, since we will be starting a new // one. - net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_START_JOB, NULL); + net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_START_JOB); OrphanJob(); @@ -661,8 +663,7 @@ int URLRequest::Redirect(const GURL& location, int http_status_code) { if (net_log_.IsLoggingAllEvents()) { net_log_.AddEvent( NetLog::TYPE_URL_REQUEST_REDIRECTED, - make_scoped_refptr(new NetLogStringParameter( - "location", location.possibly_invalid_spec()))); + NetLog::StringCallback("location", &location.possibly_invalid_spec())); } if (context_ && context_->network_delegate()) @@ -757,7 +758,7 @@ void URLRequest::set_context(const URLRequestContext* context) { if (context) { net_log_ = BoundNetLog::Make(context->net_log(), NetLog::SOURCE_URL_REQUEST); - net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE, NULL); + net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE); } } } @@ -906,7 +907,7 @@ void URLRequest::NotifyRequestCompleted() { void URLRequest::SetBlockedOnDelegate() { blocked_on_delegate_ = true; - net_log_.BeginEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); + net_log_.BeginEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE); } void URLRequest::SetUnblockedOnDelegate() { @@ -914,7 +915,7 @@ void URLRequest::SetUnblockedOnDelegate() { return; blocked_on_delegate_ = false; load_state_param_.clear(); - net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); + net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE); } void URLRequest::set_stack_trace(const base::debug::StackTrace& stack_trace) { diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc index 8491594..d393677 100644 --- a/net/url_request/url_request_http_job.cc +++ b/net/url_request/url_request_http_job.cc @@ -278,8 +278,9 @@ void URLRequestHttpJob::NotifyBeforeSendHeadersCallback(int result) { if (result == OK) { StartTransactionInternal(); } else { + std::string source("delegate"); request_->net_log().AddEvent(NetLog::TYPE_CANCELLED, - make_scoped_refptr(new NetLogStringParameter("source", "delegate"))); + NetLog::StringCallback("source", &source)); NotifyCanceled(); } } @@ -475,8 +476,9 @@ void URLRequestHttpJob::DoStartTransaction() { void URLRequestHttpJob::SaveCookiesAndNotifyHeadersComplete(int result) { if (result != net::OK) { + std::string source("delegate"); request_->net_log().AddEvent(NetLog::TYPE_CANCELLED, - make_scoped_refptr(new NetLogStringParameter("source", "delegate"))); + NetLog::StringCallback("source", &source)); NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); return; } @@ -678,11 +680,12 @@ void URLRequestHttpJob::OnStartCompleted(int result) { if (error == net::ERR_IO_PENDING) { awaiting_callback_ = true; request_->net_log().BeginEvent( - NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); + NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE); } else { + std::string source("delegate"); request_->net_log().AddEvent(NetLog::TYPE_CANCELLED, - make_scoped_refptr( - new NetLogStringParameter("source", "delegate"))); + NetLog::StringCallback("source", + &source)); NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, error)); } return; @@ -712,8 +715,7 @@ void URLRequestHttpJob::OnStartCompleted(int result) { } void URLRequestHttpJob::OnHeadersReceivedCallback(int result) { - request_->net_log().EndEvent( - NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); + request_->net_log().EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE); awaiting_callback_ = false; // Check that there are no callbacks to already canceled requests. diff --git a/net/url_request/url_request_job.cc b/net/url_request/url_request_job.cc index b384ace..255e90d 100644 --- a/net/url_request/url_request_job.cc +++ b/net/url_request/url_request_job.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -412,10 +412,8 @@ void URLRequestJob::NotifyDone(const URLRequestStatus &status) { // successful. if (request_->status().is_success()) { if (status.status() == URLRequestStatus::FAILED) { - request_->net_log().AddEvent( - NetLog::TYPE_FAILED, - make_scoped_refptr(new NetLogIntegerParameter("net_error", - status.error()))); + request_->net_log().AddEventWithNetErrorCode(NetLog::TYPE_FAILED, + status.error()); } request_->set_status(status); } diff --git a/net/url_request/url_request_throttler_entry.cc b/net/url_request/url_request_throttler_entry.cc index b0f519d..a3c1840 100644 --- a/net/url_request/url_request_throttler_entry.cc +++ b/net/url_request/url_request_throttler_entry.cc @@ -51,33 +51,17 @@ const char URLRequestThrottlerEntry::kExponentialThrottlingHeader[] = const char URLRequestThrottlerEntry::kExponentialThrottlingDisableValue[] = "disable"; -// NetLog parameters when a request is rejected by throttling. -class RejectedRequestParameters : public NetLog::EventParameters { - public: - RejectedRequestParameters(const std::string& url_id, - int num_failures, - int release_after_ms) - : url_id_(url_id), - num_failures_(num_failures), - release_after_ms_(release_after_ms) { - } - - virtual Value* ToValue() const { - DictionaryValue* dict = new DictionaryValue(); - dict->SetString("url", url_id_); - dict->SetInteger("num_failures", num_failures_); - dict->SetInteger("release_after_ms", release_after_ms_); - return dict; - } - - protected: - virtual ~RejectedRequestParameters() {} - - private: - std::string url_id_; - int num_failures_; - int release_after_ms_; -}; +// Returns NetLog parameters when a request is rejected by throttling. +Value* NetLogRejectedRequestCallback(const std::string* url_id, + int num_failures, + int release_after_ms, + NetLog::LogLevel /* log_level */) { + DictionaryValue* dict = new DictionaryValue(); + dict->SetString("url", *url_id); + dict->SetInteger("num_failures", num_failures); + dict->SetInteger("release_after_ms", release_after_ms); + return dict; +} URLRequestThrottlerEntry::URLRequestThrottlerEntry( URLRequestThrottlerManager* manager, @@ -178,10 +162,8 @@ bool URLRequestThrottlerEntry::ShouldRejectRequest( net_log_.AddEvent( NetLog::TYPE_THROTTLING_REJECTED_REQUEST, - make_scoped_refptr( - new RejectedRequestParameters(url_id_, - num_failures, - release_after_ms))); + base::Bind(&NetLogRejectedRequestCallback, + &url_id_, num_failures, release_after_ms)); reject_request = true; } diff --git a/net/url_request/url_request_throttler_manager.cc b/net/url_request/url_request_throttler_manager.cc index 6d26510..fa04a00 100644 --- a/net/url_request/url_request_throttler_manager.cc +++ b/net/url_request/url_request_throttler_manager.cc @@ -83,9 +83,8 @@ scoped_refptr<URLRequestThrottlerEntryInterface> IsLocalhost(host)) { if (!logged_for_localhost_disabled_ && IsLocalhost(host)) { logged_for_localhost_disabled_ = true; - net_log_.AddEvent( - NetLog::TYPE_THROTTLING_DISABLED_FOR_HOST, - make_scoped_refptr(new NetLogStringParameter("host", host))); + net_log_.AddEvent(NetLog::TYPE_THROTTLING_DISABLED_FOR_HOST, + NetLog::StringCallback("host", &host)); } // TODO(joi): Once sliding window is separate from back-off throttling, @@ -108,9 +107,8 @@ void URLRequestThrottlerManager::AddToOptOutList(const std::string& host) { if (opt_out_hosts_.find(host) == opt_out_hosts_.end()) { UMA_HISTOGRAM_COUNTS("Throttling.SiteOptedOut", 1); - net_log_.EndEvent( - NetLog::TYPE_THROTTLING_DISABLED_FOR_HOST, - make_scoped_refptr(new NetLogStringParameter("host", host))); + net_log_.EndEvent(NetLog::TYPE_THROTTLING_DISABLED_FOR_HOST, + NetLog::StringCallback("host", &host)); opt_out_hosts_.insert(host); } } |