Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: net/base/host_resolver.h

Issue 18775: Add more unit tests for net/base/host_resolver. (Closed)
Patch Set: add fixes, and actually use previous mapper Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | net/base/host_resolver.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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_HOST_RESOLVER_H_ 5 #ifndef NET_BASE_HOST_RESOLVER_H_
6 #define NET_BASE_HOST_RESOLVER_H_ 6 #define NET_BASE_HOST_RESOLVER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 private: 51 private:
52 class Request; 52 class Request;
53 friend class Request; 53 friend class Request;
54 scoped_refptr<Request> request_; 54 scoped_refptr<Request> request_;
55 DISALLOW_COPY_AND_ASSIGN(HostResolver); 55 DISALLOW_COPY_AND_ASSIGN(HostResolver);
56 }; 56 };
57 57
58 // A helper class used in unit tests to alter hostname mappings. See 58 // A helper class used in unit tests to alter hostname mappings. See
59 // SetHostMapper for details. 59 // SetHostMapper for details.
60 class HostMapper { 60 class HostMapper : public base::RefCountedThreadSafe<HostMapper> {
61 public: 61 public:
62 virtual ~HostMapper() {} 62 virtual ~HostMapper() {}
63 virtual std::string Map(const std::string& host) = 0; 63 virtual std::string Map(const std::string& host) = 0;
64
65 protected:
66 // Ask previous host mapper (if set) for mapping of given host.
67 std::string MapUsingPrevious(const std::string& host);
68
69 private:
70 friend class ScopedHostMapper;
71
72 // Set mapper to ask when this mapper doesn't want to modify the result.
73 void set_previous_mapper(HostMapper* mapper) {
74 previous_mapper_ = mapper;
75 }
76
77 scoped_refptr<HostMapper> previous_mapper_;
64 }; 78 };
65 79
66 #ifdef UNIT_TEST 80 #ifdef UNIT_TEST
67 // This function is designed to allow unit tests to override the behavior of 81 // This function is designed to allow unit tests to override the behavior of
68 // HostResolver. For example, a HostMapper instance can force all hostnames 82 // HostResolver. For example, a HostMapper instance can force all hostnames
69 // to map to a fixed IP address such as 127.0.0.1. 83 // to map to a fixed IP address such as 127.0.0.1.
70 // 84 //
71 // The previously set HostMapper (or NULL if there was none) is returned. 85 // The previously set HostMapper (or NULL if there was none) is returned.
72 // 86 //
73 // NOTE: This function is not thread-safe, so take care to only call this 87 // NOTE: This function is not thread-safe, so take care to only call this
74 // function while there are no outstanding HostResolver instances. 88 // function while there are no outstanding HostResolver instances.
75 // 89 //
76 // NOTE: In most cases, you should use ScopedHostMapper instead, which is 90 // NOTE: In most cases, you should use ScopedHostMapper instead, which is
77 // defined in host_resolver_unittest.h 91 // defined in host_resolver_unittest.h
78 // 92 //
79 HostMapper* SetHostMapper(HostMapper* host_mapper); 93 HostMapper* SetHostMapper(HostMapper* host_mapper);
80 #endif 94 #endif
81 95
82 } // namespace net 96 } // namespace net
83 97
84 #endif // NET_BASE_HOST_RESOLVER_H_ 98 #endif // NET_BASE_HOST_RESOLVER_H_
OLDNEW
« no previous file with comments | « no previous file | net/base/host_resolver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698