Skip to content

Commit

Permalink
NetLogEventParameter to Callback refactoring 7.
Browse files Browse the repository at this point in the history
Get rid of all uses of NetLogEventParameters in net/proxy.

R=eroman@chromium.org
BUG=126243

Review URL: https://chromiumcodereview.appspot.com/10534132

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142222 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
mmenke@chromium.org committed Jun 14, 2012
1 parent bd1ec99 commit ebed34a
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 176 deletions.
9 changes: 3 additions & 6 deletions net/proxy/multi_threaded_proxy_resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,22 +239,19 @@ class MultiThreadedProxyResolver::GetProxyForURLJob

virtual void WaitingForThread() OVERRIDE {
was_waiting_for_thread_ = true;
net_log_.BeginEvent(
NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD, NULL);
net_log_.BeginEvent(NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD);
}

virtual void FinishedWaitingForThread() OVERRIDE {
DCHECK(executor());

if (was_waiting_for_thread_) {
net_log_.EndEvent(
NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD, NULL);
net_log_.EndEvent(NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD);
}

net_log_.AddEvent(
NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD,
make_scoped_refptr(new NetLogIntegerParameter(
"thread_number", executor()->thread_number())));
NetLog::IntegerCallback("thread_number", executor()->thread_number()));
}

// Runs on the worker thread.
Expand Down
2 changes: 1 addition & 1 deletion net/proxy/multi_threaded_proxy_resolver_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MockProxyResolver : public ProxyResolver {
EXPECT_TRUE(request == NULL);

// Write something into |net_log| (doesn't really have any meaning.)
net_log.BeginEvent(NetLog::TYPE_PAC_JAVASCRIPT_DNS_RESOLVE, NULL);
net_log.BeginEvent(NetLog::TYPE_PAC_JAVASCRIPT_DNS_RESOLVE);

results->UseNamedProxy(query_url.host());

Expand Down
6 changes: 3 additions & 3 deletions net/proxy/proxy_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "net/proxy/proxy_list.h"

#include "base/callback.h"
#include "base/logging.h"
#include "base/string_tokenizer.h"
#include "base/time.h"
Expand Down Expand Up @@ -161,9 +162,8 @@ bool ProxyList::Fallback(ProxyRetryInfoMap* proxy_retry_info,
retry_info.bad_until = TimeTicks().Now() + retry_info.current_delay;
(*proxy_retry_info)[key] = retry_info;
}
net_log.AddEvent(
NetLog::TYPE_PROXY_LIST_FALLBACK,
make_scoped_refptr(new NetLogStringParameter("bad_proxy", key)));
net_log.AddEvent(NetLog::TYPE_PROXY_LIST_FALLBACK,
NetLog::StringCallback("bad_proxy", &key));
}

// Remove this proxy from our list.
Expand Down
104 changes: 35 additions & 69 deletions net/proxy/proxy_resolver_js_bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "net/proxy/proxy_resolver_js_bindings.h"

#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/string_util.h"
Expand All @@ -26,51 +27,15 @@ namespace {
// DNS resolutions.
const unsigned kCacheEntryTTLSeconds = 5 * 60;

// Event parameters for a PAC error message (line number + message).
class ErrorNetlogParams : public NetLog::EventParameters {
public:
ErrorNetlogParams(int line_number,
const string16& message)
: line_number_(line_number),
message_(message) {
}

virtual Value* ToValue() const OVERRIDE {
DictionaryValue* dict = new DictionaryValue();
dict->SetInteger("line_number", line_number_);
dict->SetString("message", message_);
return dict;
}

protected:
virtual ~ErrorNetlogParams() {}

private:
const int line_number_;
const string16 message_;

DISALLOW_COPY_AND_ASSIGN(ErrorNetlogParams);
};

// Event parameters for a PAC alert().
class AlertNetlogParams : public NetLog::EventParameters {
public:
explicit AlertNetlogParams(const string16& message) : message_(message) {}

virtual Value* ToValue() const OVERRIDE {
DictionaryValue* dict = new DictionaryValue();
dict->SetString("message", message_);
return dict;
}

protected:
virtual ~AlertNetlogParams() {}

private:
const string16 message_;

DISALLOW_COPY_AND_ASSIGN(AlertNetlogParams);
};
// Returns event parameters for a PAC error message (line number + message).
Value* NetLogErrorCallback(int line_number,
const string16* message,
NetLog::LogLevel /* log_level */) {
DictionaryValue* dict = new DictionaryValue();
dict->SetInteger("line_number", line_number);
dict->SetString("message", *message);
return dict;
}

// ProxyResolverJSBindings implementation.
class DefaultJSBindings : public ProxyResolverJSBindings {
Expand All @@ -88,67 +53,60 @@ class DefaultJSBindings : public ProxyResolverJSBindings {
VLOG(1) << "PAC-alert: " << message;

// Send to the NetLog.
LogEventToCurrentRequestAndGlobally(NetLog::TYPE_PAC_JAVASCRIPT_ALERT,
new AlertNetlogParams(message));
LogEventToCurrentRequestAndGlobally(
NetLog::TYPE_PAC_JAVASCRIPT_ALERT,
NetLog::StringCallback("message", &message));
}

// Handler for "myIpAddress()".
// TODO(eroman): Perhaps enumerate the interfaces directly, using
// getifaddrs().
virtual bool MyIpAddress(std::string* first_ip_address) OVERRIDE {
LogEventToCurrentRequest(NetLog::PHASE_BEGIN,
NetLog::TYPE_PAC_JAVASCRIPT_MY_IP_ADDRESS,
NULL);
NetLog::TYPE_PAC_JAVASCRIPT_MY_IP_ADDRESS);

bool ok = MyIpAddressImpl(first_ip_address);

LogEventToCurrentRequest(NetLog::PHASE_END,
NetLog::TYPE_PAC_JAVASCRIPT_MY_IP_ADDRESS,
NULL);
NetLog::TYPE_PAC_JAVASCRIPT_MY_IP_ADDRESS);
return ok;
}

// Handler for "myIpAddressEx()".
virtual bool MyIpAddressEx(std::string* ip_address_list) OVERRIDE {
LogEventToCurrentRequest(NetLog::PHASE_BEGIN,
NetLog::TYPE_PAC_JAVASCRIPT_MY_IP_ADDRESS_EX,
NULL);
NetLog::TYPE_PAC_JAVASCRIPT_MY_IP_ADDRESS_EX);

bool ok = MyIpAddressExImpl(ip_address_list);

LogEventToCurrentRequest(NetLog::PHASE_END,
NetLog::TYPE_PAC_JAVASCRIPT_MY_IP_ADDRESS_EX,
NULL);
NetLog::TYPE_PAC_JAVASCRIPT_MY_IP_ADDRESS_EX);
return ok;
}

// Handler for "dnsResolve(host)".
virtual bool DnsResolve(const std::string& host,
std::string* first_ip_address) OVERRIDE {
LogEventToCurrentRequest(NetLog::PHASE_BEGIN,
NetLog::TYPE_PAC_JAVASCRIPT_DNS_RESOLVE,
NULL);
NetLog::TYPE_PAC_JAVASCRIPT_DNS_RESOLVE);

bool ok = DnsResolveImpl(host, first_ip_address);

LogEventToCurrentRequest(NetLog::PHASE_END,
NetLog::TYPE_PAC_JAVASCRIPT_DNS_RESOLVE,
NULL);
NetLog::TYPE_PAC_JAVASCRIPT_DNS_RESOLVE);
return ok;
}

// Handler for "dnsResolveEx(host)".
virtual bool DnsResolveEx(const std::string& host,
std::string* ip_address_list) OVERRIDE {
LogEventToCurrentRequest(NetLog::PHASE_BEGIN,
NetLog::TYPE_PAC_JAVASCRIPT_DNS_RESOLVE_EX,
NULL);
NetLog::TYPE_PAC_JAVASCRIPT_DNS_RESOLVE_EX);

bool ok = DnsResolveExImpl(host, ip_address_list);

LogEventToCurrentRequest(NetLog::PHASE_END,
NetLog::TYPE_PAC_JAVASCRIPT_DNS_RESOLVE_EX,
NULL);
NetLog::TYPE_PAC_JAVASCRIPT_DNS_RESOLVE_EX);
return ok;
}

Expand All @@ -163,7 +121,7 @@ class DefaultJSBindings : public ProxyResolverJSBindings {
// Send the error to the NetLog.
LogEventToCurrentRequestAndGlobally(
NetLog::TYPE_PAC_JAVASCRIPT_ERROR,
new ErrorNetlogParams(line_number, message));
base::Bind(&NetLogErrorCallback, line_number, &message));

if (error_observer_.get())
error_observer_->OnPACScriptError(line_number, message);
Expand Down Expand Up @@ -287,23 +245,31 @@ class DefaultJSBindings : public ProxyResolverJSBindings {
return current_request_context()->net_log;
}

void LogEventToCurrentRequest(
NetLog::EventPhase phase,
NetLog::EventType type) {
const BoundNetLog* net_log = GetNetLogForCurrentRequest();
if (net_log)
net_log->AddEntry(type, phase);
}

void LogEventToCurrentRequest(
NetLog::EventPhase phase,
NetLog::EventType type,
scoped_refptr<NetLog::EventParameters> params) {
const NetLog::ParametersCallback& parameters_callback) {
const BoundNetLog* net_log = GetNetLogForCurrentRequest();
if (net_log)
net_log->AddEntry(type, phase, params);
net_log->AddEntry(type, phase, parameters_callback);
}

void LogEventToCurrentRequestAndGlobally(
NetLog::EventType type,
scoped_refptr<NetLog::EventParameters> params) {
LogEventToCurrentRequest(NetLog::PHASE_NONE, type, params);
const NetLog::ParametersCallback& parameters_callback) {
LogEventToCurrentRequest(NetLog::PHASE_NONE, type, parameters_callback);

// Emit to the global NetLog event stream.
if (net_log_)
net_log_->AddGlobalEntry(type, params);
net_log_->AddGlobalEntry(type, parameters_callback);
}

scoped_ptr<SyncHostResolver> host_resolver_;
Expand Down
Loading

0 comments on commit ebed34a

Please sign in to comment.