| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "net/base/mock_host_resolver.h" | 5 #include "net/base/mock_host_resolver.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/platform_thread.h" | 8 #include "base/platform_thread.h" |
| 9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
| 10 #include "googleurl/src/url_canon_ip.h" | 10 #include "googleurl/src/url_canon_ip.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 const std::string& host_pattern) { | 157 const std::string& host_pattern) { |
| 158 Rule rule(Rule::kResolverTypeFail, host_pattern, "", 0); | 158 Rule rule(Rule::kResolverTypeFail, host_pattern, "", 0); |
| 159 rules_.push_back(rule); | 159 rules_.push_back(rule); |
| 160 } | 160 } |
| 161 | 161 |
| 162 int RuleBasedHostResolverProc::Resolve(const std::string& host, | 162 int RuleBasedHostResolverProc::Resolve(const std::string& host, |
| 163 AddressList* addrlist) { | 163 AddressList* addrlist) { |
| 164 RuleList::iterator r; | 164 RuleList::iterator r; |
| 165 for (r = rules_.begin(); r != rules_.end(); ++r) { | 165 for (r = rules_.begin(); r != rules_.end(); ++r) { |
| 166 if (MatchPattern(host, r->host_pattern)) { | 166 if (MatchPattern(host, r->host_pattern)) { |
| 167 if (r->latency_ms != 0) { | 167 if (r->latency_ms != 0) |
| 168 PlatformThread::Sleep(r->latency_ms); | 168 PlatformThread::Sleep(r->latency_ms); |
| 169 // Hmm, this seems unecessary. | |
| 170 r->latency_ms = 1; | |
| 171 } | |
| 172 | 169 |
| 173 // Remap to a new host. | 170 // Remap to a new host. |
| 174 const std::string& effective_host = | 171 const std::string& effective_host = |
| 175 r->replacement.empty() ? host : r->replacement; | 172 r->replacement.empty() ? host : r->replacement; |
| 176 | 173 |
| 177 // Apply the resolving function to the remapped hostname. | 174 // Apply the resolving function to the remapped hostname. |
| 178 switch (r->resolver_type) { | 175 switch (r->resolver_type) { |
| 179 case Rule::kResolverTypeFail: | 176 case Rule::kResolverTypeFail: |
| 180 return ERR_NAME_NOT_RESOLVED; | 177 return ERR_NAME_NOT_RESOLVED; |
| 181 case Rule::kResolverTypeSystem: | 178 case Rule::kResolverTypeSystem: |
| (...skipping 23 matching lines...) Expand all Loading... |
| 205 CHECK(old_proc == current_proc_); | 202 CHECK(old_proc == current_proc_); |
| 206 } | 203 } |
| 207 | 204 |
| 208 void ScopedDefaultHostResolverProc::Init(HostResolverProc* proc) { | 205 void ScopedDefaultHostResolverProc::Init(HostResolverProc* proc) { |
| 209 current_proc_ = proc; | 206 current_proc_ = proc; |
| 210 previous_proc_ = HostResolverProc::SetDefault(current_proc_); | 207 previous_proc_ = HostResolverProc::SetDefault(current_proc_); |
| 211 current_proc_->set_previous_proc(previous_proc_); | 208 current_proc_->set_previous_proc(previous_proc_); |
| 212 } | 209 } |
| 213 | 210 |
| 214 } // namespace net | 211 } // namespace net |
| OLD | NEW |