| 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 DnsMaster object is instantiated once in the browser | 5 // A DnsMaster object is instantiated once in the browser |
| 6 // process, and delivers DNS prefetch assignments (hostnames) | 6 // process, and delivers DNS prefetch assignments (hostnames) |
| 7 // to any of several DnsSlave objects. | 7 // to any of several DnsSlave objects. |
| 8 // Most hostname lists are sent out by renderer processes, and | 8 // Most hostname lists are sent out by renderer processes, and |
| 9 // involve lists of hostnames that *might* be used in the near | 9 // involve lists of hostnames that *might* be used in the near |
| 10 // future by the browsing user. The goal of this class is to | 10 // future by the browsing user. The goal of this class is to |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 class DnsSlave; | 32 class DnsSlave; |
| 33 | 33 |
| 34 typedef chrome_common_net::NameList NameList; | 34 typedef chrome_common_net::NameList NameList; |
| 35 typedef std::map<std::string, DnsHostInfo> Results; | 35 typedef std::map<std::string, DnsHostInfo> Results; |
| 36 | 36 |
| 37 class DnsMaster { | 37 class DnsMaster { |
| 38 public: | 38 public: |
| 39 // The number of slave processes that will do DNS prefetching | 39 // The number of slave processes that will do DNS prefetching |
| 40 static const int kSlaveCountMax = 8; | 40 static const int kSlaveCountMax = 8; |
| 41 | 41 |
| 42 explicit DnsMaster(TimeDelta shutdown_wait_time); | 42 explicit DnsMaster(base::TimeDelta shutdown_wait_time); |
| 43 | 43 |
| 44 ~DnsMaster() { | 44 ~DnsMaster() { |
| 45 if (!shutdown_) | 45 if (!shutdown_) |
| 46 ShutdownSlaves(); // Ensure we did our cleanup. | 46 ShutdownSlaves(); // Ensure we did our cleanup. |
| 47 } | 47 } |
| 48 | 48 |
| 49 // ShutdownSlaves() gets all spawned threads to terminate, closes | 49 // ShutdownSlaves() gets all spawned threads to terminate, closes |
| 50 // their handles, and deletes their DnsSlave instances. | 50 // their handles, and deletes their DnsSlave instances. |
| 51 // Return value of true means all operations succeeded. | 51 // Return value of true means all operations succeeded. |
| 52 // Return value of false means that the threads wouldn't terminate, | 52 // Return value of false means that the threads wouldn't terminate, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 75 // Currently testing only provides a crude measure of success. | 75 // Currently testing only provides a crude measure of success. |
| 76 bool WasFound(const std::string& hostname) { | 76 bool WasFound(const std::string& hostname) { |
| 77 AutoLock auto_lock(lock_); | 77 AutoLock auto_lock(lock_); |
| 78 return (results_.find(hostname) != results_.end()) && | 78 return (results_.find(hostname) != results_.end()) && |
| 79 results_[hostname].was_found(); | 79 results_[hostname].was_found(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 // Accessor methods, used mostly for testing. | 82 // Accessor methods, used mostly for testing. |
| 83 // Both functions return DnsHostInfo::kNullDuration if name was not yet | 83 // Both functions return DnsHostInfo::kNullDuration if name was not yet |
| 84 // processed enough. | 84 // processed enough. |
| 85 TimeDelta GetResolutionDuration(const std::string hostname) { | 85 base::TimeDelta GetResolutionDuration(const std::string hostname) { |
| 86 AutoLock auto_lock(lock_); | 86 AutoLock auto_lock(lock_); |
| 87 if (results_.find(hostname) == results_.end()) | 87 if (results_.find(hostname) == results_.end()) |
| 88 return DnsHostInfo::kNullDuration; | 88 return DnsHostInfo::kNullDuration; |
| 89 return results_[hostname].resolve_duration(); | 89 return results_[hostname].resolve_duration(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 TimeDelta GetQueueDuration(const std::string hostname) { | 92 base::TimeDelta GetQueueDuration(const std::string hostname) { |
| 93 AutoLock auto_lock(lock_); | 93 AutoLock auto_lock(lock_); |
| 94 if (results_.find(hostname) == results_.end()) | 94 if (results_.find(hostname) == results_.end()) |
| 95 return DnsHostInfo::kNullDuration; | 95 return DnsHostInfo::kNullDuration; |
| 96 return results_[hostname].queue_duration(); | 96 return results_[hostname].queue_duration(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 int running_slave_count() { | 99 int running_slave_count() { |
| 100 AutoLock auto_lock(lock_); | 100 AutoLock auto_lock(lock_); |
| 101 return running_slave_count_; | 101 return running_slave_count_; |
| 102 } | 102 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 // slave_count_ grows (up to the indicated max). | 150 // slave_count_ grows (up to the indicated max). |
| 151 DWORD thread_ids_[kSlaveCountMax]; | 151 DWORD thread_ids_[kSlaveCountMax]; |
| 152 HANDLE thread_handles_[kSlaveCountMax]; | 152 HANDLE thread_handles_[kSlaveCountMax]; |
| 153 DnsSlave* slaves_[kSlaveCountMax]; | 153 DnsSlave* slaves_[kSlaveCountMax]; |
| 154 | 154 |
| 155 // shutdown_ is set to tell the slaves to terminate. | 155 // shutdown_ is set to tell the slaves to terminate. |
| 156 bool shutdown_; | 156 bool shutdown_; |
| 157 | 157 |
| 158 // The following is the maximum time the ShutdownSlaves method | 158 // The following is the maximum time the ShutdownSlaves method |
| 159 // will wait for all the slave processes to terminate. | 159 // will wait for all the slave processes to terminate. |
| 160 const TimeDelta kShutdownWaitTime_; | 160 const base::TimeDelta kShutdownWaitTime_; |
| 161 | 161 |
| 162 // A list of successful events resulting from pre-fetching. | 162 // A list of successful events resulting from pre-fetching. |
| 163 DnsHostInfo::DnsInfoTable cache_hits_; | 163 DnsHostInfo::DnsInfoTable cache_hits_; |
| 164 // A map of hosts that were evicted from our cache (after we prefetched them) | 164 // A map of hosts that were evicted from our cache (after we prefetched them) |
| 165 // and before the HTTP stack tried to look them up. | 165 // and before the HTTP stack tried to look them up. |
| 166 Results cache_eviction_map_; | 166 Results cache_eviction_map_; |
| 167 | 167 |
| 168 DISALLOW_EVIL_CONSTRUCTORS(DnsMaster); | 168 DISALLOW_EVIL_CONSTRUCTORS(DnsMaster); |
| 169 }; | 169 }; |
| 170 | 170 |
| 171 } // namespace chrome_browser_net | 171 } // namespace chrome_browser_net |
| 172 | 172 |
| 173 #endif // CHROME_BROWSER_NET_DNS_MASTER_H__ | 173 #endif // CHROME_BROWSER_NET_DNS_MASTER_H__ |
| 174 | 174 |
| OLD | NEW |