summaryrefslogtreecommitdiffstats
path: root/net/proxy
diff options
context:
space:
mode:
Diffstat (limited to 'net/proxy')
-rw-r--r--net/proxy/dhcp_proxy_script_adapter_fetcher_win_unittest.cc4
-rw-r--r--net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc6
-rw-r--r--net/proxy/multi_threaded_proxy_resolver_unittest.cc17
-rw-r--r--net/proxy/proxy_script_fetcher_impl.cc4
-rw-r--r--net/proxy/proxy_service.cc76
-rw-r--r--net/proxy/proxy_service.h16
-rw-r--r--net/proxy/proxy_service_unittest.cc53
7 files changed, 88 insertions, 88 deletions
diff --git a/net/proxy/dhcp_proxy_script_adapter_fetcher_win_unittest.cc b/net/proxy/dhcp_proxy_script_adapter_fetcher_win_unittest.cc
index ff75fbe..f8f2f94 100644
--- a/net/proxy/dhcp_proxy_script_adapter_fetcher_win_unittest.cc
+++ b/net/proxy/dhcp_proxy_script_adapter_fetcher_win_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -220,7 +220,7 @@ TEST(DhcpProxyScriptAdapterFetcher, CancelWhileFetcher) {
client.RunTest();
int max_loops = 4;
while (!client.fetcher_->IsWaitingForFetcher() && max_loops--) {
- base::PlatformThread::Sleep(10);
+ base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10));
MessageLoop::current()->RunAllPending();
}
client.fetcher_->Cancel();
diff --git a/net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc b/net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc
index 97a6d8e..bc1700b 100644
--- a/net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc
+++ b/net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -111,7 +111,7 @@ class RealFetchTester {
// do something a bit more clever to track worker threads even when the
// DhcpProxyScriptFetcherWin state machine has finished.
void FinishTestAllowCleanup() {
- base::PlatformThread::Sleep(30);
+ base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(30));
}
scoped_refptr<URLRequestContext> context_;
@@ -169,7 +169,7 @@ class DelayingDhcpProxyScriptAdapterFetcher
std::string ImplGetPacURLFromDhcp(
const std::string& adapter_name) OVERRIDE {
- base::PlatformThread::Sleep(20);
+ base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20));
return DhcpQuery::ImplGetPacURLFromDhcp(adapter_name);
}
};
diff --git a/net/proxy/multi_threaded_proxy_resolver_unittest.cc b/net/proxy/multi_threaded_proxy_resolver_unittest.cc
index 59c33f4..a1a4ad6 100644
--- a/net/proxy/multi_threaded_proxy_resolver_unittest.cc
+++ b/net/proxy/multi_threaded_proxy_resolver_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -32,8 +32,7 @@ class MockProxyResolver : public ProxyResolver {
: ProxyResolver(true /*expects_pac_bytes*/),
wrong_loop_(MessageLoop::current()),
request_count_(0),
- purge_count_(0),
- resolve_latency_ms_(0) {}
+ purge_count_(0) {}
// ProxyResolver implementation.
virtual int GetProxyForURL(const GURL& query_url,
@@ -41,8 +40,8 @@ class MockProxyResolver : public ProxyResolver {
const CompletionCallback& callback,
RequestHandle* request,
const BoundNetLog& net_log) OVERRIDE {
- if (resolve_latency_ms_)
- base::PlatformThread::Sleep(resolve_latency_ms_);
+ if (resolve_latency_ != base::TimeDelta())
+ base::PlatformThread::Sleep(resolve_latency_);
CheckIsOnWorkerThread();
@@ -97,8 +96,8 @@ class MockProxyResolver : public ProxyResolver {
return last_script_data_;
}
- void SetResolveLatency(int latency_ms) {
- resolve_latency_ms_ = latency_ms;
+ void SetResolveLatency(base::TimeDelta latency) {
+ resolve_latency_ = latency;
}
private:
@@ -114,7 +113,7 @@ class MockProxyResolver : public ProxyResolver {
int request_count_;
int purge_count_;
scoped_refptr<ProxyResolverScriptData> last_script_data_;
- int resolve_latency_ms_;
+ base::TimeDelta resolve_latency_;
};
@@ -566,7 +565,7 @@ TEST(MultiThreadedProxyResolverTest, SingleThread_CancelRequestByDeleting) {
// of the worker thread. The test will pass regardless, so this race doesn't
// cause flakiness. However the destruction during execution is a more
// interesting case to test.
- mock->SetResolveLatency(100);
+ mock->SetResolveLatency(base::TimeDelta::FromMilliseconds(100));
// Unblock the worker thread and delete the underlying
// MultiThreadedProxyResolver immediately.
diff --git a/net/proxy/proxy_script_fetcher_impl.cc b/net/proxy/proxy_script_fetcher_impl.cc
index def3382..32f6542 100644
--- a/net/proxy/proxy_script_fetcher_impl.cc
+++ b/net/proxy/proxy_script_fetcher_impl.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -162,7 +162,7 @@ int ProxyScriptFetcherImpl::Fetch(
FROM_HERE,
base::Bind(&ProxyScriptFetcherImpl::OnTimeout, weak_factory_.GetWeakPtr(),
cur_request_id_),
- static_cast<int>(max_duration_.InMilliseconds()));
+ max_duration_);
// Start the request.
cur_request_->Start();
diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc
index ba567c6..a18805b 100644
--- a/net/proxy/proxy_service.cc
+++ b/net/proxy/proxy_service.cc
@@ -119,32 +119,34 @@ class DefaultPollPolicy : public ProxyService::PacPollPolicy {
DefaultPollPolicy() {}
virtual Mode GetNextDelay(int initial_error,
- int64 current_delay_ms,
- int64* next_delay_ms) const OVERRIDE {
+ TimeDelta current_delay,
+ TimeDelta* next_delay) const OVERRIDE {
if (initial_error != OK) {
// Re-try policy for failures.
- const int kDelay1 = 8000; // 8 seconds
- const int kDelay2 = 32000; // 32 seconds
- const int kDelay3 = 120000; // 2 minutes
- const int kDelay4 = 14400000; // 4 hours
-
- switch (current_delay_ms) {
- case -1: // Initial poll.
- *next_delay_ms = kDelay1;
- return MODE_USE_TIMER;
- case kDelay1:
- *next_delay_ms = kDelay2;
+ const int kDelay1Seconds = 8;
+ const int kDelay2Seconds = 32;
+ const int kDelay3Seconds = 2 * 60; // 2 minutes
+ const int kDelay4Seconds = 4 * 60 * 60; // 4 Hours
+
+ // Initial poll.
+ if (current_delay < TimeDelta()) {
+ *next_delay = TimeDelta::FromSeconds(kDelay1Seconds);
+ return MODE_USE_TIMER;
+ }
+ switch (current_delay.InSeconds()) {
+ case kDelay1Seconds:
+ *next_delay = TimeDelta::FromSeconds(kDelay2Seconds);
return MODE_START_AFTER_ACTIVITY;
- case kDelay2:
- *next_delay_ms = kDelay3;
+ case kDelay2Seconds:
+ *next_delay = TimeDelta::FromSeconds(kDelay3Seconds);
return MODE_START_AFTER_ACTIVITY;
default:
- *next_delay_ms = kDelay4;
+ *next_delay = TimeDelta::FromSeconds(kDelay4Seconds);
return MODE_START_AFTER_ACTIVITY;
}
} else {
// Re-try policy for succeses.
- *next_delay_ms = 43200000; // 12 hours
+ *next_delay = TimeDelta::FromHours(12);
return MODE_START_AFTER_ACTIVITY;
}
}
@@ -412,7 +414,7 @@ class ProxyService::InitProxyResolver {
DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher,
NetLog* net_log,
const ProxyConfig& config,
- base::TimeDelta wait_delay,
+ TimeDelta wait_delay,
const CompletionCallback& callback) {
DCHECK_EQ(STATE_NONE, next_state_);
proxy_resolver_ = proxy_resolver;
@@ -549,7 +551,7 @@ class ProxyService::InitProxyResolver {
ProxyConfig config_;
ProxyConfig effective_config_;
scoped_refptr<ProxyResolverScriptData> script_data_;
- base::TimeDelta wait_delay_;
+ TimeDelta wait_delay_;
scoped_ptr<ProxyScriptDecider> decider_;
ProxyResolver* proxy_resolver_;
CompletionCallback callback_;
@@ -605,10 +607,10 @@ class ProxyService::ProxyScriptDeciderPoller {
dhcp_proxy_script_fetcher_(dhcp_proxy_script_fetcher),
last_error_(init_net_error),
last_script_data_(init_script_data),
- last_poll_time_(base::TimeTicks::Now()) {
+ last_poll_time_(TimeTicks::Now()) {
// Set the initial poll delay.
next_poll_mode_ = poll_policy()->GetNextDelay(
- last_error_, -1, &next_poll_delay_ms_);
+ last_error_, TimeDelta::FromSeconds(-1), &next_poll_delay_);
TryToStartNextPoll(false);
}
@@ -640,7 +642,7 @@ class ProxyService::ProxyScriptDeciderPoller {
FROM_HERE,
base::Bind(&ProxyScriptDeciderPoller::DoPoll,
weak_factory_.GetWeakPtr()),
- next_poll_delay_ms_);
+ next_poll_delay_);
}
void TryToStartNextPoll(bool triggered_by_activity) {
@@ -652,9 +654,8 @@ class ProxyService::ProxyScriptDeciderPoller {
case PacPollPolicy::MODE_START_AFTER_ACTIVITY:
if (triggered_by_activity && !decider_.get()) {
- base::TimeDelta elapsed_time =
- base::TimeTicks::Now() - last_poll_time_;
- if (elapsed_time.InMilliseconds() >= next_poll_delay_ms_)
+ TimeDelta elapsed_time = TimeTicks::Now() - last_poll_time_;
+ if (elapsed_time >= next_poll_delay_)
DoPoll();
}
break;
@@ -662,14 +663,14 @@ class ProxyService::ProxyScriptDeciderPoller {
}
void DoPoll() {
- last_poll_time_ = base::TimeTicks::Now();
+ last_poll_time_ = TimeTicks::Now();
// Start the proxy script decider to see if anything has changed.
// TODO(eroman): Pass a proper NetLog rather than NULL.
decider_.reset(new ProxyScriptDecider(
proxy_script_fetcher_, dhcp_proxy_script_fetcher_, NULL));
int result = decider_->Start(
- config_, base::TimeDelta(), proxy_resolver_expects_pac_bytes_,
+ config_, TimeDelta(), proxy_resolver_expects_pac_bytes_,
base::Bind(&ProxyScriptDeciderPoller::OnProxyScriptDeciderCompleted,
base::Unretained(this)));
@@ -700,7 +701,7 @@ class ProxyService::ProxyScriptDeciderPoller {
// Decide when the next poll should take place, and possibly start the
// next timer.
next_poll_mode_ = poll_policy()->GetNextDelay(
- last_error_, next_poll_delay_ms_, &next_poll_delay_ms_);
+ last_error_, next_poll_delay_, &next_poll_delay_);
TryToStartNextPoll(false);
}
@@ -744,10 +745,10 @@ class ProxyService::ProxyScriptDeciderPoller {
scoped_refptr<ProxyResolverScriptData> last_script_data_;
scoped_ptr<ProxyScriptDecider> decider_;
- int64 next_poll_delay_ms_;
+ TimeDelta next_poll_delay_;
PacPollPolicy::Mode next_poll_mode_;
- base::TimeTicks last_poll_time_;
+ TimeTicks last_poll_time_;
// Polling policy injected by unit-tests. Otherwise this is NULL and the
// default policy will be used.
@@ -902,9 +903,8 @@ ProxyService::ProxyService(ProxyConfigService* config_service,
next_config_id_(1),
current_state_(STATE_NONE) ,
net_log_(net_log),
- stall_proxy_auto_config_delay_(
- base::TimeDelta::FromMilliseconds(
- kDelayAfterNetworkChangesMs)) {
+ stall_proxy_auto_config_delay_(TimeDelta::FromMilliseconds(
+ kDelayAfterNetworkChangesMs)) {
NetworkChangeNotifier::AddIPAddressObserver(this);
ResetConfigService(config_service);
}
@@ -1266,7 +1266,7 @@ void ProxyService::ReportSuccess(const ProxyInfo& result) {
}
if (net_log_) {
net_log_->AddEntry(NetLog::TYPE_BAD_PROXY_LIST_REPORTED,
- base::TimeTicks::Now(),
+ TimeTicks::Now(),
NetLog::Source(),
NetLog::PHASE_NONE,
make_scoped_refptr(
@@ -1474,7 +1474,7 @@ void ProxyService::OnProxyConfigChanged(
scoped_refptr<NetLog::EventParameters> params(
new ProxyConfigChangedNetLogParam(fetched_config_, effective_config));
net_log_->AddEntry(net::NetLog::TYPE_PROXY_CONFIG_CHANGED,
- base::TimeTicks::Now(),
+ TimeTicks::Now(),
NetLog::Source(),
NetLog::PHASE_NONE,
params);
@@ -1505,8 +1505,8 @@ void ProxyService::InitializeUsingLastFetchedConfig() {
current_state_ = STATE_WAITING_FOR_INIT_PROXY_RESOLVER;
// If we changed networks recently, we should delay running proxy auto-config.
- base::TimeDelta wait_delay =
- stall_proxy_autoconfig_until_ - base::TimeTicks::Now();
+ TimeDelta wait_delay =
+ stall_proxy_autoconfig_until_ - TimeTicks::Now();
init_proxy_resolver_.reset(new InitProxyResolver());
int rv = init_proxy_resolver_->Start(
@@ -1550,7 +1550,7 @@ void ProxyService::InitializeUsingDecidedConfig(
void ProxyService::OnIPAddressChanged() {
// See the comment block by |kDelayAfterNetworkChangesMs| for info.
stall_proxy_autoconfig_until_ =
- base::TimeTicks::Now() + stall_proxy_auto_config_delay_;
+ TimeTicks::Now() + stall_proxy_auto_config_delay_;
State previous_state = ResetProxyConfig(false);
if (previous_state != STATE_NONE)
diff --git a/net/proxy/proxy_service.h b/net/proxy/proxy_service.h
index 8b657a9..ac32408 100644
--- a/net/proxy/proxy_service.h
+++ b/net/proxy/proxy_service.h
@@ -73,15 +73,15 @@ class NET_EXPORT ProxyService : public NetworkChangeNotifier::IPAddressObserver,
virtual ~PacPollPolicy() {}
- // Decides the next poll delay. |current_delay_ms| is the delay used
- // by the preceding poll, or -1 if determining the delay for the initial
- // poll. |initial_error| is the network error code that the last PAC
- // fetch (or WPAD initialization) failed with, or OK if it completed
- // successfully. Implementations must set |next_delay_ms| to a non-negative
- // value.
+ // Decides the next poll delay. |current_delay| is the delay used
+ // by the preceding poll, or a negative TimeDelta value if determining
+ // the delay for the initial poll. |initial_error| is the network error
+ // code that the last PAC fetch (or WPAD initialization) failed with,
+ // or OK if it completed successfully. Implementations must set
+ // |next_delay| to a non-negative value.
virtual Mode GetNextDelay(int initial_error,
- int64 current_delay_ms,
- int64* next_delay_ms) const = 0;
+ base::TimeDelta current_delay,
+ base::TimeDelta* next_delay) const = 0;
};
// The instance takes ownership of |config_service| and |resolver|.
diff --git a/net/proxy/proxy_service_unittest.cc b/net/proxy/proxy_service_unittest.cc
index 2df1725..6271809 100644
--- a/net/proxy/proxy_service_unittest.cc
+++ b/net/proxy/proxy_service_unittest.cc
@@ -33,9 +33,9 @@ class ImmediatePollPolicy : public ProxyService::PacPollPolicy {
public:
ImmediatePollPolicy() {}
- virtual Mode GetNextDelay(int error, int64 current_delay_ms,
- int64* next_delay_ms) const OVERRIDE {
- *next_delay_ms = 1;
+ virtual Mode GetNextDelay(int error, base::TimeDelta current_delay,
+ base::TimeDelta* next_delay) const OVERRIDE {
+ *next_delay = base::TimeDelta::FromMilliseconds(1);
return MODE_USE_TIMER;
}
@@ -49,9 +49,9 @@ class NeverPollPolicy : public ProxyService::PacPollPolicy {
public:
NeverPollPolicy() {}
- virtual Mode GetNextDelay(int error, int64 current_delay_ms,
- int64* next_delay_ms) const OVERRIDE {
- *next_delay_ms = 0xFFFFFFFF; // Big number of milliseconds!
+ virtual Mode GetNextDelay(int error, base::TimeDelta current_delay,
+ base::TimeDelta* next_delay) const OVERRIDE {
+ *next_delay = base::TimeDelta::FromDays(60);
return MODE_USE_TIMER;
}
@@ -64,9 +64,9 @@ class ImmediateAfterActivityPollPolicy : public ProxyService::PacPollPolicy {
public:
ImmediateAfterActivityPollPolicy() {}
- virtual Mode GetNextDelay(int error, int64 current_delay_ms,
- int64* next_delay_ms) const OVERRIDE {
- *next_delay_ms = 0;
+ virtual Mode GetNextDelay(int error, base::TimeDelta current_delay,
+ base::TimeDelta* next_delay) const OVERRIDE {
+ *next_delay = base::TimeDelta();
return MODE_START_AFTER_ACTIVITY;
}
@@ -2428,7 +2428,8 @@ TEST_F(ProxyServiceTest, PACScriptPollingPolicy) {
int error;
ProxyService::PacPollPolicy::Mode mode;
- int64 delay_ms = -1;
+ const base::TimeDelta initial_delay = base::TimeDelta::FromMilliseconds(-1);
+ base::TimeDelta delay = initial_delay;
// --------------------------------------------------
// Test the poll sequence in response to a failure.
@@ -2436,28 +2437,28 @@ TEST_F(ProxyServiceTest, PACScriptPollingPolicy) {
error = ERR_NAME_NOT_RESOLVED;
// Poll #0
- mode = policy->GetNextDelay(error, -1, &delay_ms);
- EXPECT_EQ(8000, delay_ms);
+ mode = policy->GetNextDelay(error, initial_delay, &delay);
+ EXPECT_EQ(8, delay.InSeconds());
EXPECT_EQ(ProxyService::PacPollPolicy::MODE_USE_TIMER, mode);
// Poll #1
- mode = policy->GetNextDelay(error, delay_ms, &delay_ms);
- EXPECT_EQ(32000, delay_ms);
+ mode = policy->GetNextDelay(error, delay, &delay);
+ EXPECT_EQ(32, delay.InSeconds());
EXPECT_EQ(ProxyService::PacPollPolicy::MODE_START_AFTER_ACTIVITY, mode);
// Poll #2
- mode = policy->GetNextDelay(error, delay_ms, &delay_ms);
- EXPECT_EQ(120000, delay_ms);
+ mode = policy->GetNextDelay(error, delay, &delay);
+ EXPECT_EQ(120, delay.InSeconds());
EXPECT_EQ(ProxyService::PacPollPolicy::MODE_START_AFTER_ACTIVITY, mode);
// Poll #3
- mode = policy->GetNextDelay(error, delay_ms, &delay_ms);
- EXPECT_EQ(14400000, delay_ms);
+ mode = policy->GetNextDelay(error, delay, &delay);
+ EXPECT_EQ(14400, delay.InSeconds());
EXPECT_EQ(ProxyService::PacPollPolicy::MODE_START_AFTER_ACTIVITY, mode);
// Poll #4
- mode = policy->GetNextDelay(error, delay_ms, &delay_ms);
- EXPECT_EQ(14400000, delay_ms);
+ mode = policy->GetNextDelay(error, delay, &delay);
+ EXPECT_EQ(14400, delay.InSeconds());
EXPECT_EQ(ProxyService::PacPollPolicy::MODE_START_AFTER_ACTIVITY, mode);
// --------------------------------------------------
@@ -2466,18 +2467,18 @@ TEST_F(ProxyServiceTest, PACScriptPollingPolicy) {
error = OK;
// Poll #0
- mode = policy->GetNextDelay(error, -1, &delay_ms);
- EXPECT_EQ(43200000, delay_ms);
+ mode = policy->GetNextDelay(error, initial_delay, &delay);
+ EXPECT_EQ(43200, delay.InSeconds());
EXPECT_EQ(ProxyService::PacPollPolicy::MODE_START_AFTER_ACTIVITY, mode);
// Poll #1
- mode = policy->GetNextDelay(error, delay_ms, &delay_ms);
- EXPECT_EQ(43200000, delay_ms);
+ mode = policy->GetNextDelay(error, delay, &delay);
+ EXPECT_EQ(43200, delay.InSeconds());
EXPECT_EQ(ProxyService::PacPollPolicy::MODE_START_AFTER_ACTIVITY, mode);
// Poll #2
- mode = policy->GetNextDelay(error, delay_ms, &delay_ms);
- EXPECT_EQ(43200000, delay_ms);
+ mode = policy->GetNextDelay(error, delay, &delay);
+ EXPECT_EQ(43200, delay.InSeconds());
EXPECT_EQ(ProxyService::PacPollPolicy::MODE_START_AFTER_ACTIVITY, mode);
}