| 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 #include "net/base/mock_host_resolver.h" | 5 #include "net/base/mock_host_resolver.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 *addrlist = AddressList::CreateByCopyingFirstAddress(result.head()); | 53 *addrlist = AddressList::CreateByCopyingFirstAddress(result.head()); |
| 54 else | 54 else |
| 55 addrlist->Append(result.head()); | 55 addrlist->Append(result.head()); |
| 56 } | 56 } |
| 57 return OK; | 57 return OK; |
| 58 } | 58 } |
| 59 | 59 |
| 60 struct MockHostResolverBase::Request { | 60 struct MockHostResolverBase::Request { |
| 61 Request(const RequestInfo& req_info, | 61 Request(const RequestInfo& req_info, |
| 62 AddressList* addr, | 62 AddressList* addr, |
| 63 OldCompletionCallback* cb) | 63 const CompletionCallback& cb) |
| 64 : info(req_info), addresses(addr), callback(cb) {} | 64 : info(req_info), addresses(addr), callback(cb) {} |
| 65 RequestInfo info; | 65 RequestInfo info; |
| 66 AddressList* addresses; | 66 AddressList* addresses; |
| 67 OldCompletionCallback* callback; | 67 CompletionCallback callback; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 MockHostResolverBase::~MockHostResolverBase() { | 70 MockHostResolverBase::~MockHostResolverBase() { |
| 71 STLDeleteValues(&requests_); | 71 STLDeleteValues(&requests_); |
| 72 } | 72 } |
| 73 | 73 |
| 74 int MockHostResolverBase::Resolve(const RequestInfo& info, | 74 int MockHostResolverBase::Resolve(const RequestInfo& info, |
| 75 AddressList* addresses, | 75 AddressList* addresses, |
| 76 OldCompletionCallback* callback, | 76 const CompletionCallback& callback, |
| 77 RequestHandle* handle, | 77 RequestHandle* handle, |
| 78 const BoundNetLog& net_log) { | 78 const BoundNetLog& net_log) { |
| 79 DCHECK(CalledOnValidThread()); | 79 DCHECK(CalledOnValidThread()); |
| 80 size_t id = next_request_id_++; | 80 size_t id = next_request_id_++; |
| 81 int rv = ResolveFromIPLiteralOrCache(info, addresses); | 81 int rv = ResolveFromIPLiteralOrCache(info, addresses); |
| 82 if (rv != ERR_DNS_CACHE_MISS) { | 82 if (rv != ERR_DNS_CACHE_MISS) { |
| 83 return rv; | 83 return rv; |
| 84 } | 84 } |
| 85 if (synchronous_mode_) { | 85 if (synchronous_mode_) { |
| 86 return ResolveProc(id, info, addresses); | 86 return ResolveProc(id, info, addresses); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 } | 181 } |
| 182 | 182 |
| 183 void MockHostResolverBase::ResolveNow(size_t id) { | 183 void MockHostResolverBase::ResolveNow(size_t id) { |
| 184 RequestMap::iterator it = requests_.find(id); | 184 RequestMap::iterator it = requests_.find(id); |
| 185 if (it == requests_.end()) | 185 if (it == requests_.end()) |
| 186 return; // was canceled | 186 return; // was canceled |
| 187 | 187 |
| 188 scoped_ptr<Request> req(it->second); | 188 scoped_ptr<Request> req(it->second); |
| 189 requests_.erase(it); | 189 requests_.erase(it); |
| 190 int rv = ResolveProc(id, req->info, req->addresses); | 190 int rv = ResolveProc(id, req->info, req->addresses); |
| 191 if (req->callback) | 191 if (!req->callback.is_null()) |
| 192 req->callback->Run(rv); | 192 req->callback.Run(rv); |
| 193 } | 193 } |
| 194 | 194 |
| 195 //----------------------------------------------------------------------------- | 195 //----------------------------------------------------------------------------- |
| 196 | 196 |
| 197 struct RuleBasedHostResolverProc::Rule { | 197 struct RuleBasedHostResolverProc::Rule { |
| 198 enum ResolverType { | 198 enum ResolverType { |
| 199 kResolverTypeFail, | 199 kResolverTypeFail, |
| 200 kResolverTypeSystem, | 200 kResolverTypeSystem, |
| 201 kResolverTypeIPLiteral, | 201 kResolverTypeIPLiteral, |
| 202 }; | 202 }; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 #endif | 357 #endif |
| 358 | 358 |
| 359 // Next add a rules-based layer the use controls. | 359 // Next add a rules-based layer the use controls. |
| 360 return new RuleBasedHostResolverProc(catchall); | 360 return new RuleBasedHostResolverProc(catchall); |
| 361 } | 361 } |
| 362 | 362 |
| 363 //----------------------------------------------------------------------------- | 363 //----------------------------------------------------------------------------- |
| 364 | 364 |
| 365 int HangingHostResolver::Resolve(const RequestInfo& info, | 365 int HangingHostResolver::Resolve(const RequestInfo& info, |
| 366 AddressList* addresses, | 366 AddressList* addresses, |
| 367 OldCompletionCallback* callback, | 367 const CompletionCallback& callback, |
| 368 RequestHandle* out_req, | 368 RequestHandle* out_req, |
| 369 const BoundNetLog& net_log) { | 369 const BoundNetLog& net_log) { |
| 370 return ERR_IO_PENDING; | 370 return ERR_IO_PENDING; |
| 371 } | 371 } |
| 372 | 372 |
| 373 int HangingHostResolver::ResolveFromCache(const RequestInfo& info, | 373 int HangingHostResolver::ResolveFromCache(const RequestInfo& info, |
| 374 AddressList* addresses, | 374 AddressList* addresses, |
| 375 const BoundNetLog& net_log) { | 375 const BoundNetLog& net_log) { |
| 376 return ERR_DNS_CACHE_MISS; | 376 return ERR_DNS_CACHE_MISS; |
| 377 } | 377 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 391 CHECK_EQ(old_proc, current_proc_); | 391 CHECK_EQ(old_proc, current_proc_); |
| 392 } | 392 } |
| 393 | 393 |
| 394 void ScopedDefaultHostResolverProc::Init(HostResolverProc* proc) { | 394 void ScopedDefaultHostResolverProc::Init(HostResolverProc* proc) { |
| 395 current_proc_ = proc; | 395 current_proc_ = proc; |
| 396 previous_proc_ = HostResolverProc::SetDefault(current_proc_); | 396 previous_proc_ = HostResolverProc::SetDefault(current_proc_); |
| 397 current_proc_->SetLastProc(previous_proc_); | 397 current_proc_->SetLastProc(previous_proc_); |
| 398 } | 398 } |
| 399 | 399 |
| 400 } // namespace net | 400 } // namespace net |
| OLD | NEW |