Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: net/base/host_resolver_proc.h

Issue 302010: Add a mechanism to disable IPv6.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Address darin's comments Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #ifndef NET_BASE_HOST_RESOLVER_PROC_H_ 5 #ifndef NET_BASE_HOST_RESOLVER_PROC_H_
6 #define NET_BASE_HOST_RESOLVER_PROC_H_ 6 #define NET_BASE_HOST_RESOLVER_PROC_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/ref_counted.h" 10 #include "base/ref_counted.h"
11 #include "net/base/address_family.h"
11 12
12 namespace net { 13 namespace net {
13 14
14 class AddressList; 15 class AddressList;
15 16
16 // Interface for a getaddrinfo()-like procedure. This is used by unit-tests 17 // Interface for a getaddrinfo()-like procedure. This is used by unit-tests
17 // to control the underlying resolutions in HostResolverImpl. HostResolverProcs 18 // to control the underlying resolutions in HostResolverImpl. HostResolverProcs
18 // can be chained together; they fallback to the next procedure in the chain 19 // can be chained together; they fallback to the next procedure in the chain
19 // by calling ResolveUsingPrevious(). 20 // by calling ResolveUsingPrevious().
20 // 21 //
21 // Note that implementations of HostResolverProc *MUST BE THREADSAFE*, since 22 // Note that implementations of HostResolverProc *MUST BE THREADSAFE*, since
22 // the HostResolver implementation using them can be multi-threaded. 23 // the HostResolver implementation using them can be multi-threaded.
23 class HostResolverProc : public base::RefCountedThreadSafe<HostResolverProc> { 24 class HostResolverProc : public base::RefCountedThreadSafe<HostResolverProc> {
24 public: 25 public:
25 explicit HostResolverProc(HostResolverProc* previous); 26 explicit HostResolverProc(HostResolverProc* previous);
26 virtual ~HostResolverProc() {} 27 virtual ~HostResolverProc() {}
27 28
28 // Resolves |host| to an address list. If successful returns OK and fills 29 // Resolves |host| to an address list, restricting the results to addresses
29 // |addrlist| with a list of socket addresses. Otherwise returns a 30 // in |address_family|. If successful returns OK and fills |addrlist| with
30 // network error code. 31 // a list of socket addresses. Otherwise returns a network error code.
31 virtual int Resolve(const std::string& host, AddressList* addrlist) = 0; 32 virtual int Resolve(const std::string& host,
33 AddressFamily address_family,
34 AddressList* addrlist) = 0;
32 35
33 protected: 36 protected:
34 // Asks the fallback procedure (if set) to do the resolve. 37 // Asks the fallback procedure (if set) to do the resolve.
35 int ResolveUsingPrevious(const std::string& host, AddressList* addrlist); 38 int ResolveUsingPrevious(const std::string& host,
39 AddressFamily address_family,
40 AddressList* addrlist);
36 41
37 private: 42 private:
38 friend class HostResolverImpl; 43 friend class HostResolverImpl;
39 friend class MockHostResolverBase; 44 friend class MockHostResolverBase;
40 friend class ScopedDefaultHostResolverProc; 45 friend class ScopedDefaultHostResolverProc;
41 46
42 // Sets the previous procedure in the chain. 47 // Sets the previous procedure in the chain.
43 void set_previous_proc(HostResolverProc* proc) { 48 void set_previous_proc(HostResolverProc* proc) {
44 previous_proc_ = proc; 49 previous_proc_ = proc;
45 } 50 }
46 51
47 // Sets the default host resolver procedure that is used by HostResolverImpl. 52 // Sets the default host resolver procedure that is used by HostResolverImpl.
48 // This can be used through ScopedDefaultHostResolverProc to set a catch-all 53 // This can be used through ScopedDefaultHostResolverProc to set a catch-all
49 // DNS block in unit-tests (individual tests should use MockHostResolver to 54 // DNS block in unit-tests (individual tests should use MockHostResolver to
50 // prevent hitting the network). 55 // prevent hitting the network).
51 static HostResolverProc* SetDefault(HostResolverProc* proc); 56 static HostResolverProc* SetDefault(HostResolverProc* proc);
52 static HostResolverProc* GetDefault(); 57 static HostResolverProc* GetDefault();
53 58
54 private: 59 private:
55 scoped_refptr<HostResolverProc> previous_proc_; 60 scoped_refptr<HostResolverProc> previous_proc_;
56 static HostResolverProc* default_proc_; 61 static HostResolverProc* default_proc_;
57 62
58 DISALLOW_COPY_AND_ASSIGN(HostResolverProc); 63 DISALLOW_COPY_AND_ASSIGN(HostResolverProc);
59 }; 64 };
60 65
61 // Resolves |host| to an address list, using the system's default host resolver. 66 // Resolves |host| to an address list, using the system's default host resolver.
62 // (i.e. this calls out to getaddrinfo()). If successful returns OK and fills 67 // (i.e. this calls out to getaddrinfo()). If successful returns OK and fills
63 // |addrlist| with a list of socket addresses. Otherwise returns a 68 // |addrlist| with a list of socket addresses. Otherwise returns a
64 // network error code. 69 // network error code.
65 int SystemHostResolverProc(const std::string& host, AddressList* addrlist); 70 int SystemHostResolverProc(const std::string& host,
71 AddressFamily address_family,
72 AddressList* addrlist);
66 73
67 } // namespace net 74 } // namespace net
68 75
69 #endif // NET_BASE_HOST_RESOLVER_PROC_H_ 76 #endif // NET_BASE_HOST_RESOLVER_PROC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698