Chromium Code Reviews| Index: net/proxy/proxy_resolver_js_bindings.cc |
| =================================================================== |
| --- net/proxy/proxy_resolver_js_bindings.cc (revision 141814) |
| +++ net/proxy/proxy_resolver_js_bindings.cc (working copy) |
| @@ -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" |
| @@ -26,52 +27,24 @@ |
| // 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) { |
| - } |
| +// 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; |
| +} |
| - virtual Value* ToValue() const OVERRIDE { |
| - DictionaryValue* dict = new DictionaryValue(); |
| - dict->SetInteger("line_number", line_number_); |
| - dict->SetString("message", message_); |
| - return dict; |
| - } |
| +// Returns event parameters for a PAC alert(). |
| +Value* NetLogAlertCallback(const string16* message, |
| + NetLog::LogLevel /* log_level */) { |
| + DictionaryValue* dict = new DictionaryValue(); |
| + 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); |
| -}; |
| - |
| // ProxyResolverJSBindings implementation. |
| class DefaultJSBindings : public ProxyResolverJSBindings { |
| public: |
| @@ -88,8 +61,9 @@ |
| VLOG(1) << "PAC-alert: " << message; |
| // Send to the NetLog. |
| - LogEventToCurrentRequestAndGlobally(NetLog::TYPE_PAC_JAVASCRIPT_ALERT, |
| - new AlertNetlogParams(message)); |
| + LogEventToCurrentRequestAndGlobally( |
| + NetLog::TYPE_PAC_JAVASCRIPT_ALERT, |
| + base::Bind(&NetLogAlertCallback, &message)); |
|
eroman
2012/06/13 18:55:33
Perhaps this can just use a generic NetLogString16
mmenke
2012/06/13 20:27:58
Done.
|
| } |
| // Handler for "myIpAddress()". |
| @@ -97,28 +71,24 @@ |
| // 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; |
| } |
| @@ -126,14 +96,12 @@ |
| 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; |
| } |
| @@ -141,14 +109,12 @@ |
| 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; |
| } |
| @@ -163,7 +129,7 @@ |
| // 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); |
| @@ -289,21 +255,29 @@ |
| 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_; |