| 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_BASE_MOCK_HOST_RESOLVER_H_ | 5 #ifndef NET_BASE_MOCK_HOST_RESOLVER_H_ |
| 6 #define NET_BASE_MOCK_HOST_RESOLVER_H_ | 6 #define NET_BASE_MOCK_HOST_RESOLVER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <map> | 10 #include <map> |
| 11 | 11 |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/observer_list.h" | |
| 14 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 15 #include "base/threading/non_thread_safe.h" | 14 #include "base/threading/non_thread_safe.h" |
| 16 #include "net/base/host_resolver.h" | 15 #include "net/base/host_resolver.h" |
| 17 #include "net/base/host_resolver_proc.h" | 16 #include "net/base/host_resolver_proc.h" |
| 18 | 17 |
| 19 namespace net { | 18 namespace net { |
| 20 | 19 |
| 21 class HostCache; | 20 class HostCache; |
| 22 class RuleBasedHostResolverProc; | 21 class RuleBasedHostResolverProc; |
| 23 | 22 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // HostResolver methods: | 68 // HostResolver methods: |
| 70 virtual int Resolve(const RequestInfo& info, | 69 virtual int Resolve(const RequestInfo& info, |
| 71 AddressList* addresses, | 70 AddressList* addresses, |
| 72 OldCompletionCallback* callback, | 71 OldCompletionCallback* callback, |
| 73 RequestHandle* out_req, | 72 RequestHandle* out_req, |
| 74 const BoundNetLog& net_log) OVERRIDE; | 73 const BoundNetLog& net_log) OVERRIDE; |
| 75 virtual int ResolveFromCache(const RequestInfo& info, | 74 virtual int ResolveFromCache(const RequestInfo& info, |
| 76 AddressList* addresses, | 75 AddressList* addresses, |
| 77 const BoundNetLog& net_log) OVERRIDE; | 76 const BoundNetLog& net_log) OVERRIDE; |
| 78 virtual void CancelRequest(RequestHandle req) OVERRIDE; | 77 virtual void CancelRequest(RequestHandle req) OVERRIDE; |
| 79 virtual void AddObserver(Observer* observer) OVERRIDE; | |
| 80 virtual void RemoveObserver(Observer* observer) OVERRIDE; | |
| 81 virtual HostCache* GetHostCache() OVERRIDE; | 78 virtual HostCache* GetHostCache() OVERRIDE; |
| 82 | 79 |
| 83 protected: | 80 protected: |
| 84 explicit MockHostResolverBase(bool use_caching); | 81 explicit MockHostResolverBase(bool use_caching); |
| 85 | 82 |
| 86 private: | 83 private: |
| 87 struct Request; | 84 struct Request; |
| 88 typedef std::map<size_t, Request*> RequestMap; | 85 typedef std::map<size_t, Request*> RequestMap; |
| 89 | 86 |
| 90 // Resolve as IP or from |cache_| return cached error or | 87 // Resolve as IP or from |cache_| return cached error or |
| 91 // DNS_CACHE_MISS if failed. | 88 // DNS_CACHE_MISS if failed. |
| 92 int ResolveFromIPLiteralOrCache(const RequestInfo& info, | 89 int ResolveFromIPLiteralOrCache(const RequestInfo& info, |
| 93 AddressList* addresses); | 90 AddressList* addresses); |
| 94 // Resolve via |proc_|. | 91 // Resolve via |proc_|. |
| 95 int ResolveProc(size_t id, const RequestInfo& info, AddressList* addresses); | 92 int ResolveProc(size_t id, const RequestInfo& info, AddressList* addresses); |
| 96 // Resolve request stored in |requests_|. Pass rv to callback. | 93 // Resolve request stored in |requests_|. Pass rv to callback. |
| 97 void ResolveNow(size_t id); | 94 void ResolveNow(size_t id); |
| 98 | 95 |
| 99 bool synchronous_mode_; | 96 bool synchronous_mode_; |
| 100 ObserverList<Observer> observers_; | |
| 101 scoped_refptr<RuleBasedHostResolverProc> rules_; | 97 scoped_refptr<RuleBasedHostResolverProc> rules_; |
| 102 scoped_refptr<HostResolverProc> proc_; | 98 scoped_refptr<HostResolverProc> proc_; |
| 103 scoped_ptr<HostCache> cache_; | 99 scoped_ptr<HostCache> cache_; |
| 104 RequestMap requests_; | 100 RequestMap requests_; |
| 105 size_t next_request_id_; | 101 size_t next_request_id_; |
| 106 | 102 |
| 107 DISALLOW_COPY_AND_ASSIGN(MockHostResolverBase); | 103 DISALLOW_COPY_AND_ASSIGN(MockHostResolverBase); |
| 108 }; | 104 }; |
| 109 | 105 |
| 110 class MockHostResolver : public MockHostResolverBase { | 106 class MockHostResolver : public MockHostResolverBase { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 public: | 182 public: |
| 187 virtual int Resolve(const RequestInfo& info, | 183 virtual int Resolve(const RequestInfo& info, |
| 188 AddressList* addresses, | 184 AddressList* addresses, |
| 189 OldCompletionCallback* callback, | 185 OldCompletionCallback* callback, |
| 190 RequestHandle* out_req, | 186 RequestHandle* out_req, |
| 191 const BoundNetLog& net_log) OVERRIDE; | 187 const BoundNetLog& net_log) OVERRIDE; |
| 192 virtual int ResolveFromCache(const RequestInfo& info, | 188 virtual int ResolveFromCache(const RequestInfo& info, |
| 193 AddressList* addresses, | 189 AddressList* addresses, |
| 194 const BoundNetLog& net_log) OVERRIDE; | 190 const BoundNetLog& net_log) OVERRIDE; |
| 195 virtual void CancelRequest(RequestHandle req) OVERRIDE {} | 191 virtual void CancelRequest(RequestHandle req) OVERRIDE {} |
| 196 virtual void AddObserver(Observer* observer) OVERRIDE {} | |
| 197 virtual void RemoveObserver(Observer* observer) OVERRIDE {} | |
| 198 }; | 192 }; |
| 199 | 193 |
| 200 // This class sets the default HostResolverProc for a particular scope. The | 194 // This class sets the default HostResolverProc for a particular scope. The |
| 201 // chain of resolver procs starting at |proc| is placed in front of any existing | 195 // chain of resolver procs starting at |proc| is placed in front of any existing |
| 202 // default resolver proc(s). This means that if multiple | 196 // default resolver proc(s). This means that if multiple |
| 203 // ScopedDefaultHostResolverProcs are declared, then resolving will start with | 197 // ScopedDefaultHostResolverProcs are declared, then resolving will start with |
| 204 // the procs given to the last-allocated one, then fall back to the procs given | 198 // the procs given to the last-allocated one, then fall back to the procs given |
| 205 // to the previously-allocated one, and so forth. | 199 // to the previously-allocated one, and so forth. |
| 206 // | 200 // |
| 207 // NOTE: Only use this as a catch-all safety net. Individual tests should use | 201 // NOTE: Only use this as a catch-all safety net. Individual tests should use |
| 208 // MockHostResolver. | 202 // MockHostResolver. |
| 209 class ScopedDefaultHostResolverProc { | 203 class ScopedDefaultHostResolverProc { |
| 210 public: | 204 public: |
| 211 ScopedDefaultHostResolverProc(); | 205 ScopedDefaultHostResolverProc(); |
| 212 explicit ScopedDefaultHostResolverProc(HostResolverProc* proc); | 206 explicit ScopedDefaultHostResolverProc(HostResolverProc* proc); |
| 213 | 207 |
| 214 ~ScopedDefaultHostResolverProc(); | 208 ~ScopedDefaultHostResolverProc(); |
| 215 | 209 |
| 216 void Init(HostResolverProc* proc); | 210 void Init(HostResolverProc* proc); |
| 217 | 211 |
| 218 private: | 212 private: |
| 219 scoped_refptr<HostResolverProc> current_proc_; | 213 scoped_refptr<HostResolverProc> current_proc_; |
| 220 scoped_refptr<HostResolverProc> previous_proc_; | 214 scoped_refptr<HostResolverProc> previous_proc_; |
| 221 }; | 215 }; |
| 222 | 216 |
| 223 } // namespace net | 217 } // namespace net |
| 224 | 218 |
| 225 #endif // NET_BASE_MOCK_HOST_RESOLVER_H_ | 219 #endif // NET_BASE_MOCK_HOST_RESOLVER_H_ |
| OLD | NEW |