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_MOCK_HOST_RESOLVER_CREATOR_H_
6 #define EXTENSIONS_BROWSER_API_DNS_MOCK_HOST_RESOLVER_CREATOR_H_
10 #include "base/memory/ref_counted.h"
11 #include "base/synchronization/waitable_event.h"
15 class MockHostResolver
;
18 namespace extensions
{
20 // Used only for testing. Creates a MockHostResolver, respecting threading
22 class MockHostResolverCreator
23 : public base::RefCountedThreadSafe
<MockHostResolverCreator
> {
25 static const std::string kHostname
;
26 static const std::string kAddress
;
28 MockHostResolverCreator();
30 net::HostResolver
* CreateMockHostResolver();
31 void DeleteMockHostResolver();
34 friend class base::RefCountedThreadSafe
<MockHostResolverCreator
>;
35 virtual ~MockHostResolverCreator();
37 void CreateMockHostResolverOnIOThread();
38 void DeleteMockHostResolverOnIOThread();
40 base::WaitableEvent resolver_event_
;
42 // The MockHostResolver asserts that it's used on the same thread on which
43 // it's created, which is actually a stronger rule than its real counterpart.
44 // But that's fine; it's good practice.
46 // Plain pointer because we have to manage lifetime manually.
47 net::MockHostResolver
* mock_host_resolver_
;
50 } // namespace extensions
52 #endif // EXTENSIONS_BROWSER_API_DNS_MOCK_HOST_RESOLVER_CREATOR_H_