| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // A DnsSlave object processes hostname lookups |
| 6 // via DNS on a single thread, waiting for that blocking |
| 7 // call to complete, and then getting its next hostname |
| 8 // from its associated DnsMaster object. |
| 9 // Since this class only is concerned with prefetching |
| 10 // to warm the underlying DNS cache, the actual IP |
| 11 // does not need to be recorded. It is necessary to record |
| 12 // when the lookup finished, so that the associated DnsMaster |
| 13 // won't (wastefully) ask for the same name in "too short a |
| 14 // period of time." |
| 15 // This class does no "de-duping," and merely slavishly services |
| 16 // items supplied by its DnsMaster. |
| 17 |
| 18 #ifndef CHROME_BROWSER_NET_DNS_SLAVE_H_ |
| 19 #define CHROME_BROWSER_NET_DNS_SLAVE_H_ |
| 20 |
| 21 #include <windows.h> |
| 22 #include <string> |
| 23 |
| 24 #include "base/basictypes.h" |
| 25 |
| 26 namespace chrome_browser_net { |
| 27 |
| 28 class DnsMaster; |
| 29 class DnsSlave; |
| 30 |
| 31 // Support testing infrastructure, and allow off-line testing. |
| 32 typedef void (__stdcall *FreeAddrInfoFunction)(struct addrinfo* ai); |
| 33 typedef int (__stdcall *GetAddrInfoFunction)(const char* nodename, |
| 34 const char* servname, |
| 35 const struct addrinfo* hints, |
| 36 struct addrinfo** result); |
| 37 void SetAddrinfoCallbacks(GetAddrInfoFunction getaddrinfo, |
| 38 FreeAddrInfoFunction freeaddrinfo); |
| 39 |
| 40 GetAddrInfoFunction get_getaddrinfo(); |
| 41 FreeAddrInfoFunction get_freeaddrinfo(); |
| 42 |
| 43 class DnsSlave { |
| 44 public: |
| 45 DnsSlave(DnsMaster* master, size_t slave_index) |
| 46 : master_(master), |
| 47 slave_index_(slave_index) { |
| 48 } |
| 49 |
| 50 ~DnsSlave() { |
| 51 master_ = NULL; |
| 52 } |
| 53 |
| 54 static DWORD WINAPI ThreadStart(void* pThis); |
| 55 |
| 56 unsigned Run(); |
| 57 |
| 58 private: |
| 59 std::string hostname_; // Name being looked up. |
| 60 |
| 61 DnsMaster* master_; // Master that started us. |
| 62 size_t slave_index_; // Our index into DnsMaster's array. |
| 63 |
| 64 void BlockingDnsLookup(); |
| 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(DnsSlave); |
| 67 }; |
| 68 |
| 69 } // namespace chrome_browser_net |
| 70 |
| 71 #endif // CHROME_BROWSER_NET_DNS_SLAVE_H_ |
| 72 |
| OLD | NEW |