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

Side by Side Diff: chrome/browser/net/dns_probe_service.cc

Issue 1277213003: Move DNS functions from net_error_info.h into error_page namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 5 years, 4 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 | « no previous file | chrome/browser/net/net_error_tab_helper.cc » ('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 "chrome/browser/net/dns_probe_service.h" 5 #include "chrome/browser/net/dns_probe_service.h"
6 6
7 #include "base/metrics/field_trial.h" 7 #include "base/metrics/field_trial.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "net/base/ip_endpoint.h" 10 #include "net/base/ip_endpoint.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 // Otherwise: the system DNS is not working and another public server is 70 // Otherwise: the system DNS is not working and another public server is
71 // responding but with errors or incorrect results. This is an awkward case; 71 // responding but with errors or incorrect results. This is an awkward case;
72 // an invasive captive portal or a restrictive firewall may be intercepting 72 // an invasive captive portal or a restrictive firewall may be intercepting
73 // or rewriting DNS traffic, or the public server may itself be failing or 73 // or rewriting DNS traffic, or the public server may itself be failing or
74 // down. 74 // down.
75 return chrome_common_net::DNS_PROBE_FINISHED_INCONCLUSIVE; 75 return chrome_common_net::DNS_PROBE_FINISHED_INCONCLUSIVE;
76 } 76 }
77 77
78 void HistogramProbe(DnsProbeStatus status, base::TimeDelta elapsed) { 78 void HistogramProbe(DnsProbeStatus status, base::TimeDelta elapsed) {
79 DCHECK(chrome_common_net::DnsProbeStatusIsFinished(status)); 79 DCHECK(error_page::DnsProbeStatusIsFinished(status));
80 80
81 UMA_HISTOGRAM_ENUMERATION("DnsProbe.ProbeResult", status, 81 UMA_HISTOGRAM_ENUMERATION("DnsProbe.ProbeResult", status,
82 chrome_common_net::DNS_PROBE_MAX); 82 chrome_common_net::DNS_PROBE_MAX);
83 UMA_HISTOGRAM_MEDIUM_TIMES("DnsProbe.ProbeDuration", elapsed); 83 UMA_HISTOGRAM_MEDIUM_TIMES("DnsProbe.ProbeDuration", elapsed);
84 } 84 }
85 85
86 } // namespace 86 } // namespace
87 87
88 DnsProbeService::DnsProbeService() 88 DnsProbeService::DnsProbeService()
89 : state_(STATE_NO_RESULT) { 89 : state_(STATE_NO_RESULT) {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 public_runner_.result()); 191 public_runner_.result());
192 state_ = STATE_RESULT_CACHED; 192 state_ = STATE_RESULT_CACHED;
193 193
194 HistogramProbe(cached_result_, base::Time::Now() - probe_start_time_); 194 HistogramProbe(cached_result_, base::Time::Now() - probe_start_time_);
195 195
196 CallCallbacks(); 196 CallCallbacks();
197 } 197 }
198 198
199 void DnsProbeService::CallCallbacks() { 199 void DnsProbeService::CallCallbacks() {
200 DCHECK_EQ(STATE_RESULT_CACHED, state_); 200 DCHECK_EQ(STATE_RESULT_CACHED, state_);
201 DCHECK(chrome_common_net::DnsProbeStatusIsFinished(cached_result_)); 201 DCHECK(error_page::DnsProbeStatusIsFinished(cached_result_));
202 DCHECK(!pending_callbacks_.empty()); 202 DCHECK(!pending_callbacks_.empty());
203 203
204 std::vector<ProbeCallback> callbacks; 204 std::vector<ProbeCallback> callbacks;
205 callbacks.swap(pending_callbacks_); 205 callbacks.swap(pending_callbacks_);
206 206
207 for (std::vector<ProbeCallback>::const_iterator i = callbacks.begin(); 207 for (std::vector<ProbeCallback>::const_iterator i = callbacks.begin();
208 i != callbacks.end(); ++i) { 208 i != callbacks.end(); ++i) {
209 i->Run(cached_result_); 209 i->Run(cached_result_);
210 } 210 }
211 } 211 }
212 212
213 void DnsProbeService::ClearCachedResult() { 213 void DnsProbeService::ClearCachedResult() {
214 if (state_ == STATE_RESULT_CACHED) { 214 if (state_ == STATE_RESULT_CACHED) {
215 state_ = STATE_NO_RESULT; 215 state_ = STATE_NO_RESULT;
216 cached_result_ = chrome_common_net::DNS_PROBE_MAX; 216 cached_result_ = chrome_common_net::DNS_PROBE_MAX;
217 } 217 }
218 } 218 }
219 219
220 bool DnsProbeService::CachedResultIsExpired() const { 220 bool DnsProbeService::CachedResultIsExpired() const {
221 if (state_ != STATE_RESULT_CACHED) 221 if (state_ != STATE_RESULT_CACHED)
222 return false; 222 return false;
223 223
224 const base::TimeDelta kMaxResultAge = 224 const base::TimeDelta kMaxResultAge =
225 base::TimeDelta::FromMilliseconds(kMaxResultAgeMs); 225 base::TimeDelta::FromMilliseconds(kMaxResultAgeMs);
226 return base::Time::Now() - probe_start_time_ > kMaxResultAge; 226 return base::Time::Now() - probe_start_time_ > kMaxResultAge;
227 } 227 }
228 228
229 } // namespace chrome_browser_net 229 } // namespace chrome_browser_net
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/net/net_error_tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698