1 // Copyright 2014 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.
5 #ifndef EXTENSIONS_BROWSER_API_DNS_HOST_RESOLVER_WRAPPER_H_
6 #define EXTENSIONS_BROWSER_API_DNS_HOST_RESOLVER_WRAPPER_H_
8 #include "base/memory/singleton.h"
11 class ResourceContext
;
18 namespace extensions
{
20 // Used for testing. In production code, this class does nothing interesting.
21 // This class is a singleton that holds a pointer to a mock HostResolver, or
22 // else to NULL. API classes that need to resolve hostnames ask this class for
23 // the correct HostResolver to use, passing in the one that they want to use,
24 // thereby avoiding most lifetime issues, and it will reply with either that
25 // same one, or else the test version to use instead.
27 // This is a pretty complicated way to replace a single pointer with another.
28 // TODO(miket): make the previous statement obsolete.
29 class HostResolverWrapper
{
31 static HostResolverWrapper
* GetInstance();
33 // Given a pointer to a ResourceContext, returns its HostResolver if
34 // SetHostResolverForTesting() hasn't been called, or else a
35 // a substitute MockHostResolver to use instead.
36 net::HostResolver
* GetHostResolver(content::ResourceContext
* context
);
38 // Sets the MockHostResolver to return in GetHostResolver().
39 void SetHostResolverForTesting(net::HostResolver
* mock_resolver
);
42 HostResolverWrapper();
43 friend struct DefaultSingletonTraits
<HostResolverWrapper
>;
45 net::HostResolver
* resolver_
;
47 DISALLOW_COPY_AND_ASSIGN(HostResolverWrapper
);
50 } // namespace extensions
52 #endif // EXTENSIONS_BROWSER_API_DNS_HOST_RESOLVER_WRAPPER_H_