| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/dns/dns_config_service.h" | 5 #include "net/dns/dns_config_service.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "net/base/ip_endpoint.h" | 8 #include "net/base/ip_endpoint.h" |
| 9 | 9 |
| 10 namespace net { | 10 namespace net { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 93 } |
| 94 | 94 |
| 95 have_hosts_ = true; | 95 have_hosts_ = true; |
| 96 if (have_config_) | 96 if (have_config_) |
| 97 OnCompleteConfig(); | 97 OnCompleteConfig(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void DnsConfigService::StartTimer() { | 100 void DnsConfigService::StartTimer() { |
| 101 DCHECK(CalledOnValidThread()); | 101 DCHECK(CalledOnValidThread()); |
| 102 timer_.Stop(); | 102 timer_.Stop(); |
| 103 |
| 104 // Give it a short timeout to come up with a valid config. Otherwise withdraw |
| 105 // the config from the receiver. The goal is to avoid perceivable network |
| 106 // outage (when using the wrong config) but at the same time avoid |
| 107 // unnecessary Job aborts in HostResolverImpl. The signals come from multiple |
| 108 // sources so it might receive multiple events during a config change. |
| 109 |
| 110 // DHCP and user-induced changes are on the order of seconds, so 100ms should |
| 111 // not add perceivable delay. On the other hand, config readers should finish |
| 112 // within 100ms with the rare exception of I/O block or extra large HOSTS. |
| 103 const base::TimeDelta kTimeout = base::TimeDelta::FromMilliseconds(100); | 113 const base::TimeDelta kTimeout = base::TimeDelta::FromMilliseconds(100); |
| 114 |
| 104 timer_.Start(FROM_HERE, | 115 timer_.Start(FROM_HERE, |
| 105 kTimeout, | 116 kTimeout, |
| 106 this, | 117 this, |
| 107 &DnsConfigService::OnTimeout); | 118 &DnsConfigService::OnTimeout); |
| 108 } | 119 } |
| 109 | 120 |
| 110 void DnsConfigService::OnTimeout() { | 121 void DnsConfigService::OnTimeout() { |
| 111 DCHECK(CalledOnValidThread()); | 122 DCHECK(CalledOnValidThread()); |
| 112 // Indicate that even if there is no change in On*Read, we will need to | 123 // Indicate that even if there is no change in On*Read, we will need to |
| 113 // update the receiver when the config becomes complete. | 124 // update the receiver when the config becomes complete. |
| 114 need_update_ = true; | 125 need_update_ = true; |
| 126 // Empty config is considered invalid. |
| 115 callback_.Run(DnsConfig()); | 127 callback_.Run(DnsConfig()); |
| 116 } | 128 } |
| 117 | 129 |
| 118 void DnsConfigService::OnCompleteConfig() { | 130 void DnsConfigService::OnCompleteConfig() { |
| 119 timer_.Stop(); | 131 timer_.Stop(); |
| 120 if (need_update_) { | 132 if (need_update_) { |
| 121 need_update_ = false; | 133 need_update_ = false; |
| 122 callback_.Run(dns_config_); | 134 callback_.Run(dns_config_); |
| 123 } | 135 } |
| 124 } | 136 } |
| 125 | 137 |
| 126 } // namespace net | 138 } // namespace net |
| 127 | 139 |
| OLD | NEW |