| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 82   SetMotivation(motivation); | 82   SetMotivation(motivation); | 
| 83   GetDuration();  // Set time_ | 83   GetDuration();  // Set time_ | 
| 84   DLogResultsStats("DNS Prefetch in queue"); | 84   DLogResultsStats("DNS Prefetch in queue"); | 
| 85 } | 85 } | 
| 86 | 86 | 
| 87 void DnsHostInfo::SetAssignedState() { | 87 void DnsHostInfo::SetAssignedState() { | 
| 88   DCHECK(QUEUED == state_); | 88   DCHECK(QUEUED == state_); | 
| 89   state_ = ASSIGNED; | 89   state_ = ASSIGNED; | 
| 90   queue_duration_ = GetDuration(); | 90   queue_duration_ = GetDuration(); | 
| 91   DLogResultsStats("DNS Prefetch assigned"); | 91   DLogResultsStats("DNS Prefetch assigned"); | 
| 92   UMA_HISTOGRAM_TIMES(L"DNS.PrefetchQueue", queue_duration_); | 92   UMA_HISTOGRAM_TIMES("DNS.PrefetchQueue", queue_duration_); | 
| 93 } | 93 } | 
| 94 | 94 | 
| 95 void DnsHostInfo::SetPendingDeleteState() { | 95 void DnsHostInfo::SetPendingDeleteState() { | 
| 96   DCHECK(ASSIGNED == state_  || ASSIGNED_BUT_MARKED == state_); | 96   DCHECK(ASSIGNED == state_  || ASSIGNED_BUT_MARKED == state_); | 
| 97   state_ = ASSIGNED_BUT_MARKED; | 97   state_ = ASSIGNED_BUT_MARKED; | 
| 98 } | 98 } | 
| 99 | 99 | 
| 100 void DnsHostInfo::SetFoundState() { | 100 void DnsHostInfo::SetFoundState() { | 
| 101   DCHECK(ASSIGNED == state_); | 101   DCHECK(ASSIGNED == state_); | 
| 102   state_ = FOUND; | 102   state_ = FOUND; | 
| 103   resolve_duration_ = GetDuration(); | 103   resolve_duration_ = GetDuration(); | 
| 104   if (kMaxNonNetworkDnsLookupDuration <= resolve_duration_) { | 104   if (kMaxNonNetworkDnsLookupDuration <= resolve_duration_) { | 
| 105     UMA_HISTOGRAM_LONG_TIMES(L"DNS.PrefetchFoundNameL", resolve_duration_); | 105     UMA_HISTOGRAM_LONG_TIMES("DNS.PrefetchFoundNameL", resolve_duration_); | 
| 106     // Record potential beneficial time, and maybe we'll get a cache hit. | 106     // Record potential beneficial time, and maybe we'll get a cache hit. | 
| 107     // We keep the maximum, as the warming we did earlier may still be | 107     // We keep the maximum, as the warming we did earlier may still be | 
| 108     // helping with a cache upstream in DNS resolution. | 108     // helping with a cache upstream in DNS resolution. | 
| 109     benefits_remaining_ = std::max(resolve_duration_, benefits_remaining_); | 109     benefits_remaining_ = std::max(resolve_duration_, benefits_remaining_); | 
| 110   } | 110   } | 
| 111   sequence_number_ = sequence_counter++; | 111   sequence_number_ = sequence_counter++; | 
| 112   DLogResultsStats("DNS PrefetchFound"); | 112   DLogResultsStats("DNS PrefetchFound"); | 
| 113 } | 113 } | 
| 114 | 114 | 
| 115 void DnsHostInfo::SetNoSuchNameState() { | 115 void DnsHostInfo::SetNoSuchNameState() { | 
| 116   DCHECK(ASSIGNED == state_); | 116   DCHECK(ASSIGNED == state_); | 
| 117   state_ = NO_SUCH_NAME; | 117   state_ = NO_SUCH_NAME; | 
| 118   resolve_duration_ = GetDuration(); | 118   resolve_duration_ = GetDuration(); | 
| 119   if (kMaxNonNetworkDnsLookupDuration <= resolve_duration_) { | 119   if (kMaxNonNetworkDnsLookupDuration <= resolve_duration_) { | 
| 120     DHISTOGRAM_TIMES(L"DNS.PrefetchNotFoundName", resolve_duration_); | 120     DHISTOGRAM_TIMES("DNS.PrefetchNotFoundName", resolve_duration_); | 
| 121     // Record potential beneficial time, and maybe we'll get a cache hit. | 121     // Record potential beneficial time, and maybe we'll get a cache hit. | 
| 122     benefits_remaining_ = std::max(resolve_duration_, benefits_remaining_); | 122     benefits_remaining_ = std::max(resolve_duration_, benefits_remaining_); | 
| 123   } | 123   } | 
| 124   sequence_number_ = sequence_counter++; | 124   sequence_number_ = sequence_counter++; | 
| 125   DLogResultsStats("DNS PrefetchNotFound"); | 125   DLogResultsStats("DNS PrefetchNotFound"); | 
| 126 } | 126 } | 
| 127 | 127 | 
| 128 void DnsHostInfo::SetStartedState() { | 128 void DnsHostInfo::SetStartedState() { | 
| 129   DCHECK(PENDING == state_); | 129   DCHECK(PENDING == state_); | 
| 130   state_ = STARTED; | 130   state_ = STARTED; | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 169 // 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 | 
| 170 // previously prefetched info. | 170 // previously prefetched info. | 
| 171 DnsBenefit DnsHostInfo::AccruePrefetchBenefits(DnsHostInfo* navigation_info) { | 171 DnsBenefit DnsHostInfo::AccruePrefetchBenefits(DnsHostInfo* navigation_info) { | 
| 172   DCHECK(FINISHED == navigation_info->state_ || | 172   DCHECK(FINISHED == navigation_info->state_ || | 
| 173          FINISHED_UNRESOLVED == navigation_info->state_); | 173          FINISHED_UNRESOLVED == navigation_info->state_); | 
| 174   DCHECK(0 == navigation_info->hostname_.compare(hostname_.data())); | 174   DCHECK(0 == navigation_info->hostname_.compare(hostname_.data())); | 
| 175 | 175 | 
| 176   if ((0 == benefits_remaining_.InMilliseconds()) || | 176   if ((0 == benefits_remaining_.InMilliseconds()) || | 
| 177       (FOUND != state_ && NO_SUCH_NAME != state_)) { | 177       (FOUND != state_ && NO_SUCH_NAME != state_)) { | 
| 178     if (FINISHED == navigation_info->state_) | 178     if (FINISHED == navigation_info->state_) | 
| 179       UMA_HISTOGRAM_LONG_TIMES(L"DNS.IndependentNavigation", | 179       UMA_HISTOGRAM_LONG_TIMES("DNS.IndependentNavigation", | 
| 180                                navigation_info->resolve_duration_); | 180                                navigation_info->resolve_duration_); | 
| 181     else | 181     else | 
| 182       UMA_HISTOGRAM_LONG_TIMES(L"DNS.IndependentFailedNavigation", | 182       UMA_HISTOGRAM_LONG_TIMES("DNS.IndependentFailedNavigation", | 
| 183                                navigation_info->resolve_duration_); | 183                                navigation_info->resolve_duration_); | 
| 184     return PREFETCH_NO_BENEFIT; | 184     return PREFETCH_NO_BENEFIT; | 
| 185   } | 185   } | 
| 186 | 186 | 
| 187   TimeDelta benefit = benefits_remaining_ - navigation_info->resolve_duration_; | 187   TimeDelta benefit = benefits_remaining_ - navigation_info->resolve_duration_; | 
| 188   navigation_info->benefits_remaining_ = benefits_remaining_; | 188   navigation_info->benefits_remaining_ = benefits_remaining_; | 
| 189   benefits_remaining_ = TimeDelta();  // We used up all our benefits here. | 189   benefits_remaining_ = TimeDelta();  // We used up all our benefits here. | 
| 190 | 190 | 
| 191   navigation_info->motivation_ = motivation_; | 191   navigation_info->motivation_ = motivation_; | 
| 192   if (LEARNED_REFERAL_MOTIVATED == motivation_ || | 192   if (LEARNED_REFERAL_MOTIVATED == motivation_ || | 
| 193       STATIC_REFERAL_MOTIVATED == motivation_) | 193       STATIC_REFERAL_MOTIVATED == motivation_) | 
| 194     navigation_info->referring_hostname_ = referring_hostname_; | 194     navigation_info->referring_hostname_ = referring_hostname_; | 
| 195 | 195 | 
| 196   if (navigation_info->resolve_duration_ > kMaxNonNetworkDnsLookupDuration) { | 196   if (navigation_info->resolve_duration_ > kMaxNonNetworkDnsLookupDuration) { | 
| 197     // Our precache effort didn't help since HTTP stack hit the network. | 197     // Our precache effort didn't help since HTTP stack hit the network. | 
| 198     UMA_HISTOGRAM_LONG_TIMES(L"DNS.PrefetchCacheEvictionL", resolve_duration_); | 198     UMA_HISTOGRAM_LONG_TIMES("DNS.PrefetchCacheEvictionL", resolve_duration_); | 
| 199     DLogResultsStats("DNS PrefetchCacheEviction"); | 199     DLogResultsStats("DNS PrefetchCacheEviction"); | 
| 200     return PREFETCH_CACHE_EVICTION; | 200     return PREFETCH_CACHE_EVICTION; | 
| 201   } | 201   } | 
| 202 | 202 | 
| 203   if (NO_SUCH_NAME == state_) { | 203   if (NO_SUCH_NAME == state_) { | 
| 204     UMA_HISTOGRAM_LONG_TIMES(L"DNS.PrefetchNegativeHitL", benefit); | 204     UMA_HISTOGRAM_LONG_TIMES("DNS.PrefetchNegativeHitL", benefit); | 
| 205     DLogResultsStats("DNS PrefetchNegativeHit"); | 205     DLogResultsStats("DNS PrefetchNegativeHit"); | 
| 206     return PREFETCH_NAME_NONEXISTANT; | 206     return PREFETCH_NAME_NONEXISTANT; | 
| 207   } | 207   } | 
| 208 | 208 | 
| 209   DCHECK_EQ(FOUND, state_); | 209   DCHECK_EQ(FOUND, state_); | 
| 210   if (LEARNED_REFERAL_MOTIVATED == motivation_ || | 210   if (LEARNED_REFERAL_MOTIVATED == motivation_ || | 
| 211       STATIC_REFERAL_MOTIVATED == motivation_) { | 211       STATIC_REFERAL_MOTIVATED == motivation_) { | 
| 212     UMA_HISTOGRAM_TIMES(L"DNS.PrefetchReferredPositiveHit", benefit); | 212     UMA_HISTOGRAM_TIMES("DNS.PrefetchReferredPositiveHit", benefit); | 
| 213     DLogResultsStats("DNS PrefetchReferredPositiveHit"); | 213     DLogResultsStats("DNS PrefetchReferredPositiveHit"); | 
| 214   } else { | 214   } else { | 
| 215     UMA_HISTOGRAM_LONG_TIMES(L"DNS.PrefetchPositiveHitL", benefit); | 215     UMA_HISTOGRAM_LONG_TIMES("DNS.PrefetchPositiveHitL", benefit); | 
| 216     DLogResultsStats("DNS PrefetchPositiveHit"); | 216     DLogResultsStats("DNS PrefetchPositiveHit"); | 
| 217   } | 217   } | 
| 218   return PREFETCH_NAME_FOUND; | 218   return PREFETCH_NAME_FOUND; | 
| 219 } | 219 } | 
| 220 | 220 | 
| 221 void DnsHostInfo::DLogResultsStats(const char* message) const { | 221 void DnsHostInfo::DLogResultsStats(const char* message) const { | 
| 222   if (!detailed_logging_enabled) | 222   if (!detailed_logging_enabled) | 
| 223     return; | 223     return; | 
| 224   DLOG(INFO) << "\t" << message <<  "\tq=" | 224   DLOG(INFO) << "\t" << message <<  "\tq=" | 
| 225       << queue_duration().InMilliseconds() << "ms,\tr=" | 225       << queue_duration().InMilliseconds() << "ms,\tr=" | 
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 401 | 401 | 
| 402     case LEARNED_REFERAL_MOTIVATED: | 402     case LEARNED_REFERAL_MOTIVATED: | 
| 403       return RemoveJs(referring_hostname_); | 403       return RemoveJs(referring_hostname_); | 
| 404 | 404 | 
| 405     default: | 405     default: | 
| 406       return ""; | 406       return ""; | 
| 407   } | 407   } | 
| 408 } | 408 } | 
| 409 | 409 | 
| 410 }  // namespace chrome_browser_net | 410 }  // namespace chrome_browser_net | 
| 411 |  | 
| OLD | NEW | 
|---|