Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1190)

Side by Side Diff: net/base/host_resolver_impl.cc

Issue 9197009: Adds custom ttl argument to HostCache::Set. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed incomplete refactor. Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #endif 43 #endif
44 44
45 namespace net { 45 namespace net {
46 46
47 namespace { 47 namespace {
48 48
49 // Limit the size of hostnames that will be resolved to combat issues in 49 // Limit the size of hostnames that will be resolved to combat issues in
50 // some platform's resolvers. 50 // some platform's resolvers.
51 const size_t kMaxHostLength = 4096; 51 const size_t kMaxHostLength = 4096;
52 52
53 // Default TTL for successful resolutions with ProcTask.
54 const base::TimeDelta kCacheEntryTTL = base::TimeDelta::FromMinutes(1);
55
53 // Helper to mutate the linked list contained by AddressList to the given 56 // Helper to mutate the linked list contained by AddressList to the given
54 // port. Note that in general this is dangerous since the AddressList's 57 // port. Note that in general this is dangerous since the AddressList's
55 // data might be shared (and you should use AddressList::SetPort). 58 // data might be shared (and you should use AddressList::SetPort).
56 // 59 //
57 // However since we allocated the AddressList ourselves we can safely 60 // However since we allocated the AddressList ourselves we can safely
58 // do this optimization and avoid reallocating the list. 61 // do this optimization and avoid reallocating the list.
59 void MutableSetPort(int port, AddressList* addrlist) { 62 void MutableSetPort(int port, AddressList* addrlist) {
60 struct addrinfo* mutable_head = 63 struct addrinfo* mutable_head =
61 const_cast<struct addrinfo*>(addrlist->head()); 64 const_cast<struct addrinfo*>(addrlist->head());
62 SetPortForAllAddrinfos(mutable_head, port); 65 SetPortForAllAddrinfos(mutable_head, port);
(...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 pool->AdjustNumOutstandingJobs(-1); 1349 pool->AdjustNumOutstandingJobs(-1);
1347 } 1350 }
1348 1351
1349 void HostResolverImpl::OnJobComplete(Job* job, 1352 void HostResolverImpl::OnJobComplete(Job* job,
1350 int net_error, 1353 int net_error,
1351 int os_error, 1354 int os_error,
1352 const AddressList& addrlist) { 1355 const AddressList& addrlist) {
1353 RemoveOutstandingJob(job); 1356 RemoveOutstandingJob(job);
1354 1357
1355 // Write result to the cache. 1358 // Write result to the cache.
1356 if (cache_.get()) 1359 if (cache_.get()) {
1357 cache_->Set(job->key(), net_error, addrlist, base::TimeTicks::Now()); 1360 base::TimeDelta ttl = base::TimeDelta::FromSeconds(0);
1358 1361 if (net_error == OK)
1362 ttl = kCacheEntryTTL;
1363 cache_->Set(job->key(), net_error, addrlist,
1364 base::TimeTicks::Now(),
1365 ttl);
1366 }
1359 OnJobCompleteInternal(job, net_error, os_error, addrlist); 1367 OnJobCompleteInternal(job, net_error, os_error, addrlist);
1360 } 1368 }
1361 1369
1362 void HostResolverImpl::AbortJob(Job* job) { 1370 void HostResolverImpl::AbortJob(Job* job) {
1363 OnJobCompleteInternal(job, ERR_ABORTED, 0 /* no os_error */, AddressList()); 1371 OnJobCompleteInternal(job, ERR_ABORTED, 0 /* no os_error */, AddressList());
1364 } 1372 }
1365 1373
1366 void HostResolverImpl::OnJobCompleteInternal( 1374 void HostResolverImpl::OnJobCompleteInternal(
1367 Job* job, 1375 Job* job,
1368 int net_error, 1376 int net_error,
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1596 // resolv.conf changes so we don't need to do anything to clear that cache. 1604 // resolv.conf changes so we don't need to do anything to clear that cache.
1597 if (cache_.get()) 1605 if (cache_.get())
1598 cache_->clear(); 1606 cache_->clear();
1599 // Existing jobs will have been sent to the original server so they need to 1607 // Existing jobs will have been sent to the original server so they need to
1600 // be aborted. TODO(Craig): Should these jobs be restarted? 1608 // be aborted. TODO(Craig): Should these jobs be restarted?
1601 AbortAllInProgressJobs(); 1609 AbortAllInProgressJobs();
1602 // |this| may be deleted inside AbortAllInProgressJobs(). 1610 // |this| may be deleted inside AbortAllInProgressJobs().
1603 } 1611 }
1604 1612
1605 } // namespace net 1613 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698