Evict resources from resource pool after timeout
[chromium-blink-merge.git] / net / dns / host_resolver_mojo.h
blob23fb0ff0c8bc0f0f30f14ccfa49ae91fdabdf8e5
1 // Copyright 2015 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 NET_DNS_HOST_RESOLVER_MOJO_H_
6 #define NET_DNS_HOST_RESOLVER_MOJO_H_
8 #include "base/memory/weak_ptr.h"
9 #include "base/threading/thread_checker.h"
10 #include "net/dns/host_cache.h"
11 #include "net/dns/host_resolver.h"
12 #include "net/interfaces/host_resolver_service.mojom.h"
14 namespace net {
15 class AddressList;
16 class BoundNetLog;
18 // A HostResolver implementation that converts requests to mojo types and
19 // forwards them to a mojo Impl interface.
20 class HostResolverMojo : public HostResolver {
21 public:
22 class Impl {
23 public:
24 virtual ~Impl() = default;
25 virtual void ResolveDns(interfaces::HostResolverRequestInfoPtr,
26 interfaces::HostResolverRequestClientPtr) = 0;
29 // |impl| must outlive |this|.
30 explicit HostResolverMojo(Impl* impl);
31 ~HostResolverMojo() override;
33 // HostResolver overrides.
34 int Resolve(const RequestInfo& info,
35 RequestPriority priority,
36 AddressList* addresses,
37 const CompletionCallback& callback,
38 RequestHandle* request_handle,
39 const BoundNetLog& source_net_log) override;
40 int ResolveFromCache(const RequestInfo& info,
41 AddressList* addresses,
42 const BoundNetLog& source_net_log) override;
43 void CancelRequest(RequestHandle req) override;
44 HostCache* GetHostCache() override;
46 private:
47 class Job;
49 int ResolveFromCacheInternal(const RequestInfo& info,
50 const HostCache::Key& key,
51 AddressList* addresses);
53 Impl* const impl_;
55 scoped_ptr<HostCache> host_cache_;
56 base::WeakPtrFactory<HostCache> host_cache_weak_factory_;
58 base::ThreadChecker thread_checker_;
60 DISALLOW_COPY_AND_ASSIGN(HostResolverMojo);
63 } // namespace net
65 #endif // NET_DNS_HOST_RESOLVER_MOJO_H_