| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_DNS_MOCK_HOST_RESOLVER_H_ | 5 #ifndef NET_DNS_MOCK_HOST_RESOLVER_H_ |
| 6 #define NET_DNS_MOCK_HOST_RESOLVER_H_ | 6 #define NET_DNS_MOCK_HOST_RESOLVER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| 11 #include <map> | 11 #include <map> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 17 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
| 18 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/thread_checker.h" |
| 19 #include "net/dns/host_resolver.h" | 19 #include "net/dns/host_resolver.h" |
| 20 #include "net/dns/host_resolver_proc.h" | 20 #include "net/dns/host_resolver_proc.h" |
| 21 | 21 |
| 22 namespace net { | 22 namespace net { |
| 23 | 23 |
| 24 class HostCache; | 24 class HostCache; |
| 25 class RuleBasedHostResolverProc; | 25 class RuleBasedHostResolverProc; |
| 26 | 26 |
| 27 // Fills |*addrlist| with a socket address for |host_list| which should be a | 27 // Fills |*addrlist| with a socket address for |host_list| which should be a |
| 28 // comma-separated list of IPv4 or IPv6 literal(s) without enclosing brackets. | 28 // comma-separated list of IPv4 or IPv6 literal(s) without enclosing brackets. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 49 // | 49 // |
| 50 // host_mapper->AddRule("*.com", "127.0.0.1"); | 50 // host_mapper->AddRule("*.com", "127.0.0.1"); |
| 51 // | 51 // |
| 52 // Replacement doesn't have to be string representing an IP address. It can | 52 // Replacement doesn't have to be string representing an IP address. It can |
| 53 // re-map one hostname to another as well. | 53 // re-map one hostname to another as well. |
| 54 // | 54 // |
| 55 // By default, MockHostResolvers include a single rule that maps all hosts to | 55 // By default, MockHostResolvers include a single rule that maps all hosts to |
| 56 // 127.0.0.1. | 56 // 127.0.0.1. |
| 57 | 57 |
| 58 // Base class shared by MockHostResolver and MockCachingHostResolver. | 58 // Base class shared by MockHostResolver and MockCachingHostResolver. |
| 59 class MockHostResolverBase : public HostResolver, | 59 class MockHostResolverBase |
| 60 public base::SupportsWeakPtr<MockHostResolverBase>, | 60 : public HostResolver, |
| 61 public base::NonThreadSafe { | 61 public base::SupportsWeakPtr<MockHostResolverBase> { |
| 62 private: | 62 private: |
| 63 class RequestImpl; | 63 class RequestImpl; |
| 64 | 64 |
| 65 public: | 65 public: |
| 66 ~MockHostResolverBase() override; | 66 ~MockHostResolverBase() override; |
| 67 | 67 |
| 68 RuleBasedHostResolverProc* rules() { return rules_.get(); } | 68 RuleBasedHostResolverProc* rules() { return rules_.get(); } |
| 69 void set_rules(RuleBasedHostResolverProc* rules) { rules_ = rules; } | 69 void set_rules(RuleBasedHostResolverProc* rules) { rules_ = rules; } |
| 70 | 70 |
| 71 // Controls whether resolutions complete synchronously or asynchronously. | 71 // Controls whether resolutions complete synchronously or asynchronously. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 bool synchronous_mode_; | 140 bool synchronous_mode_; |
| 141 bool ondemand_mode_; | 141 bool ondemand_mode_; |
| 142 scoped_refptr<RuleBasedHostResolverProc> rules_; | 142 scoped_refptr<RuleBasedHostResolverProc> rules_; |
| 143 std::unique_ptr<HostCache> cache_; | 143 std::unique_ptr<HostCache> cache_; |
| 144 RequestMap requests_; | 144 RequestMap requests_; |
| 145 size_t next_request_id_; | 145 size_t next_request_id_; |
| 146 | 146 |
| 147 size_t num_resolve_; | 147 size_t num_resolve_; |
| 148 size_t num_resolve_from_cache_; | 148 size_t num_resolve_from_cache_; |
| 149 | 149 |
| 150 THREAD_CHECKER(thread_checker_); |
| 151 |
| 150 DISALLOW_COPY_AND_ASSIGN(MockHostResolverBase); | 152 DISALLOW_COPY_AND_ASSIGN(MockHostResolverBase); |
| 151 }; | 153 }; |
| 152 | 154 |
| 153 class MockHostResolver : public MockHostResolverBase { | 155 class MockHostResolver : public MockHostResolverBase { |
| 154 public: | 156 public: |
| 155 MockHostResolver() : MockHostResolverBase(false /*use_caching*/) {} | 157 MockHostResolver() : MockHostResolverBase(false /*use_caching*/) {} |
| 156 ~MockHostResolver() override {} | 158 ~MockHostResolver() override {} |
| 157 }; | 159 }; |
| 158 | 160 |
| 159 // Same as MockHostResolver, except internally it uses a host-cache. | 161 // Same as MockHostResolver, except internally it uses a host-cache. |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 void Init(HostResolverProc* proc); | 306 void Init(HostResolverProc* proc); |
| 305 | 307 |
| 306 private: | 308 private: |
| 307 scoped_refptr<HostResolverProc> current_proc_; | 309 scoped_refptr<HostResolverProc> current_proc_; |
| 308 scoped_refptr<HostResolverProc> previous_proc_; | 310 scoped_refptr<HostResolverProc> previous_proc_; |
| 309 }; | 311 }; |
| 310 | 312 |
| 311 } // namespace net | 313 } // namespace net |
| 312 | 314 |
| 313 #endif // NET_DNS_MOCK_HOST_RESOLVER_H_ | 315 #endif // NET_DNS_MOCK_HOST_RESOLVER_H_ |
| OLD | NEW |