| 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 // A DnsHostInfo object is used to store status of a Dns lookup of a specific | 5 // A DnsHostInfo object is used to store status of a Dns lookup of a specific |
| 6 // hostname. | 6 // hostname. |
| 7 // It includes progress, from placement in the DnsMaster's queue, to assignment | 7 // It includes progress, from placement in the DnsMaster's queue, to assignment |
| 8 // to a slave, to resolution by the (blocking) DNS service as either FOUND or | 8 // to a slave, to resolution by the (blocking) DNS service as either FOUND or |
| 9 // NO_SUCH_NAME. | 9 // NO_SUCH_NAME. |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 PENDING, // Constructor has completed. | 37 PENDING, // Constructor has completed. |
| 38 QUEUED, // In prefetch queue but not yet assigned to a slave. | 38 QUEUED, // In prefetch queue but not yet assigned to a slave. |
| 39 ASSIGNED, // Currently being processed by a slave. | 39 ASSIGNED, // Currently being processed by a slave. |
| 40 ASSIGNED_BUT_MARKED, // Needs to be deleted as soon as slave is done. | 40 ASSIGNED_BUT_MARKED, // Needs to be deleted as soon as slave is done. |
| 41 FOUND, // DNS prefetch search completed. | 41 FOUND, // DNS prefetch search completed. |
| 42 NO_SUCH_NAME, // DNS prefetch search completed. | 42 NO_SUCH_NAME, // DNS prefetch search completed. |
| 43 // When processed by the HTTP network stack, there are 3 states: | 43 // When processed by the HTTP network stack, there are 3 states: |
| 44 STARTED, // Resolution has begun. | 44 STARTED, // Resolution has begun. |
| 45 FINISHED, // Resolution has completed. | 45 FINISHED, // Resolution has completed. |
| 46 FINISHED_UNRESOLVED}; // No resolution found. | 46 FINISHED_UNRESOLVED}; // No resolution found. |
| 47 static const TimeDelta kMaxNonNetworkDnsLookupDuration; | 47 static const base::TimeDelta kMaxNonNetworkDnsLookupDuration; |
| 48 // The number of OS cache entries we can guarantee(?) before cache eviction | 48 // The number of OS cache entries we can guarantee(?) before cache eviction |
| 49 // might likely take place. | 49 // might likely take place. |
| 50 static const int kMaxGuaranteedCacheSize = 50; | 50 static const int kMaxGuaranteedCacheSize = 50; |
| 51 | 51 |
| 52 typedef std::vector<DnsHostInfo> DnsInfoTable; | 52 typedef std::vector<DnsHostInfo> DnsInfoTable; |
| 53 | 53 |
| 54 static const TimeDelta kNullDuration; | 54 static const base::TimeDelta kNullDuration; |
| 55 | 55 |
| 56 // DnsHostInfo are usually made by the default constructor during | 56 // DnsHostInfo are usually made by the default constructor during |
| 57 // initializing of the DnsMaster's map (of info for Hostnames). | 57 // initializing of the DnsMaster's map (of info for Hostnames). |
| 58 DnsHostInfo() | 58 DnsHostInfo() |
| 59 : state_(PENDING), | 59 : state_(PENDING), |
| 60 resolve_duration_(kNullDuration), | 60 resolve_duration_(kNullDuration), |
| 61 queue_duration_(kNullDuration), | 61 queue_duration_(kNullDuration), |
| 62 benefits_remaining_(), | 62 benefits_remaining_(), |
| 63 sequence_number_(0) { | 63 sequence_number_(0) { |
| 64 } | 64 } |
| 65 | 65 |
| 66 ~DnsHostInfo() {} | 66 ~DnsHostInfo() {} |
| 67 | 67 |
| 68 // NeedDnsUpdate decides, based on our internal info, | 68 // NeedDnsUpdate decides, based on our internal info, |
| 69 // if it would be valuable to attempt to update (prefectch) | 69 // if it would be valuable to attempt to update (prefectch) |
| 70 // DNS data for hostname. This decision is based | 70 // DNS data for hostname. This decision is based |
| 71 // on how recently we've done DNS prefetching for hostname. | 71 // on how recently we've done DNS prefetching for hostname. |
| 72 bool NeedsDnsUpdate(const std::string& hostname); | 72 bool NeedsDnsUpdate(const std::string& hostname); |
| 73 | 73 |
| 74 static void set_cache_expiration(TimeDelta time); | 74 static void set_cache_expiration(base::TimeDelta time); |
| 75 | 75 |
| 76 // The prefetching lifecycle. | 76 // The prefetching lifecycle. |
| 77 void SetQueuedState(); | 77 void SetQueuedState(); |
| 78 void SetAssignedState(); | 78 void SetAssignedState(); |
| 79 void SetPendingDeleteState(); | 79 void SetPendingDeleteState(); |
| 80 void SetFoundState(); | 80 void SetFoundState(); |
| 81 void SetNoSuchNameState(); | 81 void SetNoSuchNameState(); |
| 82 // The actual browsing resolution lifecycle. | 82 // The actual browsing resolution lifecycle. |
| 83 void SetStartedState(); | 83 void SetStartedState(); |
| 84 void SetFinishedState(bool was_resolved); | 84 void SetFinishedState(bool was_resolved); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 95 bool is_assigned() const { | 95 bool is_assigned() const { |
| 96 return ASSIGNED == state_ || ASSIGNED_BUT_MARKED == state_; | 96 return ASSIGNED == state_ || ASSIGNED_BUT_MARKED == state_; |
| 97 } | 97 } |
| 98 bool is_marked_to_delete() const { return ASSIGNED_BUT_MARKED == state_; } | 98 bool is_marked_to_delete() const { return ASSIGNED_BUT_MARKED == state_; } |
| 99 const std::string hostname() const { return hostname_; } | 99 const std::string hostname() const { return hostname_; } |
| 100 | 100 |
| 101 bool HasHostname(const std::string& hostname) const { | 101 bool HasHostname(const std::string& hostname) const { |
| 102 return (hostname == hostname_); | 102 return (hostname == hostname_); |
| 103 } | 103 } |
| 104 | 104 |
| 105 TimeDelta resolve_duration() const { return resolve_duration_;} | 105 base::TimeDelta resolve_duration() const { return resolve_duration_;} |
| 106 TimeDelta queue_duration() const { return queue_duration_;} | 106 base::TimeDelta queue_duration() const { return queue_duration_;} |
| 107 TimeDelta benefits_remaining() const { return benefits_remaining_; } | 107 base::TimeDelta benefits_remaining() const { return benefits_remaining_; } |
| 108 | 108 |
| 109 DnsBenefit AcruePrefetchBenefits(DnsHostInfo* later_host_info); | 109 DnsBenefit AcruePrefetchBenefits(DnsHostInfo* later_host_info); |
| 110 | 110 |
| 111 void DLogResultsStats(const char* message) const; | 111 void DLogResultsStats(const char* message) const; |
| 112 | 112 |
| 113 static void GetHtmlTable(const DnsInfoTable host_infos, | 113 static void GetHtmlTable(const DnsInfoTable host_infos, |
| 114 const char* description, | 114 const char* description, |
| 115 const bool brief, | 115 const bool brief, |
| 116 std::string* output); | 116 std::string* output); |
| 117 | 117 |
| 118 private: | 118 private: |
| 119 // The next declaration is non-const to facilitate testing. | 119 // The next declaration is non-const to facilitate testing. |
| 120 static TimeDelta kCacheExpirationDuration; | 120 static base::TimeDelta kCacheExpirationDuration; |
| 121 | 121 |
| 122 DnsProcessingState state_; | 122 DnsProcessingState state_; |
| 123 std::string hostname_; // Hostname for this info. | 123 std::string hostname_; // Hostname for this info. |
| 124 | 124 |
| 125 TimeTicks time_; // When was last state changed (usually lookup completed). | 125 // When was last state changed (usually lookup completed). |
| 126 TimeDelta resolve_duration_; // Time needed for DNS to resolve. | 126 base::TimeTicks time_; |
| 127 TimeDelta queue_duration_; // Time spent in queue. | 127 // Time needed for DNS to resolve. |
| 128 TimeDelta benefits_remaining_; // Unused potential benefits of a prefetch. | 128 base::TimeDelta resolve_duration_; |
| 129 // Time spent in queue. |
| 130 base::TimeDelta queue_duration_; |
| 131 // Unused potential benefits of a prefetch. |
| 132 base::TimeDelta benefits_remaining_; |
| 129 | 133 |
| 130 int sequence_number_; // Used to calculate potential of cache eviction. | 134 int sequence_number_; // Used to calculate potential of cache eviction. |
| 131 static int sequence_counter; // Used to allocate sequence_number_'s. | 135 static int sequence_counter; // Used to allocate sequence_number_'s. |
| 132 | 136 |
| 133 TimeDelta GetDuration() { | 137 base::TimeDelta GetDuration() { |
| 134 TimeTicks old_time = time_; | 138 base::TimeTicks old_time = time_; |
| 135 time_ = TimeTicks::Now(); | 139 time_ = base::TimeTicks::Now(); |
| 136 return time_ - old_time; | 140 return time_ - old_time; |
| 137 } | 141 } |
| 138 | 142 |
| 139 // IsStillCached() guesses if the DNS cache still has IP data. | 143 // IsStillCached() guesses if the DNS cache still has IP data. |
| 140 bool IsStillCached() const; | 144 bool IsStillCached() const; |
| 141 | 145 |
| 142 // We put these objects into a std::map, and hence we | 146 // We put these objects into a std::map, and hence we |
| 143 // need some "evil" constructors. | 147 // need some "evil" constructors. |
| 144 // DISALLOW_EVIL_CONSTRUCTORS(DnsHostInfo); | 148 // DISALLOW_EVIL_CONSTRUCTORS(DnsHostInfo); |
| 145 }; | 149 }; |
| 146 | 150 |
| 147 } // namespace chrome_browser_net | 151 } // namespace chrome_browser_net |
| 148 | 152 |
| 149 #endif // CHROME_BROWSER_NET_DNS_HOST_INFO_H__ | 153 #endif // CHROME_BROWSER_NET_DNS_HOST_INFO_H__ |
| 150 | |
| OLD | NEW |