OLD | NEW |
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 #include "net/base/host_resolver.h" | 5 #include "net/base/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 if (cur_request_) { | 23 if (cur_request_) { |
24 resolver_->CancelRequest(cur_request_); | 24 resolver_->CancelRequest(cur_request_); |
25 } | 25 } |
26 } | 26 } |
27 | 27 |
28 int SingleRequestHostResolver::Resolve(const HostResolver::RequestInfo& info, | 28 int SingleRequestHostResolver::Resolve(LoadLog* load_log, |
| 29 const HostResolver::RequestInfo& info, |
29 AddressList* addresses, | 30 AddressList* addresses, |
30 CompletionCallback* callback) { | 31 CompletionCallback* callback) { |
31 DCHECK(!cur_request_ && !cur_request_callback_) << "resolver already in use"; | 32 DCHECK(!cur_request_ && !cur_request_callback_) << "resolver already in use"; |
32 | 33 |
33 HostResolver::RequestHandle request = NULL; | 34 HostResolver::RequestHandle request = NULL; |
34 | 35 |
35 // 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 |
36 // we can clear out |cur_request_*|. | 37 // we can clear out |cur_request_*|. |
37 CompletionCallback* transient_callback = callback ? &callback_ : NULL; | 38 CompletionCallback* transient_callback = callback ? &callback_ : NULL; |
38 | 39 |
39 int rv = resolver_->Resolve(info, addresses, transient_callback, &request); | 40 int rv = resolver_->Resolve( |
| 41 load_log, info, addresses, transient_callback, &request); |
40 | 42 |
41 if (rv == ERR_IO_PENDING) { | 43 if (rv == ERR_IO_PENDING) { |
42 // Cleared in OnResolveCompletion(). | 44 // Cleared in OnResolveCompletion(). |
43 cur_request_ = request; | 45 cur_request_ = request; |
44 cur_request_callback_ = callback; | 46 cur_request_callback_ = callback; |
45 } | 47 } |
46 | 48 |
47 return rv; | 49 return rv; |
48 } | 50 } |
49 | 51 |
50 void SingleRequestHostResolver::OnResolveCompletion(int result) { | 52 void SingleRequestHostResolver::OnResolveCompletion(int result) { |
51 DCHECK(cur_request_ && cur_request_callback_); | 53 DCHECK(cur_request_ && cur_request_callback_); |
52 | 54 |
53 CompletionCallback* callback = cur_request_callback_; | 55 CompletionCallback* callback = cur_request_callback_; |
54 | 56 |
55 // Clear the outstanding request information. | 57 // Clear the outstanding request information. |
56 cur_request_ = NULL; | 58 cur_request_ = NULL; |
57 cur_request_callback_ = NULL; | 59 cur_request_callback_ = NULL; |
58 | 60 |
59 // Call the user's original callback. | 61 // Call the user's original callback. |
60 callback->Run(result); | 62 callback->Run(result); |
61 } | 63 } |
62 | 64 |
63 } // namespace net | 65 } // namespace net |
OLD | NEW |