blob: 35732bc21f9558749c0ac74114c2e12f042cc162 [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
Avi Drissman13fc8932015-12-20 04:40:468#include "base/macros.h"
sammc6119a59c2015-04-01 06:56:529#include "base/memory/weak_ptr.h"
sammc6ac3fe52015-02-25 06:00:2810#include "base/threading/thread_checker.h"
sammc6119a59c2015-04-01 06:56:5211#include "net/dns/host_cache.h"
sammc6ac3fe52015-02-25 06:00:2812#include "net/dns/host_resolver.h"
13#include "net/interfaces/host_resolver_service.mojom.h"
sammc6ac3fe52015-02-25 06:00:2814
15namespace net {
16class AddressList;
17class BoundNetLog;
18
sammca3242c92015-07-10 02:38:5119// A HostResolver implementation that converts requests to mojo types and
20// forwards them to a mojo Impl interface.
amistry39230722015-07-03 00:24:3921class HostResolverMojo : public HostResolver {
sammc6ac3fe52015-02-25 06:00:2822 public:
sammca3242c92015-07-10 02:38:5123 class Impl {
24 public:
25 virtual ~Impl() = default;
26 virtual void ResolveDns(interfaces::HostResolverRequestInfoPtr,
27 interfaces::HostResolverRequestClientPtr) = 0;
28 };
29
30 // |impl| must outlive |this|.
31 explicit HostResolverMojo(Impl* impl);
sammc6ac3fe52015-02-25 06:00:2832 ~HostResolverMojo() override;
33
34 // HostResolver overrides.
juliatuttlec53b19a72016-05-05 13:51:3135 // Note: |Resolve()| currently ignores |priority|.
sammc6ac3fe52015-02-25 06:00:2836 int Resolve(const RequestInfo& info,
37 RequestPriority priority,
38 AddressList* addresses,
39 const CompletionCallback& callback,
maksim.sisov31452af2016-07-27 06:38:1040 std::unique_ptr<Request>* request,
sammc6ac3fe52015-02-25 06:00:2841 const BoundNetLog& source_net_log) override;
42 int ResolveFromCache(const RequestInfo& info,
43 AddressList* addresses,
44 const BoundNetLog& source_net_log) override;
sammc6119a59c2015-04-01 06:56:5245 HostCache* GetHostCache() override;
sammc6ac3fe52015-02-25 06:00:2846
47 private:
48 class Job;
maksim.sisov31452af2016-07-27 06:38:1049 class RequestImpl;
sammc6ac3fe52015-02-25 06:00:2850
sammc6119a59c2015-04-01 06:56:5251 int ResolveFromCacheInternal(const RequestInfo& info,
52 const HostCache::Key& key,
53 AddressList* addresses);
54
sammca3242c92015-07-10 02:38:5155 Impl* const impl_;
sammc6ac3fe52015-02-25 06:00:2856
danakj22f90e72016-04-16 01:55:4057 std::unique_ptr<HostCache> host_cache_;
sammc6119a59c2015-04-01 06:56:5258 base::WeakPtrFactory<HostCache> host_cache_weak_factory_;
59
sammc6ac3fe52015-02-25 06:00:2860 base::ThreadChecker thread_checker_;
61
62 DISALLOW_COPY_AND_ASSIGN(HostResolverMojo);
63};
64
65} // namespace net
66
67#endif // NET_DNS_HOST_RESOLVER_MOJO_H_