Commit 163d9b29 authored by szym@chromium.org's avatar szym@chromium.org

[net/dns] Suppress multiple DnsConfig withdrawals after timeout.

BUG=132110
TEST=net_unittests --gtest_filter=DnsConfigServiceTest.Timeout


Review URL: https://chromiumcodereview.appspot.com/10537106

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141715 0039d316-1c4b-4281-b951-d872f2087c98
parent aa5b7e5a
...@@ -75,7 +75,8 @@ base::Value* DnsConfig::ToValue() const { ...@@ -75,7 +75,8 @@ base::Value* DnsConfig::ToValue() const {
DnsConfigService::DnsConfigService() DnsConfigService::DnsConfigService()
: have_config_(false), : have_config_(false),
have_hosts_(false), have_hosts_(false),
need_update_(false) {} need_update_(false),
last_sent_empty_(true) {}
DnsConfigService::~DnsConfigService() { DnsConfigService::~DnsConfigService() {
// Must always clean up. // Must always clean up.
...@@ -146,6 +147,10 @@ void DnsConfigService::OnHostsRead(const DnsHosts& hosts) { ...@@ -146,6 +147,10 @@ void DnsConfigService::OnHostsRead(const DnsHosts& hosts) {
void DnsConfigService::StartTimer() { void DnsConfigService::StartTimer() {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
if (last_sent_empty_) {
DCHECK(!timer_.IsRunning());
return; // No need to withdraw again.
}
timer_.Stop(); timer_.Stop();
// Give it a short timeout to come up with a valid config. Otherwise withdraw // Give it a short timeout to come up with a valid config. Otherwise withdraw
...@@ -167,19 +172,22 @@ void DnsConfigService::StartTimer() { ...@@ -167,19 +172,22 @@ void DnsConfigService::StartTimer() {
void DnsConfigService::OnTimeout() { void DnsConfigService::OnTimeout() {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
DCHECK(!last_sent_empty_);
// Indicate that even if there is no change in On*Read, we will need to // Indicate that even if there is no change in On*Read, we will need to
// update the receiver when the config becomes complete. // update the receiver when the config becomes complete.
need_update_ = true; need_update_ = true;
// Empty config is considered invalid. // Empty config is considered invalid.
last_sent_empty_ = true;
callback_.Run(DnsConfig()); callback_.Run(DnsConfig());
} }
void DnsConfigService::OnCompleteConfig() { void DnsConfigService::OnCompleteConfig() {
timer_.Stop(); timer_.Stop();
if (need_update_) { if (!need_update_)
need_update_ = false; return;
callback_.Run(dns_config_); need_update_ = false;
} last_sent_empty_ = false;
callback_.Run(dns_config_);
} }
} // namespace net } // namespace net
......
...@@ -135,6 +135,8 @@ class NET_EXPORT_PRIVATE DnsConfigService ...@@ -135,6 +135,8 @@ class NET_EXPORT_PRIVATE DnsConfigService
bool have_hosts_; bool have_hosts_;
// True if receiver needs to be updated when the config becomes complete. // True if receiver needs to be updated when the config becomes complete.
bool need_update_; bool need_update_;
// True if the last config sent was empty (instead of |dns_config_|).
bool last_sent_empty_;
// Started in Invalidate*, cleared in On*Read. // Started in Invalidate*, cleared in On*Read.
base::OneShotTimer<DnsConfigService> timer_; base::OneShotTimer<DnsConfigService> timer_;
......
...@@ -114,6 +114,7 @@ TEST_F(DnsConfigServiceTest, FirstConfig) { ...@@ -114,6 +114,7 @@ TEST_F(DnsConfigServiceTest, FirstConfig) {
TEST_F(DnsConfigServiceTest, Timeout) { TEST_F(DnsConfigServiceTest, Timeout) {
DnsConfig config = MakeConfig(1); DnsConfig config = MakeConfig(1);
config.hosts = MakeHosts(1); config.hosts = MakeHosts(1);
ASSERT_TRUE(config.IsValid());
service_->OnConfigRead(config); service_->OnConfigRead(config);
service_->OnHostsRead(config.hosts); service_->OnHostsRead(config.hosts);
...@@ -131,6 +132,14 @@ TEST_F(DnsConfigServiceTest, Timeout) { ...@@ -131,6 +132,14 @@ TEST_F(DnsConfigServiceTest, Timeout) {
WaitForConfig(TestTimeouts::action_timeout()); WaitForConfig(TestTimeouts::action_timeout());
EXPECT_FALSE(last_config_.IsValid()); EXPECT_FALSE(last_config_.IsValid());
service_->InvalidateConfig();
// We don't expect an update. This should time out. If we get an update,
// we'll detect unchanged config.
WaitForConfig(base::TimeDelta::FromMilliseconds(100) +
TestTimeouts::tiny_timeout());
EXPECT_FALSE(last_config_.IsValid());
service_->OnConfigRead(config);
service_->OnHostsRead(config.hosts); service_->OnHostsRead(config.hosts);
EXPECT_TRUE(last_config_.Equals(config)); EXPECT_TRUE(last_config_.Equals(config));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment