blob: 602660adb8e0cf38fb77cb04c66cb8902d41f96c [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;
tfarina42834112016-09-22 13:38:2017class NetLogWithSource;
sammc6ac3fe52015-02-25 06:00:2818
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;
sammc170917f2016-10-09 23:26:0426 virtual void ResolveDns(
27 std::unique_ptr<HostResolver::RequestInfo> request_info,
28 interfaces::HostResolverRequestClientPtr) = 0;
sammca3242c92015-07-10 02:38:5129 };
30
31 // |impl| must outlive |this|.
32 explicit HostResolverMojo(Impl* impl);
sammc6ac3fe52015-02-25 06:00:2833 ~HostResolverMojo() override;
34
35 // HostResolver overrides.
juliatuttlec53b19a72016-05-05 13:51:3136 // Note: |Resolve()| currently ignores |priority|.
sammc6ac3fe52015-02-25 06:00:2837 int Resolve(const RequestInfo& info,
38 RequestPriority priority,
39 AddressList* addresses,
40 const CompletionCallback& callback,
maksim.sisov31452af2016-07-27 06:38:1041 std::unique_ptr<Request>* request,
tfarina42834112016-09-22 13:38:2042 const NetLogWithSource& source_net_log) override;
sammc6ac3fe52015-02-25 06:00:2843 int ResolveFromCache(const RequestInfo& info,
44 AddressList* addresses,
tfarina42834112016-09-22 13:38:2045 const NetLogWithSource& source_net_log) override;
sammc6119a59c2015-04-01 06:56:5246 HostCache* GetHostCache() override;
sammc6ac3fe52015-02-25 06:00:2847
48 private:
49 class Job;
maksim.sisov31452af2016-07-27 06:38:1050 class RequestImpl;
sammc6ac3fe52015-02-25 06:00:2851
sammc6119a59c2015-04-01 06:56:5252 int ResolveFromCacheInternal(const RequestInfo& info,
53 const HostCache::Key& key,
54 AddressList* addresses);
55
sammca3242c92015-07-10 02:38:5156 Impl* const impl_;
sammc6ac3fe52015-02-25 06:00:2857
danakj22f90e72016-04-16 01:55:4058 std::unique_ptr<HostCache> host_cache_;
sammc6119a59c2015-04-01 06:56:5259 base::WeakPtrFactory<HostCache> host_cache_weak_factory_;
60
sammc6ac3fe52015-02-25 06:00:2861 base::ThreadChecker thread_checker_;
62
63 DISALLOW_COPY_AND_ASSIGN(HostResolverMojo);
64};
65
66} // namespace net
67
68#endif // NET_DNS_HOST_RESOLVER_MOJO_H_