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

Unified Diff: net/base/dns_query.cc

Issue 7276014: DnsQuery: changed raw function pointer to callback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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
Index: net/base/dns_query.cc
diff --git a/net/base/dns_query.cc b/net/base/dns_query.cc
index 7ccf32a336a3f6cd6ddbf595ed6c62f7179d6ac7..a92a3904cd87cc195c3aefca24e391abdae78557 100644
--- a/net/base/dns_query.cc
+++ b/net/base/dns_query.cc
@@ -5,6 +5,7 @@
#include "net/base/dns_query.h"
#include <string>
+#include <limits>
#include "base/rand_util.h"
#include "net/base/dns_util.h"
@@ -35,9 +36,11 @@ static const char kHeader[] = {0x00, 0x00, 0x01, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const size_t kHeaderSize = arraysize(kHeader);
-DnsQuery::DnsQuery(const std::string& dns_name, uint16 qtype, uint64 (*prng)())
+DnsQuery::DnsQuery(const std::string& dns_name,
+ uint16 qtype,
+ const base::RandIntCallback& rand_int)
: dns_name_size_(dns_name.size()),
- prng_(prng) {
+ rand_int_(rand_int) {
DCHECK(DnsResponseBuffer(reinterpret_cast<const uint8*>(dns_name.c_str()),
dns_name.size()).DNSName(NULL));
DCHECK(qtype == kDNS_A || qtype == kDNS_AAAA);
@@ -58,7 +61,7 @@ DnsQuery::DnsQuery(const std::string& dns_name, uint16 qtype, uint64 (*prng)())
DnsQuery::DnsQuery(const DnsQuery& rhs)
: dns_name_size_(rhs.dns_name_size_),
- prng_(rhs.prng_) {
+ rand_int_(rhs.rand_int_) {
io_buffer_ = new IOBufferWithSize(rhs.io_buffer()->size());
memcpy(io_buffer_->data(), rhs.io_buffer()->data(), rhs.io_buffer()->size());
RandomizeId();
@@ -90,7 +93,9 @@ const char* DnsQuery::question_data() const {
}
void DnsQuery::RandomizeId() {
- PackUint16BE(&io_buffer_->data()[0], (*prng_)() & 0xffff);
+ int min = std::numeric_limits<uint16>::min();
+ int max = std::numeric_limits<uint16>::max();
+ PackUint16BE(&io_buffer_->data()[0], rand_int_.Run(min, max));
}
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698