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 "chrome/browser/net/dns_probe_service.h" | 5 #include "chrome/browser/net/dns_probe_service.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
8 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
9 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
10 #include "net/base/ip_endpoint.h" | 12 #include "net/base/ip_endpoint.h" |
11 #include "net/base/net_util.h" | 13 #include "net/base/net_util.h" |
12 #include "net/dns/dns_client.h" | 14 #include "net/dns/dns_client.h" |
13 #include "net/dns/dns_config_service.h" | 15 #include "net/dns/dns_config_service.h" |
14 #include "net/dns/dns_protocol.h" | 16 #include "net/dns/dns_protocol.h" |
15 | 17 |
16 using base::FieldTrialList; | 18 using base::FieldTrialList; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 ClearCachedResult(); | 121 ClearCachedResult(); |
120 SetSystemClientToCurrentConfig(); | 122 SetSystemClientToCurrentConfig(); |
121 } | 123 } |
122 | 124 |
123 void DnsProbeService::OnInitialDNSConfigRead() { | 125 void DnsProbeService::OnInitialDNSConfigRead() { |
124 OnDNSChanged(); | 126 OnDNSChanged(); |
125 } | 127 } |
126 | 128 |
127 void DnsProbeService::SetSystemClientForTesting( | 129 void DnsProbeService::SetSystemClientForTesting( |
128 scoped_ptr<DnsClient> system_client) { | 130 scoped_ptr<DnsClient> system_client) { |
129 system_runner_.SetClient(system_client.Pass()); | 131 system_runner_.SetClient(std::move(system_client)); |
130 } | 132 } |
131 | 133 |
132 void DnsProbeService::SetPublicClientForTesting( | 134 void DnsProbeService::SetPublicClientForTesting( |
133 scoped_ptr<DnsClient> public_client) { | 135 scoped_ptr<DnsClient> public_client) { |
134 public_runner_.SetClient(public_client.Pass()); | 136 public_runner_.SetClient(std::move(public_client)); |
135 } | 137 } |
136 | 138 |
137 void DnsProbeService::ClearCachedResultForTesting() { | 139 void DnsProbeService::ClearCachedResultForTesting() { |
138 ClearCachedResult(); | 140 ClearCachedResult(); |
139 } | 141 } |
140 | 142 |
141 void DnsProbeService::SetSystemClientToCurrentConfig() { | 143 void DnsProbeService::SetSystemClientToCurrentConfig() { |
142 DnsConfig system_config; | 144 DnsConfig system_config; |
143 NetworkChangeNotifier::GetDnsConfig(&system_config); | 145 NetworkChangeNotifier::GetDnsConfig(&system_config); |
144 system_config.search.clear(); | 146 system_config.search.clear(); |
145 system_config.attempts = 1; | 147 system_config.attempts = 1; |
146 system_config.randomize_ports = false; | 148 system_config.randomize_ports = false; |
147 | 149 |
148 scoped_ptr<DnsClient> system_client(DnsClient::CreateClient(NULL)); | 150 scoped_ptr<DnsClient> system_client(DnsClient::CreateClient(NULL)); |
149 system_client->SetConfig(system_config); | 151 system_client->SetConfig(system_config); |
150 | 152 |
151 system_runner_.SetClient(system_client.Pass()); | 153 system_runner_.SetClient(std::move(system_client)); |
152 } | 154 } |
153 | 155 |
154 void DnsProbeService::SetPublicClientToGooglePublicDns() { | 156 void DnsProbeService::SetPublicClientToGooglePublicDns() { |
155 DnsConfig public_config; | 157 DnsConfig public_config; |
156 public_config.nameservers.push_back(MakeDnsEndPoint(kGooglePublicDns1)); | 158 public_config.nameservers.push_back(MakeDnsEndPoint(kGooglePublicDns1)); |
157 public_config.nameservers.push_back(MakeDnsEndPoint(kGooglePublicDns2)); | 159 public_config.nameservers.push_back(MakeDnsEndPoint(kGooglePublicDns2)); |
158 public_config.attempts = 1; | 160 public_config.attempts = 1; |
159 public_config.randomize_ports = false; | 161 public_config.randomize_ports = false; |
160 | 162 |
161 scoped_ptr<DnsClient> public_client(DnsClient::CreateClient(NULL)); | 163 scoped_ptr<DnsClient> public_client(DnsClient::CreateClient(NULL)); |
162 public_client->SetConfig(public_config); | 164 public_client->SetConfig(public_config); |
163 | 165 |
164 public_runner_.SetClient(public_client.Pass()); | 166 public_runner_.SetClient(std::move(public_client)); |
165 } | 167 } |
166 | 168 |
167 void DnsProbeService::StartProbes() { | 169 void DnsProbeService::StartProbes() { |
168 DCHECK_EQ(STATE_NO_RESULT, state_); | 170 DCHECK_EQ(STATE_NO_RESULT, state_); |
169 | 171 |
170 DCHECK(!system_runner_.IsRunning()); | 172 DCHECK(!system_runner_.IsRunning()); |
171 DCHECK(!public_runner_.IsRunning()); | 173 DCHECK(!public_runner_.IsRunning()); |
172 | 174 |
173 const base::Closure callback = base::Bind(&DnsProbeService::OnProbeComplete, | 175 const base::Closure callback = base::Bind(&DnsProbeService::OnProbeComplete, |
174 base::Unretained(this)); | 176 base::Unretained(this)); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 bool DnsProbeService::CachedResultIsExpired() const { | 222 bool DnsProbeService::CachedResultIsExpired() const { |
221 if (state_ != STATE_RESULT_CACHED) | 223 if (state_ != STATE_RESULT_CACHED) |
222 return false; | 224 return false; |
223 | 225 |
224 const base::TimeDelta kMaxResultAge = | 226 const base::TimeDelta kMaxResultAge = |
225 base::TimeDelta::FromMilliseconds(kMaxResultAgeMs); | 227 base::TimeDelta::FromMilliseconds(kMaxResultAgeMs); |
226 return base::Time::Now() - probe_start_time_ > kMaxResultAge; | 228 return base::Time::Now() - probe_start_time_ > kMaxResultAge; |
227 } | 229 } |
228 | 230 |
229 } // namespace chrome_browser_net | 231 } // namespace chrome_browser_net |
OLD | NEW |