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

Side by Side Diff: net/dns/dns_config_service.cc

Issue 9721002: [net/dns] Removes locking from DnsConfigServiceWin and adds local computer name. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Move lowercasing to ServeFromHosts, add test. Reorganize OnHostsRead. Created 8 years, 9 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 unified diff | Download patch
« no previous file with comments | « net/dns/dns_config_service.h ('k') | net/dns/dns_config_service_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « net/dns/dns_config_service.h ('k') | net/dns/dns_config_service_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698