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

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

Issue 149511: Refactorings surrounding HostResolver:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Merge in socks5_client_socket_unittest.cc Created 11 years, 5 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
« no previous file with comments | « net/base/host_resolver_impl_unittest.cc ('k') | net/base/host_resolver_proc.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef NET_BASE_HOST_RESOLVER_PROC_H_
6 #define NET_BASE_HOST_RESOLVER_PROC_H_
7
8 #include <string>
9
10 #include "base/ref_counted.h"
11
12 namespace net {
13
14 class AddressList;
15
16 // Interface for a getaddrinfo()-like procedure. This is used by unit-tests
17 // to control the underlying resolutions in HostResolverImpl. HostResolverProcs
18 // can be chained together; they fallback to the next procedure in the chain
19 // by calling ResolveUsingPrevious().
20 //
21 // Note that implementations of HostResolverProc *MUST BE THREADSAFE*, since
22 // the HostResolver implementation using them can be multi-threaded.
23 class HostResolverProc : public base::RefCountedThreadSafe<HostResolverProc> {
24 public:
25 explicit HostResolverProc(HostResolverProc* previous);
26 virtual ~HostResolverProc() {}
27
28 // Resolves |host| to an address list. If successful returns OK and fills
29 // |addrlist| with a list of socket addresses. Otherwise returns a
30 // network error code.
31 virtual int Resolve(const std::string& host, AddressList* addrlist) = 0;
32
33 protected:
34 // Asks the fallback procedure (if set) to do the resolve.
35 int ResolveUsingPrevious(const std::string& host, AddressList* addrlist);
36
37 private:
38 friend class HostResolverImpl;
39 friend class MockHostResolver;
40 friend class ScopedDefaultHostResolverProc;
41
42 // Sets the previous procedure in the chain.
43 void set_previous_proc(HostResolverProc* proc) {
44 previous_proc_ = proc;
45 }
46
47 // Sets the default host resolver procedure that is used by HostResolverImpl.
48 // This can be used through ScopedDefaultHostResolverProc to set a catch-all
49 // DNS block in unit-tests (individual tests should use MockHostResolver to
50 // prevent hitting the network).
51 static HostResolverProc* SetDefault(HostResolverProc* proc);
52 static HostResolverProc* GetDefault();
53
54 private:
55 scoped_refptr<HostResolverProc> previous_proc_;
56 static HostResolverProc* default_proc_;
57
58 DISALLOW_COPY_AND_ASSIGN(HostResolverProc);
59 };
60
61 // 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
63 // |addrlist| with a list of socket addresses. Otherwise returns a
64 // network error code.
65 int SystemHostResolverProc(const std::string& host, AddressList* addrlist);
66
67 } // namespace net
68
69 #endif // NET_BASE_HOST_RESOLVER_PROC_H_
OLDNEW
« no previous file with comments | « net/base/host_resolver_impl_unittest.cc ('k') | net/base/host_resolver_proc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698