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; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17 | class NetLogWithSource; |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 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; |
sammc | 170917f | 2016-10-09 23:26:04 | [diff] [blame] | 26 | virtual void ResolveDns( |
| 27 | std::unique_ptr<HostResolver::RequestInfo> request_info, |
| 28 | interfaces::HostResolverRequestClientPtr) = 0; |
sammc | a3242c9 | 2015-07-10 02:38:51 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | // |impl| must outlive |this|. |
| 32 | explicit HostResolverMojo(Impl* impl); |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 33 | ~HostResolverMojo() override; |
| 34 | |
| 35 | // HostResolver overrides. |
juliatuttle | c53b19a7 | 2016-05-05 13:51:31 | [diff] [blame] | 36 | // Note: |Resolve()| currently ignores |priority|. |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 37 | int Resolve(const RequestInfo& info, |
| 38 | RequestPriority priority, |
| 39 | AddressList* addresses, |
| 40 | const CompletionCallback& callback, |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 41 | std::unique_ptr<Request>* request, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 42 | const NetLogWithSource& source_net_log) override; |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 43 | int ResolveFromCache(const RequestInfo& info, |
| 44 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 45 | const NetLogWithSource& source_net_log) override; |
sammc | 6119a59c | 2015-04-01 06:56:52 | [diff] [blame] | 46 | HostCache* GetHostCache() override; |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 47 | |
| 48 | private: |
| 49 | class Job; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 50 | class RequestImpl; |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 51 | |
sammc | 6119a59c | 2015-04-01 06:56:52 | [diff] [blame] | 52 | int ResolveFromCacheInternal(const RequestInfo& info, |
| 53 | const HostCache::Key& key, |
| 54 | AddressList* addresses); |
| 55 | |
sammc | a3242c9 | 2015-07-10 02:38:51 | [diff] [blame] | 56 | Impl* const impl_; |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 57 | |
danakj | 22f90e7 | 2016-04-16 01:55:40 | [diff] [blame] | 58 | std::unique_ptr<HostCache> host_cache_; |
sammc | 6119a59c | 2015-04-01 06:56:52 | [diff] [blame] | 59 | base::WeakPtrFactory<HostCache> host_cache_weak_factory_; |
| 60 | |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 61 | 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_ |