sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 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. |
| 4 | |
| 5 | #ifndef NET_DNS_HOST_RESOLVER_MOJO_H_ |
| 6 | #define NET_DNS_HOST_RESOLVER_MOJO_H_ |
| 7 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 8 | #include "base/macros.h" |
sammc | 6119a59c | 2015-04-01 06:56:52 | [diff] [blame] | 9 | #include "base/memory/weak_ptr.h" |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 10 | #include "base/threading/thread_checker.h" |
sammc | 6119a59c | 2015-04-01 06:56:52 | [diff] [blame] | 11 | #include "net/dns/host_cache.h" |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 12 | #include "net/dns/host_resolver.h" |
| 13 | #include "net/interfaces/host_resolver_service.mojom.h" |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 14 | |
| 15 | namespace net { |
| 16 | class AddressList; |
| 17 | class BoundNetLog; |
| 18 | |
sammc | a3242c9 | 2015-07-10 02:38:51 | [diff] [blame] | 19 | // A HostResolver implementation that converts requests to mojo types and |
| 20 | // forwards them to a mojo Impl interface. |
amistry | 3923072 | 2015-07-03 00:24:39 | [diff] [blame] | 21 | class HostResolverMojo : public HostResolver { |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 22 | public: |
sammc | a3242c9 | 2015-07-10 02:38:51 | [diff] [blame] | 23 | 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); |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 32 | ~HostResolverMojo() override; |
| 33 | |
| 34 | // HostResolver overrides. |
juliatuttle | c53b19a7 | 2016-05-05 13:51:31 | [diff] [blame] | 35 | // Note: |Resolve()| currently ignores |priority|. |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 36 | int Resolve(const RequestInfo& info, |
| 37 | RequestPriority priority, |
| 38 | AddressList* addresses, |
| 39 | const CompletionCallback& callback, |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame^] | 40 | std::unique_ptr<Request>* request, |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 41 | const BoundNetLog& source_net_log) override; |
| 42 | int ResolveFromCache(const RequestInfo& info, |
| 43 | AddressList* addresses, |
| 44 | const BoundNetLog& source_net_log) override; |
sammc | 6119a59c | 2015-04-01 06:56:52 | [diff] [blame] | 45 | HostCache* GetHostCache() override; |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 46 | |
| 47 | private: |
| 48 | class Job; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame^] | 49 | class RequestImpl; |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 50 | |
sammc | 6119a59c | 2015-04-01 06:56:52 | [diff] [blame] | 51 | int ResolveFromCacheInternal(const RequestInfo& info, |
| 52 | const HostCache::Key& key, |
| 53 | AddressList* addresses); |
| 54 | |
sammc | a3242c9 | 2015-07-10 02:38:51 | [diff] [blame] | 55 | Impl* const impl_; |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 56 | |
danakj | 22f90e7 | 2016-04-16 01:55:40 | [diff] [blame] | 57 | std::unique_ptr<HostCache> host_cache_; |
sammc | 6119a59c | 2015-04-01 06:56:52 | [diff] [blame] | 58 | base::WeakPtrFactory<HostCache> host_cache_weak_factory_; |
| 59 | |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 60 | 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_ |