summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-20 11:51:23 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-20 11:51:23 +0000
commitb7779a46dbf7f0201498db0e430a4ecbdd8d2032 (patch)
tree36f16dfeb7b5e4c178c42b93a99a6d2aa2999dcf /chrome
parent0d12ef12d81a4fffda677a1b683597aa8c77d44c (diff)
downloadchromium_src-b7779a46dbf7f0201498db0e430a4ecbdd8d2032.zip
chromium_src-b7779a46dbf7f0201498db0e430a4ecbdd8d2032.tar.gz
chromium_src-b7779a46dbf7f0201498db0e430a4ecbdd8d2032.tar.bz2
Platform cleanup in chrome/browser/net.
Preparing for more complex changes. Review URL: http://codereview.chromium.org/14919 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7344 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/net/dns_global.cc2
-rw-r--r--chrome/browser/net/dns_master.cc23
-rw-r--r--chrome/browser/net/dns_master.h8
-rw-r--r--chrome/browser/net/dns_master_unittest.cc11
-rw-r--r--chrome/browser/net/dns_slave.h8
5 files changed, 23 insertions, 29 deletions
diff --git a/chrome/browser/net/dns_global.cc b/chrome/browser/net/dns_global.cc
index 096af58..1cbf815 100644
--- a/chrome/browser/net/dns_global.cc
+++ b/chrome/browser/net/dns_global.cc
@@ -187,7 +187,7 @@ PrefetchObserver::~PrefetchObserver() {
void PrefetchObserver::OnStartResolution(const std::string& host_name,
void* context) {
- DCHECK_NE(0, host_name.length());
+ DCHECK_NE(0U, host_name.length());
DnsHostInfo navigation_info;
navigation_info.SetHostname(host_name);
navigation_info.SetStartedState();
diff --git a/chrome/browser/net/dns_master.cc b/chrome/browser/net/dns_master.cc
index 29bf139..4d477b0 100644
--- a/chrome/browser/net/dns_master.cc
+++ b/chrome/browser/net/dns_master.cc
@@ -20,12 +20,12 @@ using base::TimeDelta;
namespace chrome_browser_net {
DnsMaster::DnsMaster(TimeDelta shutdown_wait_time)
- : slave_count_(0),
- shutdown_(false),
+ : slaves_have_work_(&lock_),
+ slave_count_(0),
running_slave_count_(0),
- kShutdownWaitTime_(shutdown_wait_time),
- slaves_have_work_(&lock_) {
- for ( int i = 0; i < kSlaveCountMax; i++ ) {
+ shutdown_(false),
+ kShutdownWaitTime_(shutdown_wait_time) {
+ for (size_t i = 0; i < kSlaveCountMax; i++) {
thread_ids_[i] = 0;
thread_handles_[i] = 0;
slaves_[i] = NULL;
@@ -40,8 +40,7 @@ void DnsMaster::ResolveList(const NameList& hostnames,
AutoLock auto_lock(lock_);
if (shutdown_) return;
if (slave_count_ < kSlaveCountMin) {
- for (int target_count = std::min(static_cast<int>(hostnames.size()),
- kSlaveCountMin);
+ for (int target_count = std::min(hostnames.size(), kSlaveCountMin);
target_count > 0;
target_count--)
PreLockedCreateNewSlaveIfNeeded();
@@ -114,7 +113,7 @@ bool DnsMaster::AccruePrefetchBenefits(const GURL& referrer,
// Remain under lock to push data.
cache_hits_.push_back(*navigation_info);
if (referrer_based_prefetch) {
- std::string& motivating_referrer(
+ std::string motivating_referrer(
prefetched_host_info.referring_hostname());
if (!motivating_referrer.empty()) {
referrers_[motivating_referrer].AccrueValue(
@@ -170,12 +169,6 @@ void DnsMaster::NavigatingTo(const std::string& host_name) {
slaves_have_work_.Signal();
}
-static char* PluralOptionalHostname(size_t count) {
- if (count == 1)
- return "hostname";
- return "hostnames";
-}
-
// Provide sort order so all .com's are together, etc.
struct RightToLeftStringSorter {
bool operator()(const std::string& left, const std::string& right) const {
@@ -410,7 +403,7 @@ void DnsMaster::SetNoSuchNameState(const std::string hostname) {
}
bool DnsMaster::PreLockedCreateNewSlaveIfNeeded() {
- // Don't create more then max.
+ // Don't create more than max.
if (kSlaveCountMax <= slave_count_ || shutdown_)
return false;
diff --git a/chrome/browser/net/dns_master.h b/chrome/browser/net/dns_master.h
index 4bc61ee..a606152 100644
--- a/chrome/browser/net/dns_master.h
+++ b/chrome/browser/net/dns_master.h
@@ -38,7 +38,7 @@ typedef std::map<std::string, DnsHostInfo> Results;
class DnsMaster {
public:
// The number of slave processes that will do DNS prefetching
- static const int kSlaveCountMax = 8;
+ static const size_t kSlaveCountMax = 8;
explicit DnsMaster(base::TimeDelta shutdown_wait_time);
@@ -113,7 +113,7 @@ class DnsMaster {
return results_[hostname].queue_duration();
}
- int running_slave_count() {
+ size_t running_slave_count() {
AutoLock auto_lock(lock_);
return running_slave_count_;
}
@@ -171,8 +171,8 @@ class DnsMaster {
// is done using ConditionVariables.
ConditionVariable slaves_have_work_;
- int slave_count_; // Count of slave processes started.
- int running_slave_count_; // Count of slaves process still running.
+ size_t slave_count_; // Count of slave processes started.
+ size_t running_slave_count_; // Count of slaves process still running.
// The following arrays are only initialized as
// slave_count_ grows (up to the indicated max).
diff --git a/chrome/browser/net/dns_master_unittest.cc b/chrome/browser/net/dns_master_unittest.cc
index 228c764..650a8ff 100644
--- a/chrome/browser/net/dns_master_unittest.cc
+++ b/chrome/browser/net/dns_master_unittest.cc
@@ -13,6 +13,7 @@
#include <sstream>
#include <string>
+#include "base/platform_thread.h"
#include "base/spin_wait.h"
#include "chrome/browser/net/dns_global.h"
#include "chrome/browser/net/dns_host_info.h"
@@ -88,7 +89,7 @@ static int __stdcall fake_get_addr_info(const char* nodename,
latency[hostname] = 1;
} // Release lock.
- Sleep(duration);
+ PlatformThread::Sleep(duration);
return was_found ? 0 : WSAHOST_NOT_FOUND;
}
@@ -284,7 +285,7 @@ TEST(DnsMasterTest, DISABLED_SingleSlaveLookupTest) {
EXPECT_FALSE(testing_master.WasFound(bad1));
EXPECT_FALSE(testing_master.WasFound(bad2));
- EXPECT_EQ(1, testing_master.running_slave_count());
+ EXPECT_EQ(1U, testing_master.running_slave_count());
// With just one thread (doing nothing now), ensure a clean shutdown.
EXPECT_TRUE(testing_master.ShutdownSlaves());
@@ -332,7 +333,7 @@ TEST(DnsMasterTest, DISABLED_MultiThreadedLookupTest) {
EXPECT_FALSE(testing_master.WasFound(bad1));
EXPECT_FALSE(testing_master.WasFound(bad2));
- EXPECT_EQ(8, testing_master.running_slave_count());
+ EXPECT_EQ(8U, testing_master.running_slave_count());
EXPECT_TRUE(testing_master.ShutdownSlaves());
}
@@ -378,7 +379,7 @@ TEST(DnsMasterTest, DISABLED_MultiThreadedSpeedupTest) {
EXPECT_FALSE(testing_master.WasFound(goog2));
EXPECT_FALSE(testing_master.WasFound(goog4));
- EXPECT_EQ(1, testing_master.running_slave_count());
+ EXPECT_EQ(1U, testing_master.running_slave_count());
// Get all 8 threads running by calling many times before queue is handled.
names.clear();
@@ -422,7 +423,7 @@ TEST(DnsMasterTest, DISABLED_MultiThreadedSpeedupTest) {
EXPECT_GE(testing_master.GetResolutionDuration(bad2).InMilliseconds(),
testing_master.GetResolutionDuration(goog4).InMilliseconds());
- EXPECT_EQ(8, testing_master.running_slave_count());
+ EXPECT_EQ(8U, testing_master.running_slave_count());
EXPECT_TRUE(testing_master.ShutdownSlaves());
}
diff --git a/chrome/browser/net/dns_slave.h b/chrome/browser/net/dns_slave.h
index 0d77d5e..6bbc17f 100644
--- a/chrome/browser/net/dns_slave.h
+++ b/chrome/browser/net/dns_slave.h
@@ -42,9 +42,9 @@ FreeAddrInfoFunction get_freeaddrinfo();
class DnsSlave {
public:
- DnsSlave(DnsMaster* master, int slave_index)
- : slave_index_(slave_index),
- master_(master) {
+ DnsSlave(DnsMaster* master, size_t slave_index)
+ : master_(master),
+ slave_index_(slave_index) {
}
~DnsSlave() {
@@ -59,7 +59,7 @@ class DnsSlave {
std::string hostname_; // Name being looked up.
DnsMaster* master_; // Master that started us.
- int slave_index_; // Our index into DnsMaster's array.
+ size_t slave_index_; // Our index into DnsMaster's array.
void BlockingDnsLookup();