| 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/host_resolver_impl.h" | 5 #include "net/base/host_resolver_impl.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <Winsock2.h> | 8 #include <Winsock2.h> |
| 9 #elif defined(OS_POSIX) | 9 #elif defined(OS_POSIX) |
| 10 #include <netdb.h> | 10 #include <netdb.h> |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 const std::string host_; | 254 const std::string host_; |
| 255 const NetLog::Source source_; | 255 const NetLog::Source source_; |
| 256 }; | 256 }; |
| 257 | 257 |
| 258 //----------------------------------------------------------------------------- | 258 //----------------------------------------------------------------------------- |
| 259 | 259 |
| 260 class HostResolverImpl::Request { | 260 class HostResolverImpl::Request { |
| 261 public: | 261 public: |
| 262 Request(const BoundNetLog& source_net_log, | 262 Request(const BoundNetLog& source_net_log, |
| 263 const BoundNetLog& request_net_log, | 263 const BoundNetLog& request_net_log, |
| 264 int id, | |
| 265 const RequestInfo& info, | 264 const RequestInfo& info, |
| 266 OldCompletionCallback* callback, | 265 OldCompletionCallback* callback, |
| 267 AddressList* addresses) | 266 AddressList* addresses) |
| 268 : source_net_log_(source_net_log), | 267 : source_net_log_(source_net_log), |
| 269 request_net_log_(request_net_log), | 268 request_net_log_(request_net_log), |
| 270 id_(id), | |
| 271 info_(info), | 269 info_(info), |
| 272 job_(NULL), | 270 job_(NULL), |
| 273 callback_(callback), | 271 callback_(callback), |
| 274 addresses_(addresses) { | 272 addresses_(addresses) { |
| 275 } | 273 } |
| 276 | 274 |
| 277 // Mark the request as cancelled. | 275 // Mark the request as cancelled. |
| 278 void MarkAsCancelled() { | 276 void MarkAsCancelled() { |
| 279 job_ = NULL; | 277 job_ = NULL; |
| 280 callback_ = NULL; | 278 callback_ = NULL; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 308 } | 306 } |
| 309 | 307 |
| 310 const BoundNetLog& source_net_log() { | 308 const BoundNetLog& source_net_log() { |
| 311 return source_net_log_; | 309 return source_net_log_; |
| 312 } | 310 } |
| 313 | 311 |
| 314 const BoundNetLog& request_net_log() { | 312 const BoundNetLog& request_net_log() { |
| 315 return request_net_log_; | 313 return request_net_log_; |
| 316 } | 314 } |
| 317 | 315 |
| 318 int id() const { | |
| 319 return id_; | |
| 320 } | |
| 321 | |
| 322 const RequestInfo& info() const { | 316 const RequestInfo& info() const { |
| 323 return info_; | 317 return info_; |
| 324 } | 318 } |
| 325 | 319 |
| 326 private: | 320 private: |
| 327 BoundNetLog source_net_log_; | 321 BoundNetLog source_net_log_; |
| 328 BoundNetLog request_net_log_; | 322 BoundNetLog request_net_log_; |
| 329 | 323 |
| 330 // Unique ID for this request. Used by observers to identify requests. | |
| 331 int id_; | |
| 332 | |
| 333 // The request info that started the request. | 324 // The request info that started the request. |
| 334 RequestInfo info_; | 325 RequestInfo info_; |
| 335 | 326 |
| 336 // The resolve job (running in worker pool) that this request is dependent on. | 327 // The resolve job (running in worker pool) that this request is dependent on. |
| 337 Job* job_; | 328 Job* job_; |
| 338 | 329 |
| 339 // The user's callback to invoke when the request completes. | 330 // The user's callback to invoke when the request completes. |
| 340 OldCompletionCallback* callback_; | 331 OldCompletionCallback* callback_; |
| 341 | 332 |
| 342 // The address list to save result into. | 333 // The address list to save result into. |
| (...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1056 HostResolverProc* resolver_proc, | 1047 HostResolverProc* resolver_proc, |
| 1057 HostCache* cache, | 1048 HostCache* cache, |
| 1058 size_t max_jobs, | 1049 size_t max_jobs, |
| 1059 size_t max_retry_attempts, | 1050 size_t max_retry_attempts, |
| 1060 NetLog* net_log) | 1051 NetLog* net_log) |
| 1061 : cache_(cache), | 1052 : cache_(cache), |
| 1062 max_jobs_(max_jobs), | 1053 max_jobs_(max_jobs), |
| 1063 max_retry_attempts_(max_retry_attempts), | 1054 max_retry_attempts_(max_retry_attempts), |
| 1064 unresponsive_delay_(base::TimeDelta::FromMilliseconds(6000)), | 1055 unresponsive_delay_(base::TimeDelta::FromMilliseconds(6000)), |
| 1065 retry_factor_(2), | 1056 retry_factor_(2), |
| 1066 next_request_id_(0), | |
| 1067 next_job_id_(0), | 1057 next_job_id_(0), |
| 1068 resolver_proc_(resolver_proc), | 1058 resolver_proc_(resolver_proc), |
| 1069 default_address_family_(ADDRESS_FAMILY_UNSPECIFIED), | 1059 default_address_family_(ADDRESS_FAMILY_UNSPECIFIED), |
| 1070 ipv6_probe_monitoring_(false), | 1060 ipv6_probe_monitoring_(false), |
| 1071 additional_resolver_flags_(0), | 1061 additional_resolver_flags_(0), |
| 1072 net_log_(net_log) { | 1062 net_log_(net_log) { |
| 1073 DCHECK_GT(max_jobs, 0u); | 1063 DCHECK_GT(max_jobs, 0u); |
| 1074 | 1064 |
| 1075 // Maximum of 4 retry attempts for host resolution. | 1065 // Maximum of 4 retry attempts for host resolution. |
| 1076 static const size_t kDefaultMaxRetryAttempts = 4u; | 1066 static const size_t kDefaultMaxRetryAttempts = 4u; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1130 | 1120 |
| 1131 int HostResolverImpl::Resolve(const RequestInfo& info, | 1121 int HostResolverImpl::Resolve(const RequestInfo& info, |
| 1132 AddressList* addresses, | 1122 AddressList* addresses, |
| 1133 OldCompletionCallback* callback, | 1123 OldCompletionCallback* callback, |
| 1134 RequestHandle* out_req, | 1124 RequestHandle* out_req, |
| 1135 const BoundNetLog& source_net_log) { | 1125 const BoundNetLog& source_net_log) { |
| 1136 DCHECK(addresses); | 1126 DCHECK(addresses); |
| 1137 DCHECK(callback); | 1127 DCHECK(callback); |
| 1138 DCHECK(CalledOnValidThread()); | 1128 DCHECK(CalledOnValidThread()); |
| 1139 | 1129 |
| 1140 // Choose a unique ID number for observers to see. | |
| 1141 int request_id = next_request_id_++; | |
| 1142 | |
| 1143 // Make a log item for the request. | 1130 // Make a log item for the request. |
| 1144 BoundNetLog request_net_log = BoundNetLog::Make(net_log_, | 1131 BoundNetLog request_net_log = BoundNetLog::Make(net_log_, |
| 1145 NetLog::SOURCE_HOST_RESOLVER_IMPL_REQUEST); | 1132 NetLog::SOURCE_HOST_RESOLVER_IMPL_REQUEST); |
| 1146 | 1133 |
| 1147 // Update the net log and notify registered observers. | 1134 // Update the net log and notify registered observers. |
| 1148 OnStartRequest(source_net_log, request_net_log, request_id, info); | 1135 OnStartRequest(source_net_log, request_net_log, info); |
| 1149 | 1136 |
| 1150 // Build a key that identifies the request in the cache and in the | 1137 // Build a key that identifies the request in the cache and in the |
| 1151 // outstanding jobs map. | 1138 // outstanding jobs map. |
| 1152 Key key = GetEffectiveKeyForRequest(info); | 1139 Key key = GetEffectiveKeyForRequest(info); |
| 1153 | 1140 |
| 1154 int rv = ResolveHelper(request_id, key, info, addresses, request_net_log); | 1141 int rv = ResolveHelper(key, info, addresses, request_net_log); |
| 1155 if (rv != ERR_DNS_CACHE_MISS) { | 1142 if (rv != ERR_DNS_CACHE_MISS) { |
| 1156 OnFinishRequest(source_net_log, request_net_log, request_id, info, | 1143 OnFinishRequest(source_net_log, request_net_log, info, |
| 1157 rv, | 1144 rv, |
| 1158 0 /* os_error (unknown since from cache) */); | 1145 0 /* os_error (unknown since from cache) */); |
| 1159 return rv; | 1146 return rv; |
| 1160 } | 1147 } |
| 1161 | 1148 |
| 1162 // Create a handle for this request, and pass it back to the user if they | 1149 // Create a handle for this request, and pass it back to the user if they |
| 1163 // asked for it (out_req != NULL). | 1150 // asked for it (out_req != NULL). |
| 1164 Request* req = new Request(source_net_log, request_net_log, request_id, info, | 1151 Request* req = new Request(source_net_log, request_net_log, info, |
| 1165 callback, addresses); | 1152 callback, addresses); |
| 1166 if (out_req) | 1153 if (out_req) |
| 1167 *out_req = reinterpret_cast<RequestHandle>(req); | 1154 *out_req = reinterpret_cast<RequestHandle>(req); |
| 1168 | 1155 |
| 1169 // Next we need to attach our request to a "job". This job is responsible for | 1156 // Next we need to attach our request to a "job". This job is responsible for |
| 1170 // calling "getaddrinfo(hostname)" on a worker thread. | 1157 // calling "getaddrinfo(hostname)" on a worker thread. |
| 1171 scoped_refptr<Job> job; | 1158 scoped_refptr<Job> job; |
| 1172 | 1159 |
| 1173 // If there is already an outstanding job to resolve |key|, use | 1160 // If there is already an outstanding job to resolve |key|, use |
| 1174 // it. This prevents starting concurrent resolves for the same hostname. | 1161 // it. This prevents starting concurrent resolves for the same hostname. |
| 1175 job = FindOutstandingJob(key); | 1162 job = FindOutstandingJob(key); |
| 1176 if (job) { | 1163 if (job) { |
| 1177 job->AddRequest(req); | 1164 job->AddRequest(req); |
| 1178 } else { | 1165 } else { |
| 1179 JobPool* pool = GetPoolForRequest(req); | 1166 JobPool* pool = GetPoolForRequest(req); |
| 1180 if (CanCreateJobForPool(*pool)) { | 1167 if (CanCreateJobForPool(*pool)) { |
| 1181 CreateAndStartJob(req); | 1168 CreateAndStartJob(req); |
| 1182 } else { | 1169 } else { |
| 1183 return EnqueueRequest(pool, req); | 1170 return EnqueueRequest(pool, req); |
| 1184 } | 1171 } |
| 1185 } | 1172 } |
| 1186 | 1173 |
| 1187 // Completion happens during OnJobComplete(Job*). | 1174 // Completion happens during OnJobComplete(Job*). |
| 1188 return ERR_IO_PENDING; | 1175 return ERR_IO_PENDING; |
| 1189 } | 1176 } |
| 1190 | 1177 |
| 1191 int HostResolverImpl::ResolveHelper(int request_id, | 1178 int HostResolverImpl::ResolveHelper(const Key& key, |
| 1192 const Key& key, | |
| 1193 const RequestInfo& info, | 1179 const RequestInfo& info, |
| 1194 AddressList* addresses, | 1180 AddressList* addresses, |
| 1195 const BoundNetLog& request_net_log) { | 1181 const BoundNetLog& request_net_log) { |
| 1196 // The result of |getaddrinfo| for empty hosts is inconsistent across systems. | 1182 // The result of |getaddrinfo| for empty hosts is inconsistent across systems. |
| 1197 // On Windows it gives the default interface's address, whereas on Linux it | 1183 // On Windows it gives the default interface's address, whereas on Linux it |
| 1198 // gives an error. We will make it fail on all platforms for consistency. | 1184 // gives an error. We will make it fail on all platforms for consistency. |
| 1199 if (info.hostname().empty() || info.hostname().size() > kMaxHostLength) | 1185 if (info.hostname().empty() || info.hostname().size() > kMaxHostLength) |
| 1200 return ERR_NAME_NOT_RESOLVED; | 1186 return ERR_NAME_NOT_RESOLVED; |
| 1201 | 1187 |
| 1202 int net_error = ERR_UNEXPECTED; | 1188 int net_error = ERR_UNEXPECTED; |
| 1203 if (ResolveAsIP(key, info, &net_error, addresses)) | 1189 if (ResolveAsIP(key, info, &net_error, addresses)) |
| 1204 return net_error; | 1190 return net_error; |
| 1205 net_error = ERR_DNS_CACHE_MISS; | 1191 net_error = ERR_DNS_CACHE_MISS; |
| 1206 ServeFromCache(key, info, request_net_log, &net_error, addresses); | 1192 ServeFromCache(key, info, request_net_log, &net_error, addresses); |
| 1207 return net_error; | 1193 return net_error; |
| 1208 } | 1194 } |
| 1209 | 1195 |
| 1210 int HostResolverImpl::ResolveFromCache(const RequestInfo& info, | 1196 int HostResolverImpl::ResolveFromCache(const RequestInfo& info, |
| 1211 AddressList* addresses, | 1197 AddressList* addresses, |
| 1212 const BoundNetLog& source_net_log) { | 1198 const BoundNetLog& source_net_log) { |
| 1213 DCHECK(CalledOnValidThread()); | 1199 DCHECK(CalledOnValidThread()); |
| 1214 DCHECK(addresses); | 1200 DCHECK(addresses); |
| 1215 | 1201 |
| 1216 // Choose a unique ID number for observers to see. | |
| 1217 int request_id = next_request_id_++; | |
| 1218 | |
| 1219 // Make a log item for the request. | 1202 // Make a log item for the request. |
| 1220 BoundNetLog request_net_log = BoundNetLog::Make(net_log_, | 1203 BoundNetLog request_net_log = BoundNetLog::Make(net_log_, |
| 1221 NetLog::SOURCE_HOST_RESOLVER_IMPL_REQUEST); | 1204 NetLog::SOURCE_HOST_RESOLVER_IMPL_REQUEST); |
| 1222 | 1205 |
| 1223 // Update the net log and notify registered observers. | 1206 // Update the net log and notify registered observers. |
| 1224 OnStartRequest(source_net_log, request_net_log, request_id, info); | 1207 OnStartRequest(source_net_log, request_net_log, info); |
| 1225 | 1208 |
| 1226 // Build a key that identifies the request in the cache and in the | 1209 // Build a key that identifies the request in the cache and in the |
| 1227 // outstanding jobs map. | 1210 // outstanding jobs map. |
| 1228 Key key = GetEffectiveKeyForRequest(info); | 1211 Key key = GetEffectiveKeyForRequest(info); |
| 1229 | 1212 |
| 1230 int rv = ResolveHelper(request_id, key, info, addresses, request_net_log); | 1213 int rv = ResolveHelper(key, info, addresses, request_net_log); |
| 1231 OnFinishRequest(source_net_log, request_net_log, request_id, info, | 1214 OnFinishRequest(source_net_log, request_net_log, info, |
| 1232 rv, | 1215 rv, |
| 1233 0 /* os_error (unknown since from cache) */); | 1216 0 /* os_error (unknown since from cache) */); |
| 1234 return rv; | 1217 return rv; |
| 1235 } | 1218 } |
| 1236 | 1219 |
| 1237 // See OnJobComplete(Job*) for why it is important not to clean out | 1220 // See OnJobComplete(Job*) for why it is important not to clean out |
| 1238 // cancelled requests from Job::requests_. | 1221 // cancelled requests from Job::requests_. |
| 1239 void HostResolverImpl::CancelRequest(RequestHandle req_handle) { | 1222 void HostResolverImpl::CancelRequest(RequestHandle req_handle) { |
| 1240 DCHECK(CalledOnValidThread()); | 1223 DCHECK(CalledOnValidThread()); |
| 1241 Request* req = reinterpret_cast<Request*>(req_handle); | 1224 Request* req = reinterpret_cast<Request*>(req_handle); |
| 1242 DCHECK(req); | 1225 DCHECK(req); |
| 1243 | 1226 |
| 1244 scoped_ptr<Request> request_deleter; // Frees at end of function. | 1227 scoped_ptr<Request> request_deleter; // Frees at end of function. |
| 1245 | 1228 |
| 1246 if (!req->job()) { | 1229 if (!req->job()) { |
| 1247 // If the request was not attached to a job yet, it must have been | 1230 // If the request was not attached to a job yet, it must have been |
| 1248 // enqueued into a pool. Remove it from that pool's queue. | 1231 // enqueued into a pool. Remove it from that pool's queue. |
| 1249 // Otherwise if it was attached to a job, the job is responsible for | 1232 // Otherwise if it was attached to a job, the job is responsible for |
| 1250 // deleting it. | 1233 // deleting it. |
| 1251 JobPool* pool = GetPoolForRequest(req); | 1234 JobPool* pool = GetPoolForRequest(req); |
| 1252 pool->RemovePendingRequest(req); | 1235 pool->RemovePendingRequest(req); |
| 1253 request_deleter.reset(req); | 1236 request_deleter.reset(req); |
| 1254 } else { | 1237 } else { |
| 1255 req->request_net_log().EndEvent( | 1238 req->request_net_log().EndEvent( |
| 1256 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_ATTACH, NULL); | 1239 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_ATTACH, NULL); |
| 1257 } | 1240 } |
| 1258 | 1241 |
| 1259 // NULL out the fields of req, to mark it as cancelled. | 1242 // NULL out the fields of req, to mark it as cancelled. |
| 1260 req->MarkAsCancelled(); | 1243 req->MarkAsCancelled(); |
| 1261 OnCancelRequest(req->source_net_log(), req->request_net_log(), req->id(), | 1244 OnCancelRequest(req->source_net_log(), req->request_net_log(), req->info()); |
| 1262 req->info()); | |
| 1263 } | |
| 1264 | |
| 1265 void HostResolverImpl::AddObserver(HostResolver::Observer* observer) { | |
| 1266 DCHECK(CalledOnValidThread()); | |
| 1267 observers_.push_back(observer); | |
| 1268 } | |
| 1269 | |
| 1270 void HostResolverImpl::RemoveObserver(HostResolver::Observer* observer) { | |
| 1271 DCHECK(CalledOnValidThread()); | |
| 1272 ObserversList::iterator it = | |
| 1273 std::find(observers_.begin(), observers_.end(), observer); | |
| 1274 | |
| 1275 // Observer must exist. | |
| 1276 DCHECK(it != observers_.end()); | |
| 1277 | |
| 1278 observers_.erase(it); | |
| 1279 } | 1245 } |
| 1280 | 1246 |
| 1281 void HostResolverImpl::SetDefaultAddressFamily(AddressFamily address_family) { | 1247 void HostResolverImpl::SetDefaultAddressFamily(AddressFamily address_family) { |
| 1282 DCHECK(CalledOnValidThread()); | 1248 DCHECK(CalledOnValidThread()); |
| 1283 ipv6_probe_monitoring_ = false; | 1249 ipv6_probe_monitoring_ = false; |
| 1284 DiscardIPv6ProbeJob(); | 1250 DiscardIPv6ProbeJob(); |
| 1285 default_address_family_ = address_family; | 1251 default_address_family_ = address_family; |
| 1286 } | 1252 } |
| 1287 | 1253 |
| 1288 AddressFamily HostResolverImpl::GetDefaultAddressFamily() const { | 1254 AddressFamily HostResolverImpl::GetDefaultAddressFamily() const { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1408 // Complete all of the requests that were attached to the job. | 1374 // Complete all of the requests that were attached to the job. |
| 1409 for (RequestsList::const_iterator it = job->requests().begin(); | 1375 for (RequestsList::const_iterator it = job->requests().begin(); |
| 1410 it != job->requests().end(); ++it) { | 1376 it != job->requests().end(); ++it) { |
| 1411 Request* req = *it; | 1377 Request* req = *it; |
| 1412 if (!req->was_cancelled()) { | 1378 if (!req->was_cancelled()) { |
| 1413 DCHECK_EQ(job, req->job()); | 1379 DCHECK_EQ(job, req->job()); |
| 1414 req->request_net_log().EndEvent( | 1380 req->request_net_log().EndEvent( |
| 1415 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_ATTACH, NULL); | 1381 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_ATTACH, NULL); |
| 1416 | 1382 |
| 1417 // Update the net log and notify registered observers. | 1383 // Update the net log and notify registered observers. |
| 1418 OnFinishRequest(req->source_net_log(), req->request_net_log(), req->id(), | 1384 OnFinishRequest(req->source_net_log(), req->request_net_log(), |
| 1419 req->info(), net_error, os_error); | 1385 req->info(), net_error, os_error); |
| 1420 | 1386 |
| 1421 req->OnComplete(net_error, addrlist); | 1387 req->OnComplete(net_error, addrlist); |
| 1422 | 1388 |
| 1423 // Check if the job was cancelled as a result of running the callback. | 1389 // Check if the job was cancelled as a result of running the callback. |
| 1424 // (Meaning that |this| was deleted). | 1390 // (Meaning that |this| was deleted). |
| 1425 if (job->was_cancelled()) | 1391 if (job->was_cancelled()) |
| 1426 return; | 1392 return; |
| 1427 } | 1393 } |
| 1428 } | 1394 } |
| 1429 | 1395 |
| 1430 cur_completing_job_ = NULL; | 1396 cur_completing_job_ = NULL; |
| 1431 } | 1397 } |
| 1432 | 1398 |
| 1433 void HostResolverImpl::OnStartRequest(const BoundNetLog& source_net_log, | 1399 void HostResolverImpl::OnStartRequest(const BoundNetLog& source_net_log, |
| 1434 const BoundNetLog& request_net_log, | 1400 const BoundNetLog& request_net_log, |
| 1435 int request_id, | |
| 1436 const RequestInfo& info) { | 1401 const RequestInfo& info) { |
| 1437 source_net_log.BeginEvent( | 1402 source_net_log.BeginEvent( |
| 1438 NetLog::TYPE_HOST_RESOLVER_IMPL, | 1403 NetLog::TYPE_HOST_RESOLVER_IMPL, |
| 1439 make_scoped_refptr(new NetLogSourceParameter( | 1404 make_scoped_refptr(new NetLogSourceParameter( |
| 1440 "source_dependency", request_net_log.source()))); | 1405 "source_dependency", request_net_log.source()))); |
| 1441 | 1406 |
| 1442 request_net_log.BeginEvent( | 1407 request_net_log.BeginEvent( |
| 1443 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, | 1408 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, |
| 1444 make_scoped_refptr(new RequestInfoParameters( | 1409 make_scoped_refptr(new RequestInfoParameters( |
| 1445 info, source_net_log.source()))); | 1410 info, source_net_log.source()))); |
| 1446 | |
| 1447 // Notify the observers of the start. | |
| 1448 if (!observers_.empty()) { | |
| 1449 for (ObserversList::iterator it = observers_.begin(); | |
| 1450 it != observers_.end(); ++it) { | |
| 1451 (*it)->OnStartResolution(request_id, info); | |
| 1452 } | |
| 1453 } | |
| 1454 } | 1411 } |
| 1455 | 1412 |
| 1456 void HostResolverImpl::OnFinishRequest(const BoundNetLog& source_net_log, | 1413 void HostResolverImpl::OnFinishRequest(const BoundNetLog& source_net_log, |
| 1457 const BoundNetLog& request_net_log, | 1414 const BoundNetLog& request_net_log, |
| 1458 int request_id, | |
| 1459 const RequestInfo& info, | 1415 const RequestInfo& info, |
| 1460 int net_error, | 1416 int net_error, |
| 1461 int os_error) { | 1417 int os_error) { |
| 1462 bool was_resolved = net_error == OK; | 1418 bool was_resolved = net_error == OK; |
| 1463 | 1419 |
| 1464 // Notify the observers of the completion. | |
| 1465 if (!observers_.empty()) { | |
| 1466 for (ObserversList::iterator it = observers_.begin(); | |
| 1467 it != observers_.end(); ++it) { | |
| 1468 (*it)->OnFinishResolutionWithStatus(request_id, was_resolved, info); | |
| 1469 } | |
| 1470 } | |
| 1471 | |
| 1472 // Log some extra parameters on failure for synchronous requests. | 1420 // Log some extra parameters on failure for synchronous requests. |
| 1473 scoped_refptr<NetLog::EventParameters> params; | 1421 scoped_refptr<NetLog::EventParameters> params; |
| 1474 if (!was_resolved) { | 1422 if (!was_resolved) { |
| 1475 params = new HostResolveFailedParams(0, net_error, os_error); | 1423 params = new HostResolveFailedParams(0, net_error, os_error); |
| 1476 } | 1424 } |
| 1477 | 1425 |
| 1478 request_net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, params); | 1426 request_net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, params); |
| 1479 source_net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL, NULL); | 1427 source_net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL, NULL); |
| 1480 } | 1428 } |
| 1481 | 1429 |
| 1482 void HostResolverImpl::OnCancelRequest(const BoundNetLog& source_net_log, | 1430 void HostResolverImpl::OnCancelRequest(const BoundNetLog& source_net_log, |
| 1483 const BoundNetLog& request_net_log, | 1431 const BoundNetLog& request_net_log, |
| 1484 int request_id, | |
| 1485 const RequestInfo& info) { | 1432 const RequestInfo& info) { |
| 1486 request_net_log.AddEvent(NetLog::TYPE_CANCELLED, NULL); | 1433 request_net_log.AddEvent(NetLog::TYPE_CANCELLED, NULL); |
| 1487 | |
| 1488 // Notify the observers of the cancellation. | |
| 1489 if (!observers_.empty()) { | |
| 1490 for (ObserversList::iterator it = observers_.begin(); | |
| 1491 it != observers_.end(); ++it) { | |
| 1492 (*it)->OnCancelResolution(request_id, info); | |
| 1493 } | |
| 1494 } | |
| 1495 | |
| 1496 request_net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, NULL); | 1434 request_net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, NULL); |
| 1497 source_net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL, NULL); | 1435 source_net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL, NULL); |
| 1498 } | 1436 } |
| 1499 | 1437 |
| 1500 void HostResolverImpl::DiscardIPv6ProbeJob() { | 1438 void HostResolverImpl::DiscardIPv6ProbeJob() { |
| 1501 if (ipv6_probe_job_.get()) { | 1439 if (ipv6_probe_job_.get()) { |
| 1502 ipv6_probe_job_->Cancel(); | 1440 ipv6_probe_job_->Cancel(); |
| 1503 ipv6_probe_job_ = NULL; | 1441 ipv6_probe_job_ = NULL; |
| 1504 } | 1442 } |
| 1505 } | 1443 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1590 | 1528 |
| 1591 int HostResolverImpl::EnqueueRequest(JobPool* pool, Request* req) { | 1529 int HostResolverImpl::EnqueueRequest(JobPool* pool, Request* req) { |
| 1592 scoped_ptr<Request> req_evicted_from_queue( | 1530 scoped_ptr<Request> req_evicted_from_queue( |
| 1593 pool->InsertPendingRequest(req)); | 1531 pool->InsertPendingRequest(req)); |
| 1594 | 1532 |
| 1595 // If the queue has become too large, we need to kick something out. | 1533 // If the queue has become too large, we need to kick something out. |
| 1596 if (req_evicted_from_queue.get()) { | 1534 if (req_evicted_from_queue.get()) { |
| 1597 Request* r = req_evicted_from_queue.get(); | 1535 Request* r = req_evicted_from_queue.get(); |
| 1598 int error = ERR_HOST_RESOLVER_QUEUE_TOO_LARGE; | 1536 int error = ERR_HOST_RESOLVER_QUEUE_TOO_LARGE; |
| 1599 | 1537 |
| 1600 OnFinishRequest(r->source_net_log(), r->request_net_log(), r->id(), | 1538 OnFinishRequest(r->source_net_log(), r->request_net_log(), r->info(), error, |
| 1601 r->info(), error, | |
| 1602 0 /* os_error (not applicable) */); | 1539 0 /* os_error (not applicable) */); |
| 1603 | 1540 |
| 1604 if (r == req) | 1541 if (r == req) |
| 1605 return error; | 1542 return error; |
| 1606 | 1543 |
| 1607 r->OnComplete(error, AddressList()); | 1544 r->OnComplete(error, AddressList()); |
| 1608 } | 1545 } |
| 1609 | 1546 |
| 1610 return ERR_IO_PENDING; | 1547 return ERR_IO_PENDING; |
| 1611 } | 1548 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1654 // resolv.conf changes so we don't need to do anything to clear that cache. | 1591 // resolv.conf changes so we don't need to do anything to clear that cache. |
| 1655 if (cache_.get()) | 1592 if (cache_.get()) |
| 1656 cache_->clear(); | 1593 cache_->clear(); |
| 1657 // Existing jobs will have been sent to the original server so they need to | 1594 // Existing jobs will have been sent to the original server so they need to |
| 1658 // be aborted. TODO(Craig): Should these jobs be restarted? | 1595 // be aborted. TODO(Craig): Should these jobs be restarted? |
| 1659 AbortAllInProgressJobs(); | 1596 AbortAllInProgressJobs(); |
| 1660 // |this| may be deleted inside AbortAllInProgressJobs(). | 1597 // |this| may be deleted inside AbortAllInProgressJobs(). |
| 1661 } | 1598 } |
| 1662 | 1599 |
| 1663 } // namespace net | 1600 } // namespace net |
| OLD | NEW |