| 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/single_request_host_resolver.h" | 5 #include "net/base/single_request_host_resolver.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 | 10 |
| 11 namespace net { | 11 namespace net { |
| 12 | 12 |
| 13 SingleRequestHostResolver::SingleRequestHostResolver(HostResolver* resolver) | 13 SingleRequestHostResolver::SingleRequestHostResolver(HostResolver* resolver) |
| 14 : resolver_(resolver), | 14 : resolver_(resolver), |
| 15 cur_request_(NULL), | 15 cur_request_(NULL), |
| 16 cur_request_callback_(NULL), | 16 cur_request_callback_(NULL), |
| 17 ALLOW_THIS_IN_INITIALIZER_LIST( | 17 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 18 callback_(this, &SingleRequestHostResolver::OnResolveCompletion)) { | 18 callback_(this, &SingleRequestHostResolver::OnResolveCompletion)) { |
| 19 DCHECK(resolver_ != NULL); | 19 DCHECK(resolver_ != NULL); |
| 20 } | 20 } |
| 21 | 21 |
| 22 SingleRequestHostResolver::~SingleRequestHostResolver() { | 22 SingleRequestHostResolver::~SingleRequestHostResolver() { |
| 23 Cancel(); | 23 Cancel(); |
| 24 } | 24 } |
| 25 | 25 |
| 26 int SingleRequestHostResolver::Resolve(const HostResolver::RequestInfo& info, | 26 int SingleRequestHostResolver::Resolve(const HostResolver::RequestInfo& info, |
| 27 AddressList* addresses, | 27 AddressList* addresses, |
| 28 CompletionCallback* callback, | 28 CompletionCallback* callback, |
| 29 const BoundNetLog& net_log) { | 29 const BoundNetLog& net_log) { |
| 30 DCHECK(addresses); |
| 31 DCHECK(callback); |
| 30 DCHECK(!cur_request_callback_) << "resolver already in use"; | 32 DCHECK(!cur_request_callback_) << "resolver already in use"; |
| 31 | 33 |
| 32 HostResolver::RequestHandle request = NULL; | 34 HostResolver::RequestHandle request = NULL; |
| 33 | 35 |
| 34 // We need to be notified of completion before |callback| is called, so that | 36 // We need to be notified of completion before |callback| is called, so that |
| 35 // we can clear out |cur_request_*|. | 37 // we can clear out |cur_request_*|. |
| 36 CompletionCallback* transient_callback = callback ? &callback_ : NULL; | 38 CompletionCallback* transient_callback = callback ? &callback_ : NULL; |
| 37 | 39 |
| 38 int rv = resolver_->Resolve( | 40 int rv = resolver_->Resolve( |
| 39 info, addresses, transient_callback, &request, net_log); | 41 info, addresses, transient_callback, &request, net_log); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 63 | 65 |
| 64 // Clear the outstanding request information. | 66 // Clear the outstanding request information. |
| 65 cur_request_ = NULL; | 67 cur_request_ = NULL; |
| 66 cur_request_callback_ = NULL; | 68 cur_request_callback_ = NULL; |
| 67 | 69 |
| 68 // Call the user's original callback. | 70 // Call the user's original callback. |
| 69 callback->Run(result); | 71 callback->Run(result); |
| 70 } | 72 } |
| 71 | 73 |
| 72 } // namespace net | 74 } // namespace net |
| OLD | NEW |