blob: 23fb0ff0c8bc0f0f30f14ccfa49ae91fdabdf8e5 [file] [log] [blame]
sammc6ac3fe52015-02-25 06:00:281// 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.
4
5#ifndef NET_DNS_HOST_RESOLVER_MOJO_H_
6#define NET_DNS_HOST_RESOLVER_MOJO_H_
7
sammc6119a59c2015-04-01 06:56:528#include "base/memory/weak_ptr.h"
sammc6ac3fe52015-02-25 06:00:289#include "base/threading/thread_checker.h"
sammc6119a59c2015-04-01 06:56:5210#include "net/dns/host_cache.h"
sammc6ac3fe52015-02-25 06:00:2811#include "net/dns/host_resolver.h"
12#include "net/interfaces/host_resolver_service.mojom.h"
sammc6ac3fe52015-02-25 06:00:2813
14namespace net {
15class AddressList;
16class BoundNetLog;
17
sammca3242c92015-07-10 02:38:5118// A HostResolver implementation that converts requests to mojo types and
19// forwards them to a mojo Impl interface.
amistry39230722015-07-03 00:24:3920class HostResolverMojo : public HostResolver {
sammc6ac3fe52015-02-25 06:00:2821 public:
sammca3242c92015-07-10 02:38:5122 class Impl {
23 public:
24 virtual ~Impl() = default;
25 virtual void ResolveDns(interfaces::HostResolverRequestInfoPtr,
26 interfaces::HostResolverRequestClientPtr) = 0;
27 };
28
29 // |impl| must outlive |this|.
30 explicit HostResolverMojo(Impl* impl);
sammc6ac3fe52015-02-25 06:00:2831 ~HostResolverMojo() override;
32
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;
sammc6119a59c2015-04-01 06:56:5244 HostCache* GetHostCache() override;
sammc6ac3fe52015-02-25 06:00:2845
46 private:
47 class Job;
48
sammc6119a59c2015-04-01 06:56:5249 int ResolveFromCacheInternal(const RequestInfo& info,
50 const HostCache::Key& key,
51 AddressList* addresses);
52
sammca3242c92015-07-10 02:38:5153 Impl* const impl_;
sammc6ac3fe52015-02-25 06:00:2854
sammc6119a59c2015-04-01 06:56:5255 scoped_ptr<HostCache> host_cache_;
56 base::WeakPtrFactory<HostCache> host_cache_weak_factory_;
57
sammc6ac3fe52015-02-25 06:00:2858 base::ThreadChecker thread_checker_;
59
60 DISALLOW_COPY_AND_ASSIGN(HostResolverMojo);
61};
62
63} // namespace net
64
65#endif // NET_DNS_HOST_RESOLVER_MOJO_H_