| 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 manages asynchronous resolution of DNS hostnames. | 6 // process, and manages asynchronous resolution of DNS hostnames. |
| 7 // Most hostname lists are sent out by renderer processes, and | 7 // Most hostname lists are sent out by renderer processes, and |
| 8 // involve lists of hostnames that *might* be used in the near | 8 // involve lists of hostnames that *might* be used in the near |
| 9 // future by the browsing user. The goal of this class is to | 9 // future by the browsing user. The goal of this class is to |
| 10 // cause the underlying DNS structure to lookup a hostname before | 10 // cause the underlying DNS structure to lookup a hostname before |
| 11 // it is really needed, and hence reduce latency in the standard | 11 // it is really needed, and hence reduce latency in the standard |
| 12 // lookup paths. | 12 // lookup paths. |
| 13 | 13 |
| 14 #ifndef CHROME_BROWSER_NET_DNS_MASTER_H_ | 14 #ifndef CHROME_BROWSER_NET_DNS_MASTER_H_ |
| 15 #define CHROME_BROWSER_NET_DNS_MASTER_H_ | 15 #define CHROME_BROWSER_NET_DNS_MASTER_H_ |
| 16 | 16 |
| 17 #include <map> | 17 #include <map> |
| 18 #include <queue> | 18 #include <queue> |
| 19 #include <set> | 19 #include <set> |
| 20 #include <string> | 20 #include <string> |
| 21 | 21 |
| 22 #include "base/lock.h" | 22 #include "base/lock.h" |
| 23 #include "base/ref_counted.h" | 23 #include "base/ref_counted.h" |
| 24 #include "chrome/browser/net/dns_host_info.h" | 24 #include "chrome/browser/net/dns_host_info.h" |
| 25 #include "chrome/browser/net/referrer.h" | 25 #include "chrome/browser/net/referrer.h" |
| 26 #include "chrome/common/net/dns.h" | 26 #include "chrome/common/net/dns.h" |
| 27 #include "testing/gtest/include/gtest/gtest_prod.h" | 27 #include "testing/gtest/include/gtest/gtest_prod.h" |
| 28 | 28 |
| 29 using base::TimeDelta; |
| 30 |
| 29 namespace net { | 31 namespace net { |
| 30 class HostResolver; | 32 class HostResolver; |
| 31 } | 33 } |
| 32 | 34 |
| 33 class MessageLoop; | 35 class MessageLoop; |
| 34 | 36 |
| 35 namespace chrome_browser_net { | 37 namespace chrome_browser_net { |
| 36 | 38 |
| 37 typedef chrome_common_net::NameList NameList; | 39 typedef chrome_common_net::NameList NameList; |
| 38 typedef std::map<std::string, DnsHostInfo> Results; | 40 typedef std::map<std::string, DnsHostInfo> Results; |
| 39 | 41 |
| 40 class DnsMaster : public base::RefCountedThreadSafe<DnsMaster> { | 42 class DnsMaster : public base::RefCountedThreadSafe<DnsMaster> { |
| 41 public: | 43 public: |
| 42 // |max_concurrent| specifies how many concurrent (paralell) prefetches will | 44 // |max_concurrent| specifies how many concurrent (paralell) prefetches will |
| 43 // be performed. Host lookups will be issued on the |host_resolver_loop| | 45 // be performed. Host lookups will be issued on the |host_resolver_loop| |
| 44 // thread, using the |host_resolver| instance. | 46 // thread, using the |host_resolver| instance. |
| 45 DnsMaster(net::HostResolver* host_resolver, | 47 DnsMaster(net::HostResolver* host_resolver, MessageLoop* host_resolver_loop, |
| 46 MessageLoop* host_resolver_loop, | 48 TimeDelta max_queue_delay_ms, size_t max_concurrent); |
| 47 size_t max_concurrent); | |
| 48 ~DnsMaster(); | 49 ~DnsMaster(); |
| 49 | 50 |
| 50 // Cancel pending requests and prevent new ones from being made. | 51 // Cancel pending requests and prevent new ones from being made. |
| 51 void Shutdown(); | 52 void Shutdown(); |
| 52 | 53 |
| 53 // In some circumstances, for privacy reasons, all results should be | 54 // In some circumstances, for privacy reasons, all results should be |
| 54 // discarded. This method gracefully handles that activity. | 55 // discarded. This method gracefully handles that activity. |
| 55 // Destroy all our internal state, which shows what names we've looked up, and | 56 // Destroy all our internal state, which shows what names we've looked up, and |
| 56 // how long each has taken, etc. etc. We also destroy records of suggesses | 57 // how long each has taken, etc. etc. We also destroy records of suggesses |
| 57 // (cache hits etc.). | 58 // (cache hits etc.). |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 | 221 |
| 221 // A list of successful events resulting from pre-fetching. | 222 // A list of successful events resulting from pre-fetching. |
| 222 DnsHostInfo::DnsInfoTable cache_hits_; | 223 DnsHostInfo::DnsInfoTable cache_hits_; |
| 223 // A map of hosts that were evicted from our cache (after we prefetched them) | 224 // A map of hosts that were evicted from our cache (after we prefetched them) |
| 224 // and before the HTTP stack tried to look them up. | 225 // and before the HTTP stack tried to look them up. |
| 225 Results cache_eviction_map_; | 226 Results cache_eviction_map_; |
| 226 | 227 |
| 227 // The number of concurrent lookups currently allowed. | 228 // The number of concurrent lookups currently allowed. |
| 228 const size_t max_concurrent_lookups_; | 229 const size_t max_concurrent_lookups_; |
| 229 | 230 |
| 231 // The maximum queueing delay that is acceptable before we enter congestion |
| 232 // reduction mode, and discard all queued (but not yet assigned) resolutions. |
| 233 const TimeDelta max_queue_delay_; |
| 234 |
| 230 // The host resovler we warm DNS entries for. The resolver (which is not | 235 // The host resovler we warm DNS entries for. The resolver (which is not |
| 231 // thread safe) should be accessed only on |host_resolver_loop_|. | 236 // thread safe) should be accessed only on |host_resolver_loop_|. |
| 232 scoped_refptr<net::HostResolver> host_resolver_; | 237 scoped_refptr<net::HostResolver> host_resolver_; |
| 233 MessageLoop* host_resolver_loop_; | 238 MessageLoop* host_resolver_loop_; |
| 234 | 239 |
| 235 DISALLOW_COPY_AND_ASSIGN(DnsMaster); | 240 DISALLOW_COPY_AND_ASSIGN(DnsMaster); |
| 236 }; | 241 }; |
| 237 | 242 |
| 238 } // namespace chrome_browser_net | 243 } // namespace chrome_browser_net |
| 239 | 244 |
| 240 #endif // CHROME_BROWSER_NET_DNS_MASTER_H_ | 245 #endif // CHROME_BROWSER_NET_DNS_MASTER_H_ |
| OLD | NEW |