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

Unified Diff: net/dns/dns_transaction.cc

Issue 10546133: NetLogEventParameter to Callback refactoring 4. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Sync? Created 8 years, 6 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
« no previous file with comments | « no previous file | net/net.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/dns_transaction.cc
===================================================================
--- net/dns/dns_transaction.cc (revision 141995)
+++ net/dns/dns_transaction.cc (working copy)
@@ -50,49 +50,15 @@
return ParseIPLiteralToNumber(hostname, &ip);
}
-class StartParameters : public NetLog::EventParameters {
- public:
- StartParameters(const std::string& hostname,
- uint16 qtype)
- : hostname_(hostname), qtype_(qtype) {}
-
- virtual Value* ToValue() const OVERRIDE {
- DictionaryValue* dict = new DictionaryValue();
- dict->SetString("hostname", hostname_);
- dict->SetInteger("query_type", qtype_);
- return dict;
- }
-
- protected:
- virtual ~StartParameters() {}
-
- private:
- const std::string hostname_;
- const uint16 qtype_;
+Value* NetLogStartCallback(const std::string* hostname,
+ uint16 qtype,
+ NetLog::LogLevel /* log_level */) {
+ DictionaryValue* dict = new DictionaryValue();
+ dict->SetString("hostname", *hostname);
+ dict->SetInteger("query_type", qtype);
+ return dict;
};
-class ResponseParameters : public NetLog::EventParameters {
- public:
- ResponseParameters(int rcode, int answer_count, const NetLog::Source& source)
- : rcode_(rcode), answer_count_(answer_count), source_(source) {}
-
- virtual Value* ToValue() const OVERRIDE {
- DictionaryValue* dict = new DictionaryValue();
- dict->SetInteger("rcode", rcode_);
- dict->SetInteger("answer_count", answer_count_);
- dict->Set("source_dependency", source_.ToValue());
- return dict;
- }
-
- protected:
- virtual ~ResponseParameters() {}
-
- private:
- const int rcode_;
- const int answer_count_;
- const NetLog::Source source_;
-};
-
// ----------------------------------------------------------------------------
// A single asynchronous DNS exchange over UDP, which consists of sending out a
@@ -134,6 +100,19 @@
return (resp != NULL && resp->IsValid()) ? resp : NULL;
}
+ // Returns a Value representing the received response, along with a reference
+ // to the NetLog source source of the UDP socket used. The request must have
+ // completed before this is called.
+ Value* NetLogResponseCallback(NetLog::LogLevel /* log_level */) const {
+ DCHECK(response_->IsValid());
+
+ DictionaryValue* dict = new DictionaryValue();
+ dict->SetInteger("rcode", response_->rcode());
+ dict->SetInteger("answer_count", response_->answer_count());
+ socket_->NetLog().source().AddToEventParameters(dict);
+ return dict;
+ }
+
private:
enum State {
STATE_CONNECT,
@@ -304,8 +283,8 @@
virtual int Start() OVERRIDE {
DCHECK(!callback_.is_null());
DCHECK(attempts_.empty());
- net_log_.BeginEvent(NetLog::TYPE_DNS_TRANSACTION, make_scoped_refptr(
- new StartParameters(hostname_, qtype_)));
+ net_log_.BeginEvent(NetLog::TYPE_DNS_TRANSACTION,
+ base::Bind(&NetLogStartCallback, &hostname_, qtype_));
int rv = PrepareSearch();
if (rv == OK) {
AttemptResult result = FinishAttempt(StartQuery());
@@ -428,9 +407,8 @@
query.reset(attempts_[0]->query()->CloneWithNewId(id));
}
- net_log_.AddEvent(NetLog::TYPE_DNS_TRANSACTION_ATTEMPT, make_scoped_refptr(
- new NetLogSourceParameter("source_dependency",
- socket->NetLog().source())));
+ net_log_.AddEvent(NetLog::TYPE_DNS_TRANSACTION_ATTEMPT,
+ socket->NetLog().source().ToEventParametersCallback());
const DnsConfig& config = session_->config();
@@ -459,9 +437,8 @@
// Begins query for the current name. Makes the first attempt.
AttemptResult StartQuery() {
std::string dotted_qname = DNSDomainToString(qnames_.front());
- net_log_.BeginEvent(
- NetLog::TYPE_DNS_TRANSACTION_QUERY,
- make_scoped_refptr(new NetLogStringParameter("qname", dotted_qname)));
+ net_log_.BeginEvent(NetLog::TYPE_DNS_TRANSACTION_QUERY,
+ NetLog::StringCallback("qname", &dotted_qname));
first_server_index_ = session_->NextFirstServerIndex();
@@ -483,10 +460,8 @@
if (attempt && attempt->response()) {
net_log_.AddEvent(
NetLog::TYPE_DNS_TRANSACTION_RESPONSE,
- make_scoped_refptr(
- new ResponseParameters(attempt->response()->rcode(),
- attempt->response()->answer_count(),
- attempt->socket()->NetLog().source())));
+ base::Bind(&DnsUDPAttempt::NetLogResponseCallback,
+ base::Unretained(attempt)));
}
}
« no previous file with comments | « no previous file | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698