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

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

Issue 992733002: Remove //net (except for Android test stuff) and sdch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « net/dns/host_resolver_impl_unittest.cc ('k') | net/dns/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')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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_DNS_HOST_RESOLVER_PROC_H_
6 #define NET_DNS_HOST_RESOLVER_PROC_H_
7
8 #include <string>
9
10 #include "base/memory/ref_counted.h"
11 #include "net/base/address_family.h"
12 #include "net/base/net_export.h"
13
14 namespace net {
15
16 class AddressList;
17
18 // Interface for a getaddrinfo()-like procedure. This is used by unit-tests
19 // to control the underlying resolutions in HostResolverImpl. HostResolverProcs
20 // can be chained together; they fallback to the next procedure in the chain
21 // by calling ResolveUsingPrevious().
22 //
23 // Note that implementations of HostResolverProc *MUST BE THREADSAFE*, since
24 // the HostResolver implementation using them can be multi-threaded.
25 class NET_EXPORT HostResolverProc
26 : public base::RefCountedThreadSafe<HostResolverProc> {
27 public:
28 explicit HostResolverProc(HostResolverProc* previous);
29
30 // Resolves |host| to an address list, restricting the results to addresses
31 // in |address_family|. If successful returns OK and fills |addrlist| with
32 // a list of socket addresses. Otherwise returns a network error code, and
33 // fills |os_error| with a more specific error if it was non-NULL.
34 virtual int Resolve(const std::string& host,
35 AddressFamily address_family,
36 HostResolverFlags host_resolver_flags,
37 AddressList* addrlist,
38 int* os_error) = 0;
39
40 protected:
41 friend class base::RefCountedThreadSafe<HostResolverProc>;
42
43 virtual ~HostResolverProc();
44
45 // Asks the fallback procedure (if set) to do the resolve.
46 int ResolveUsingPrevious(const std::string& host,
47 AddressFamily address_family,
48 HostResolverFlags host_resolver_flags,
49 AddressList* addrlist,
50 int* os_error);
51
52 private:
53 friend class HostResolverImpl;
54 friend class MockHostResolverBase;
55 friend class ScopedDefaultHostResolverProc;
56
57 // Sets the previous procedure in the chain. Aborts if this would result in a
58 // cycle.
59 void SetPreviousProc(HostResolverProc* proc);
60
61 // Sets the last procedure in the chain, i.e. appends |proc| to the end of the
62 // current chain. Aborts if this would result in a cycle.
63 void SetLastProc(HostResolverProc* proc);
64
65 // Returns the last procedure in the chain starting at |proc|. Will return
66 // NULL iff |proc| is NULL.
67 static HostResolverProc* GetLastProc(HostResolverProc* proc);
68
69 // Sets the default host resolver procedure that is used by HostResolverImpl.
70 // This can be used through ScopedDefaultHostResolverProc to set a catch-all
71 // DNS block in unit-tests (individual tests should use MockHostResolver to
72 // prevent hitting the network).
73 static HostResolverProc* SetDefault(HostResolverProc* proc);
74 static HostResolverProc* GetDefault();
75
76 scoped_refptr<HostResolverProc> previous_proc_;
77 static HostResolverProc* default_proc_;
78
79 DISALLOW_COPY_AND_ASSIGN(HostResolverProc);
80 };
81
82 // Resolves |host| to an address list, using the system's default host resolver.
83 // (i.e. this calls out to getaddrinfo()). If successful returns OK and fills
84 // |addrlist| with a list of socket addresses. Otherwise returns a
85 // network error code, and fills |os_error| with a more specific error if it
86 // was non-NULL.
87 NET_EXPORT_PRIVATE int SystemHostResolverCall(
88 const std::string& host,
89 AddressFamily address_family,
90 HostResolverFlags host_resolver_flags,
91 AddressList* addrlist,
92 int* os_error);
93
94 // Wraps call to SystemHostResolverCall as an instance of HostResolverProc.
95 class NET_EXPORT_PRIVATE SystemHostResolverProc : public HostResolverProc {
96 public:
97 SystemHostResolverProc();
98 int Resolve(const std::string& hostname,
99 AddressFamily address_family,
100 HostResolverFlags host_resolver_flags,
101 AddressList* addr_list,
102 int* os_error) override;
103
104 protected:
105 ~SystemHostResolverProc() override;
106
107 DISALLOW_COPY_AND_ASSIGN(SystemHostResolverProc);
108 };
109
110 } // namespace net
111
112 #endif // NET_DNS_HOST_RESOLVER_PROC_H_
OLDNEW
« no previous file with comments | « net/dns/host_resolver_impl_unittest.cc ('k') | net/dns/host_resolver_proc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698