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 20 matching lines...) Expand all Loading... |
31 namespace chrome_browser_net { | 31 namespace chrome_browser_net { |
32 | 32 |
33 class DnsSlave; | 33 class DnsSlave; |
34 | 34 |
35 typedef chrome_common_net::NameList NameList; | 35 typedef chrome_common_net::NameList NameList; |
36 typedef std::map<std::string, DnsHostInfo> Results; | 36 typedef std::map<std::string, DnsHostInfo> Results; |
37 | 37 |
38 class DnsMaster { | 38 class DnsMaster { |
39 public: | 39 public: |
40 // The number of slave processes that will do DNS prefetching | 40 // The number of slave processes that will do DNS prefetching |
41 static const int kSlaveCountMax = 8; | 41 static const size_t kSlaveCountMax = 8; |
42 | 42 |
43 explicit DnsMaster(base::TimeDelta shutdown_wait_time); | 43 explicit DnsMaster(base::TimeDelta shutdown_wait_time); |
44 | 44 |
45 ~DnsMaster() { | 45 ~DnsMaster() { |
46 if (!shutdown_) | 46 if (!shutdown_) |
47 ShutdownSlaves(); // Ensure we did our cleanup. | 47 ShutdownSlaves(); // Ensure we did our cleanup. |
48 } | 48 } |
49 | 49 |
50 // ShutdownSlaves() gets all spawned threads to terminate, closes | 50 // ShutdownSlaves() gets all spawned threads to terminate, closes |
51 // their handles, and deletes their DnsSlave instances. | 51 // their handles, and deletes their DnsSlave instances. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 return results_[hostname].resolve_duration(); | 106 return results_[hostname].resolve_duration(); |
107 } | 107 } |
108 | 108 |
109 base::TimeDelta GetQueueDuration(const std::string hostname) { | 109 base::TimeDelta GetQueueDuration(const std::string hostname) { |
110 AutoLock auto_lock(lock_); | 110 AutoLock auto_lock(lock_); |
111 if (results_.find(hostname) == results_.end()) | 111 if (results_.find(hostname) == results_.end()) |
112 return DnsHostInfo::kNullDuration; | 112 return DnsHostInfo::kNullDuration; |
113 return results_[hostname].queue_duration(); | 113 return results_[hostname].queue_duration(); |
114 } | 114 } |
115 | 115 |
116 int running_slave_count() { | 116 size_t running_slave_count() { |
117 AutoLock auto_lock(lock_); | 117 AutoLock auto_lock(lock_); |
118 return running_slave_count_; | 118 return running_slave_count_; |
119 } | 119 } |
120 | 120 |
121 //---------------------------------------------------------------------------- | 121 //---------------------------------------------------------------------------- |
122 // Methods below this line should only be called by slave processes. | 122 // Methods below this line should only be called by slave processes. |
123 | 123 |
124 // GetNextAssignment() gets the next hostname from queue for processing | 124 // GetNextAssignment() gets the next hostname from queue for processing |
125 // It is not meant to be public, and should only be used by the slave. | 125 // It is not meant to be public, and should only be used by the slave. |
126 // GetNextAssignment() waits on a condition variable if there are no more | 126 // GetNextAssignment() waits on a condition variable if there are no more |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 164 |
165 // For each hostname that we might navigate to (that we've "learned about") | 165 // For each hostname that we might navigate to (that we've "learned about") |
166 // we have a Referrer list. Each Referrer list has all hostnames we need to | 166 // we have a Referrer list. Each Referrer list has all hostnames we need to |
167 // pre-resolve when there is a navigation to the orginial hostname. | 167 // pre-resolve when there is a navigation to the orginial hostname. |
168 Referrers referrers_; | 168 Referrers referrers_; |
169 | 169 |
170 // Signaling slaves to process elements in the queue, or to terminate, | 170 // Signaling slaves to process elements in the queue, or to terminate, |
171 // is done using ConditionVariables. | 171 // is done using ConditionVariables. |
172 ConditionVariable slaves_have_work_; | 172 ConditionVariable slaves_have_work_; |
173 | 173 |
174 int slave_count_; // Count of slave processes started. | 174 size_t slave_count_; // Count of slave processes started. |
175 int running_slave_count_; // Count of slaves process still running. | 175 size_t running_slave_count_; // Count of slaves process still running. |
176 | 176 |
177 // The following arrays are only initialized as | 177 // The following arrays are only initialized as |
178 // slave_count_ grows (up to the indicated max). | 178 // slave_count_ grows (up to the indicated max). |
179 DWORD thread_ids_[kSlaveCountMax]; | 179 DWORD thread_ids_[kSlaveCountMax]; |
180 HANDLE thread_handles_[kSlaveCountMax]; | 180 HANDLE thread_handles_[kSlaveCountMax]; |
181 DnsSlave* slaves_[kSlaveCountMax]; | 181 DnsSlave* slaves_[kSlaveCountMax]; |
182 | 182 |
183 // shutdown_ is set to tell the slaves to terminate. | 183 // shutdown_ is set to tell the slaves to terminate. |
184 bool shutdown_; | 184 bool shutdown_; |
185 | 185 |
186 // The following is the maximum time the ShutdownSlaves method | 186 // The following is the maximum time the ShutdownSlaves method |
187 // will wait for all the slave processes to terminate. | 187 // will wait for all the slave processes to terminate. |
188 const base::TimeDelta kShutdownWaitTime_; | 188 const base::TimeDelta kShutdownWaitTime_; |
189 | 189 |
190 // A list of successful events resulting from pre-fetching. | 190 // A list of successful events resulting from pre-fetching. |
191 DnsHostInfo::DnsInfoTable cache_hits_; | 191 DnsHostInfo::DnsInfoTable cache_hits_; |
192 // A map of hosts that were evicted from our cache (after we prefetched them) | 192 // A map of hosts that were evicted from our cache (after we prefetched them) |
193 // and before the HTTP stack tried to look them up. | 193 // and before the HTTP stack tried to look them up. |
194 Results cache_eviction_map_; | 194 Results cache_eviction_map_; |
195 | 195 |
196 DISALLOW_COPY_AND_ASSIGN(DnsMaster); | 196 DISALLOW_COPY_AND_ASSIGN(DnsMaster); |
197 }; | 197 }; |
198 | 198 |
199 } // namespace chrome_browser_net | 199 } // namespace chrome_browser_net |
200 | 200 |
201 #endif // CHROME_BROWSER_NET_DNS_MASTER_H_ | 201 #endif // CHROME_BROWSER_NET_DNS_MASTER_H_ |
202 | 202 |
OLD | NEW |