blob: 89511e4f5ac9081f1a61ec2eb34bca3f35348a2a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef EXTENSIONS_BROWSER_API_DNS_HOST_RESOLVER_WRAPPER_H_
#define EXTENSIONS_BROWSER_API_DNS_HOST_RESOLVER_WRAPPER_H_
#include "base/memory/singleton.h"
namespace content {
class ResourceContext;
}
namespace net {
class HostResolver;
}
namespace extensions {
// Used for testing. In production code, this class does nothing interesting.
// This class is a singleton that holds a pointer to a mock HostResolver, or
// else to NULL. API classes that need to resolve hostnames ask this class for
// the correct HostResolver to use, passing in the one that they want to use,
// thereby avoiding most lifetime issues, and it will reply with either that
// same one, or else the test version to use instead.
//
// This is a pretty complicated way to replace a single pointer with another.
// TODO(miket): make the previous statement obsolete.
class HostResolverWrapper {
public:
static HostResolverWrapper* GetInstance();
// Given a pointer to a ResourceContext, returns its HostResolver if
// SetHostResolverForTesting() hasn't been called, or else a
// a substitute MockHostResolver to use instead.
net::HostResolver* GetHostResolver(content::ResourceContext* context);
// Sets the MockHostResolver to return in GetHostResolver().
void SetHostResolverForTesting(net::HostResolver* mock_resolver);
private:
HostResolverWrapper();
friend struct DefaultSingletonTraits<HostResolverWrapper>;
net::HostResolver* resolver_;
DISALLOW_COPY_AND_ASSIGN(HostResolverWrapper);
};
} // namespace extensions
#endif // EXTENSIONS_BROWSER_API_DNS_HOST_RESOLVER_WRAPPER_H_
|