| 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 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <ws2tcpip.h> | 8 #include <ws2tcpip.h> |
| 9 #include <wspiapi.h> // Needed for Win2k compat. | 9 #include <wspiapi.h> // Needed for Win2k compat. |
| 10 #elif defined(OS_POSIX) | 10 #elif defined(OS_POSIX) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 CompletionCallback* callback) | 69 CompletionCallback* callback) |
| 70 : host_(host), | 70 : host_(host), |
| 71 port_(port), | 71 port_(port), |
| 72 resolver_(resolver), | 72 resolver_(resolver), |
| 73 addresses_(addresses), | 73 addresses_(addresses), |
| 74 callback_(callback), | 74 callback_(callback), |
| 75 origin_loop_(MessageLoop::current()), | 75 origin_loop_(MessageLoop::current()), |
| 76 error_(OK), | 76 error_(OK), |
| 77 results_(NULL) { | 77 results_(NULL) { |
| 78 } | 78 } |
| 79 | 79 |
| 80 ~Request() { | 80 ~Request() { |
| 81 if (results_) | 81 if (results_) |
| 82 freeaddrinfo(results_); | 82 freeaddrinfo(results_); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void DoLookup() { | 85 void DoLookup() { |
| 86 // Running on the worker thread | 86 // Running on the worker thread |
| 87 error_ = ResolveAddrInfo(host_, port_, &results_); | 87 error_ = ResolveAddrInfo(host_, port_, &results_); |
| 88 | 88 |
| 89 Task* reply = NewRunnableMethod(this, &Request::DoCallback); | 89 Task* reply = NewRunnableMethod(this, &Request::DoCallback); |
| 90 | 90 |
| 91 // The origin loop could go away while we are trying to post to it, so we | 91 // The origin loop could go away while we are trying to post to it, so we |
| 92 // need to call its PostTask method inside a lock. See ~HostResolver. | 92 // need to call its PostTask method inside a lock. See ~HostResolver. |
| 93 { | 93 { |
| 94 AutoLock locked(origin_loop_lock_); | 94 AutoLock locked(origin_loop_lock_); |
| 95 if (origin_loop_) { | 95 if (origin_loop_) { |
| 96 origin_loop_->PostTask(FROM_HERE, reply); | 96 origin_loop_->PostTask(FROM_HERE, reply); |
| 97 reply = NULL; | 97 reply = NULL; |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 | 100 |
| 101 // Does nothing if it got posted. | 101 // Does nothing if it got posted. |
| 102 delete reply; | 102 delete reply; |
| 103 } | 103 } |
| 104 | 104 |
| 105 void DoCallback() { | 105 void DoCallback() { |
| 106 // Running on the origin thread. | 106 // Running on the origin thread. |
| 107 DCHECK(error_ || results_); | 107 DCHECK(error_ || results_); |
| 108 | 108 |
| 109 // We may have been cancelled! | 109 // We may have been cancelled! |
| 110 if (!resolver_) | 110 if (!resolver_) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 122 | 122 |
| 123 callback_->Run(error_); | 123 callback_->Run(error_); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void Cancel() { | 126 void Cancel() { |
| 127 resolver_ = NULL; | 127 resolver_ = NULL; |
| 128 | 128 |
| 129 AutoLock locked(origin_loop_lock_); | 129 AutoLock locked(origin_loop_lock_); |
| 130 origin_loop_ = NULL; | 130 origin_loop_ = NULL; |
| 131 } | 131 } |
| 132 | 132 |
| 133 private: | 133 private: |
| 134 // Set on the origin thread, read on the worker thread. | 134 // Set on the origin thread, read on the worker thread. |
| 135 std::string host_; | 135 std::string host_; |
| 136 std::string port_; | 136 std::string port_; |
| 137 | 137 |
| 138 // Only used on the origin thread (where Resolve was called). | 138 // Only used on the origin thread (where Resolve was called). |
| 139 HostResolver* resolver_; | 139 HostResolver* resolver_; |
| 140 AddressList* addresses_; | 140 AddressList* addresses_; |
| 141 CompletionCallback* callback_; | 141 CompletionCallback* callback_; |
| 142 | 142 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 NewRunnableMethod(request_.get(), &Request::DoLookup), true)) { | 185 NewRunnableMethod(request_.get(), &Request::DoLookup), true)) { |
| 186 NOTREACHED(); | 186 NOTREACHED(); |
| 187 request_ = NULL; | 187 request_ = NULL; |
| 188 return ERR_FAILED; | 188 return ERR_FAILED; |
| 189 } | 189 } |
| 190 | 190 |
| 191 return ERR_IO_PENDING; | 191 return ERR_IO_PENDING; |
| 192 } | 192 } |
| 193 | 193 |
| 194 } // namespace net | 194 } // namespace net |
| OLD | NEW |