OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // See header file for description of RendererDnsPrefetch class | 5 // See header file for description of RendererDnsPrefetch class |
6 | 6 |
7 #include "components/network_hints/renderer/renderer_dns_prefetch.h" | 7 #include "components/network_hints/renderer/renderer_dns_prefetch.h" |
8 | 8 |
9 #include <ctype.h> | 9 #include <ctype.h> |
10 | 10 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 --count; | 123 --count; |
124 } else { | 124 } else { |
125 DCHECK(kPending == it->second || kLookupRequested == it->second); | 125 DCHECK(kPending == it->second || kLookupRequested == it->second); |
126 } | 126 } |
127 } | 127 } |
128 } | 128 } |
129 | 129 |
130 void RendererDnsPrefetch::DnsPrefetchNames(size_t max_count) { | 130 void RendererDnsPrefetch::DnsPrefetchNames(size_t max_count) { |
131 // We are on the renderer thread, and just need to send things to the browser. | 131 // We are on the renderer thread, and just need to send things to the browser. |
132 NameList names; | 132 NameList names; |
| 133 size_t domains_handled = 0; |
133 for (DomainUseMap::iterator it = domain_map_.begin(); | 134 for (DomainUseMap::iterator it = domain_map_.begin(); |
134 it != domain_map_.end(); | 135 it != domain_map_.end(); |
135 ++it) { | 136 ++it) { |
136 if (0 == (it->second & kLookupRequested)) { | 137 if (0 == (it->second & kLookupRequested)) { |
137 it->second |= kLookupRequested; | 138 it->second |= kLookupRequested; |
138 names.push_back(it->first); | 139 domains_handled++; |
| 140 if (it->first.length() <= network_hints::kMaxDnsHostnameLength) |
| 141 names.push_back(it->first); |
139 if (0 == max_count) continue; // Get all, independent of count. | 142 if (0 == max_count) continue; // Get all, independent of count. |
140 if (1 == max_count) break; | 143 if (1 == max_count) break; |
141 --max_count; | 144 --max_count; |
142 DCHECK_GE(max_count, 1u); | 145 DCHECK_GE(max_count, 1u); |
143 } | 146 } |
144 } | 147 } |
145 DCHECK_GE(new_name_count_, names.size()); | 148 DCHECK_GE(new_name_count_, domains_handled); |
146 new_name_count_ -= names.size(); | 149 new_name_count_ -= domains_handled; |
147 | 150 |
148 network_hints::LookupRequest request; | 151 network_hints::LookupRequest request; |
149 request.hostname_list = names; | 152 request.hostname_list = names; |
150 RenderThread::Get()->Send(new NetworkHintsMsg_DNSPrefetch(request)); | 153 RenderThread::Get()->Send(new NetworkHintsMsg_DNSPrefetch(request)); |
151 } | 154 } |
152 | 155 |
153 // is_numeric_ip() checks to see if all characters in name are either numeric, | 156 // is_numeric_ip() checks to see if all characters in name are either numeric, |
154 // or dots. Such a name will not actually be passed to DNS, as it is an IP | 157 // or dots. Such a name will not actually be passed to DNS, as it is an IP |
155 // address. | 158 // address. |
156 bool RendererDnsPrefetch::is_numeric_ip(const char* name, size_t length) { | 159 bool RendererDnsPrefetch::is_numeric_ip(const char* name, size_t length) { |
157 // Scan for a character outside our lookup list. | 160 // Scan for a character outside our lookup list. |
158 while (length-- > 0) { | 161 while (length-- > 0) { |
159 if (!isdigit(*name) && '.' != *name) | 162 if (!isdigit(*name) && '.' != *name) |
160 return false; | 163 return false; |
161 ++name; | 164 ++name; |
162 } | 165 } |
163 return true; | 166 return true; |
164 } | 167 } |
165 | 168 |
166 } // namespace predictor | 169 } // namespace predictor |
OLD | NEW |