OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // See header file for description of class | 5 // See header file for description of class |
6 | 6 |
7 #include "chrome/browser/net/dns_host_info.h" | 7 #include "chrome/browser/net/dns_host_info.h" |
8 | 8 |
9 #include <math.h> | 9 #include <math.h> |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 const TimeDelta DnsHostInfo::kMaxNonNetworkDnsLookupDuration( | 70 const TimeDelta DnsHostInfo::kMaxNonNetworkDnsLookupDuration( |
71 TimeDelta::FromMilliseconds(15)); | 71 TimeDelta::FromMilliseconds(15)); |
72 | 72 |
73 // Used by test ONLY. The value is otherwise constant. | 73 // Used by test ONLY. The value is otherwise constant. |
74 void DnsHostInfo::set_cache_expiration(TimeDelta time) { | 74 void DnsHostInfo::set_cache_expiration(TimeDelta time) { |
75 kCacheExpirationDuration = time; | 75 kCacheExpirationDuration = time; |
76 } | 76 } |
77 | 77 |
78 void DnsHostInfo::SetQueuedState(ResolutionMotivation motivation) { | 78 void DnsHostInfo::SetQueuedState(ResolutionMotivation motivation) { |
79 DCHECK(PENDING == state_ || FOUND == state_ || NO_SUCH_NAME == state_); | 79 DCHECK(PENDING == state_ || FOUND == state_ || NO_SUCH_NAME == state_); |
80 old_prequeue_state_ = state_; | |
81 state_ = QUEUED; | 80 state_ = QUEUED; |
82 queue_duration_ = resolve_duration_ = kNullDuration; | 81 queue_duration_ = resolve_duration_ = kNullDuration; |
83 SetMotivation(motivation); | 82 SetMotivation(motivation); |
84 GetDuration(); // Set time_ | 83 GetDuration(); // Set time_ |
85 DLogResultsStats("DNS Prefetch in queue"); | 84 DLogResultsStats("DNS Prefetch in queue"); |
86 } | 85 } |
87 | 86 |
88 void DnsHostInfo::SetAssignedState() { | 87 void DnsHostInfo::SetAssignedState() { |
89 DCHECK(QUEUED == state_); | 88 DCHECK(QUEUED == state_); |
90 state_ = ASSIGNED; | 89 state_ = ASSIGNED; |
91 queue_duration_ = GetDuration(); | 90 queue_duration_ = GetDuration(); |
92 DLogResultsStats("DNS Prefetch assigned"); | 91 DLogResultsStats("DNS Prefetch assigned"); |
93 UMA_HISTOGRAM_TIMES("DNS.PrefetchQueue", queue_duration_); | 92 UMA_HISTOGRAM_TIMES("DNS.PrefetchQueue", queue_duration_); |
94 } | 93 } |
95 | 94 |
96 void DnsHostInfo::RemoveFromQueue() { | |
97 DCHECK(ASSIGNED == state_); | |
98 state_ = old_prequeue_state_; | |
99 DLogResultsStats("DNS Prefetch reset to prequeue"); | |
100 static const TimeDelta kBoundary = TimeDelta::FromSeconds(2); | |
101 if (queue_duration_ > kBoundary) { | |
102 UMA_HISTOGRAM_MEDIUM_TIMES("DNS.QueueRecycledDeltaOver2", | |
103 queue_duration_ - kBoundary); | |
104 return; | |
105 } | |
106 // Make a custom linear histogram for the region from 0 to boundary. | |
107 const size_t kBucketCount = 52; | |
108 static LinearHistogram histogram("DNS.QueueRecycledUnder2", TimeDelta(), | |
109 kBoundary, kBucketCount); | |
110 histogram.SetFlags(kUmaTargetedHistogramFlag); | |
111 histogram.AddTime(queue_duration_); | |
112 } | |
113 | |
114 void DnsHostInfo::SetPendingDeleteState() { | 95 void DnsHostInfo::SetPendingDeleteState() { |
115 DCHECK(ASSIGNED == state_ || ASSIGNED_BUT_MARKED == state_); | 96 DCHECK(ASSIGNED == state_ || ASSIGNED_BUT_MARKED == state_); |
116 state_ = ASSIGNED_BUT_MARKED; | 97 state_ = ASSIGNED_BUT_MARKED; |
117 } | 98 } |
118 | 99 |
119 void DnsHostInfo::SetFoundState() { | 100 void DnsHostInfo::SetFoundState() { |
120 DCHECK(ASSIGNED == state_); | 101 DCHECK(ASSIGNED == state_); |
121 state_ = FOUND; | 102 state_ = FOUND; |
122 resolve_duration_ = GetDuration(); | 103 resolve_duration_ = GetDuration(); |
123 if (kMaxNonNetworkDnsLookupDuration <= resolve_duration_) { | 104 if (kMaxNonNetworkDnsLookupDuration <= resolve_duration_) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 void DnsHostInfo::SetFinishedState(bool was_resolved) { | 136 void DnsHostInfo::SetFinishedState(bool was_resolved) { |
156 DCHECK(STARTED == state_); | 137 DCHECK(STARTED == state_); |
157 state_ = was_resolved ? FINISHED : FINISHED_UNRESOLVED; | 138 state_ = was_resolved ? FINISHED : FINISHED_UNRESOLVED; |
158 resolve_duration_ = GetDuration(); | 139 resolve_duration_ = GetDuration(); |
159 // TODO(jar): Sequence number should be incremented in prefetched HostInfo. | 140 // TODO(jar): Sequence number should be incremented in prefetched HostInfo. |
160 DLogResultsStats("DNS HTTP Finished"); | 141 DLogResultsStats("DNS HTTP Finished"); |
161 } | 142 } |
162 | 143 |
163 void DnsHostInfo::SetHostname(const std::string& hostname) { | 144 void DnsHostInfo::SetHostname(const std::string& hostname) { |
164 if (hostname != hostname_) { | 145 if (hostname != hostname_) { |
165 DCHECK_EQ(hostname_.size(), 0u); // Not yet initialized. | 146 DCHECK(hostname_.size() == 0); // Not yet initialized. |
166 hostname_ = hostname; | 147 hostname_ = hostname; |
167 } | 148 } |
168 } | 149 } |
169 | 150 |
170 // IsStillCached() guesses if the DNS cache still has IP data, | 151 // IsStillCached() guesses if the DNS cache still has IP data, |
171 // or at least remembers results about "not finding host." | 152 // or at least remembers results about "not finding host." |
172 bool DnsHostInfo::IsStillCached() const { | 153 bool DnsHostInfo::IsStillCached() const { |
173 DCHECK(FOUND == state_ || NO_SUCH_NAME == state_); | 154 DCHECK(FOUND == state_ || NO_SUCH_NAME == state_); |
174 | 155 |
175 // Default MS OS does not cache failures. Hence we could return false almost | 156 // Default MS OS does not cache failures. Hence we could return false almost |
176 // all the time for that case. However, we'd never try again to prefetch | 157 // all the time for that case. However, we'd never try again to prefetch |
177 // the value if we returned false that way. Hence we'll just let the lookup | 158 // the value if we returned false that way. Hence we'll just let the lookup |
178 // time out the same way as FOUND case. | 159 // time out the same way as FOUND case. |
179 | 160 |
180 if (sequence_counter - sequence_number_ > kMaxGuaranteedCacheSize) | 161 if (sequence_counter - sequence_number_ > kMaxGuaranteedCacheSize) |
181 return false; | 162 return false; |
182 | 163 |
183 TimeDelta time_since_resolution = TimeTicks::Now() - time_; | 164 TimeDelta time_since_resolution = TimeTicks::Now() - time_; |
184 | 165 |
185 return time_since_resolution < kCacheExpirationDuration; | 166 return time_since_resolution < kCacheExpirationDuration; |
186 } | 167 } |
187 | 168 |
188 // Compare the actual navigation DNS latency found in navigation_info, to the | 169 // Compare the actual navigation DNS latency found in navigation_info, to the |
189 // previously prefetched info. | 170 // previously prefetched info. |
190 DnsBenefit DnsHostInfo::AccruePrefetchBenefits(DnsHostInfo* navigation_info) { | 171 DnsBenefit DnsHostInfo::AccruePrefetchBenefits(DnsHostInfo* navigation_info) { |
191 DCHECK(FINISHED == navigation_info->state_ || | 172 DCHECK(FINISHED == navigation_info->state_ || |
192 FINISHED_UNRESOLVED == navigation_info->state_); | 173 FINISHED_UNRESOLVED == navigation_info->state_); |
193 DCHECK_EQ(navigation_info->hostname_, hostname_.data()); | 174 DCHECK(0 == navigation_info->hostname_.compare(hostname_.data())); |
194 | 175 |
195 if ((0 == benefits_remaining_.InMilliseconds()) || | 176 if ((0 == benefits_remaining_.InMilliseconds()) || |
196 (FOUND != state_ && NO_SUCH_NAME != state_)) { | 177 (FOUND != state_ && NO_SUCH_NAME != state_)) { |
197 if (FINISHED == navigation_info->state_) | 178 if (FINISHED == navigation_info->state_) |
198 UMA_HISTOGRAM_LONG_TIMES("DNS.IndependentNavigation", | 179 UMA_HISTOGRAM_LONG_TIMES("DNS.IndependentNavigation", |
199 navigation_info->resolve_duration_); | 180 navigation_info->resolve_duration_); |
200 else | 181 else |
201 UMA_HISTOGRAM_LONG_TIMES("DNS.IndependentFailedNavigation", | 182 UMA_HISTOGRAM_LONG_TIMES("DNS.IndependentFailedNavigation", |
202 navigation_info->resolve_duration_); | 183 navigation_info->resolve_duration_); |
203 return PREFETCH_NO_BENEFIT; | 184 return PREFETCH_NO_BENEFIT; |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 | 401 |
421 case LEARNED_REFERAL_MOTIVATED: | 402 case LEARNED_REFERAL_MOTIVATED: |
422 return RemoveJs(referring_hostname_); | 403 return RemoveJs(referring_hostname_); |
423 | 404 |
424 default: | 405 default: |
425 return ""; | 406 return ""; |
426 } | 407 } |
427 } | 408 } |
428 | 409 |
429 } // namespace chrome_browser_net | 410 } // namespace chrome_browser_net |
OLD | NEW |