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 | |
sammc | 6119a59c | 2015-04-01 06:56:52 | [diff] [blame] | 8 | #include "base/memory/weak_ptr.h" |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 9 | #include "base/threading/thread_checker.h" |
sammc | 6119a59c | 2015-04-01 06:56:52 | [diff] [blame] | 10 | #include "net/dns/host_cache.h" |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 11 | #include "net/dns/host_resolver.h" |
| 12 | #include "net/interfaces/host_resolver_service.mojom.h" |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 13 | |
| 14 | namespace net { |
| 15 | class AddressList; |
| 16 | class BoundNetLog; |
| 17 | |
sammc | a3242c9 | 2015-07-10 02:38:51 | [diff] [blame^] | 18 | // A HostResolver implementation that converts requests to mojo types and |
| 19 | // forwards them to a mojo Impl interface. |
amistry | 3923072 | 2015-07-03 00:24:39 | [diff] [blame] | 20 | class HostResolverMojo : public HostResolver { |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 21 | public: |
sammc | a3242c9 | 2015-07-10 02:38:51 | [diff] [blame^] | 22 | 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); |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 31 | ~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; |
sammc | 6119a59c | 2015-04-01 06:56:52 | [diff] [blame] | 44 | HostCache* GetHostCache() override; |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 45 | |
| 46 | private: |
| 47 | class Job; |
| 48 | |
sammc | 6119a59c | 2015-04-01 06:56:52 | [diff] [blame] | 49 | int ResolveFromCacheInternal(const RequestInfo& info, |
| 50 | const HostCache::Key& key, |
| 51 | AddressList* addresses); |
| 52 | |
sammc | a3242c9 | 2015-07-10 02:38:51 | [diff] [blame^] | 53 | Impl* const impl_; |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 54 | |
sammc | 6119a59c | 2015-04-01 06:56:52 | [diff] [blame] | 55 | scoped_ptr<HostCache> host_cache_; |
| 56 | base::WeakPtrFactory<HostCache> host_cache_weak_factory_; |
| 57 | |
sammc | 6ac3fe5 | 2015-02-25 06:00:28 | [diff] [blame] | 58 | 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_ |