Finish refactoring of DomCodeToUsLayoutKeyboardCode().
[chromium-blink-merge.git] / extensions / browser / api / dns / host_resolver_wrapper.h
blob89511e4f5ac9081f1a61ec2eb34bca3f35348a2a
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"
10 namespace content {
11 class ResourceContext;
14 namespace net {
15 class HostResolver;
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 {
30 public:
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);
41 private:
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_