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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
16 #include "components/network_hints/common/network_hints_common.h" | 16 #include "components/network_hints/common/network_hints_common.h" |
17 #include "components/network_hints/common/network_hints_messages.h" | 17 #include "components/network_hints/common/network_hints_param_traits.h" |
Sam McNally
2016/07/12 05:25:30
Remove.
tibell
2016/07/12 07:14:24
Done.
| |
18 #include "components/network_hints/renderer/dns_prefetch_queue.h" | 18 #include "components/network_hints/renderer/dns_prefetch_queue.h" |
19 #include "content/public/renderer/render_thread.h" | 19 #include "content/public/renderer/render_thread.h" |
20 #include "services/shell/public/cpp/interface_provider.h" | |
20 | 21 |
21 using content::RenderThread; | 22 using content::RenderThread; |
22 | 23 |
23 namespace network_hints { | 24 namespace network_hints { |
24 | 25 |
25 RendererDnsPrefetch::RendererDnsPrefetch() | 26 RendererDnsPrefetch::RendererDnsPrefetch() |
26 : c_string_queue_(1000), | 27 : c_string_queue_(1000), |
27 weak_factory_(this) { | 28 weak_factory_(this) { |
28 Reset(); | 29 Reset(); |
29 } | 30 } |
30 | 31 |
31 RendererDnsPrefetch::~RendererDnsPrefetch() { | 32 RendererDnsPrefetch::~RendererDnsPrefetch() { |
32 } | 33 } |
33 | 34 |
34 void RendererDnsPrefetch::Reset() { | 35 void RendererDnsPrefetch::Reset() { |
35 domain_map_.clear(); | 36 domain_map_.clear(); |
36 c_string_queue_.Clear(); | 37 c_string_queue_.Clear(); |
37 buffer_full_discard_count_ = 0; | 38 buffer_full_discard_count_ = 0; |
38 numeric_ip_discard_count_ = 0; | 39 numeric_ip_discard_count_ = 0; |
39 new_name_count_ = 0; | 40 new_name_count_ = 0; |
40 } | 41 } |
41 | 42 |
43 void RendererDnsPrefetch::EnsureConnected() { | |
44 DCHECK(content::RenderThread::Get()); | |
45 if (!network_hints_.is_bound()) { | |
46 RenderThread::Get()->GetRemoteInterfaces()->GetInterface( | |
47 mojo::GetProxy(&network_hints_)); | |
48 } | |
49 } | |
50 | |
42 // Push names into queue quickly! | 51 // Push names into queue quickly! |
43 void RendererDnsPrefetch::Resolve(const char* name, size_t length) { | 52 void RendererDnsPrefetch::Resolve(const char* name, size_t length) { |
44 DCHECK(content::RenderThread::Get()); | 53 DCHECK(content::RenderThread::Get()); |
45 if (!length) | 54 if (!length) |
46 return; // Don't store empty strings in buffer. | 55 return; // Don't store empty strings in buffer. |
47 if (is_numeric_ip(name, length)) | 56 if (is_numeric_ip(name, length)) |
48 return; // Numeric IPs have no DNS lookup significance. | 57 return; // Numeric IPs have no DNS lookup significance. |
49 | 58 |
50 size_t old_size = c_string_queue_.Size(); | 59 size_t old_size = c_string_queue_.Size(); |
51 DnsQueue::PushResult result = c_string_queue_.Push(name, length); | 60 DnsQueue::PushResult result = c_string_queue_.Push(name, length); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 if (1 == max_count) break; | 155 if (1 == max_count) break; |
147 --max_count; | 156 --max_count; |
148 DCHECK_GE(max_count, 1u); | 157 DCHECK_GE(max_count, 1u); |
149 } | 158 } |
150 } | 159 } |
151 DCHECK_GE(new_name_count_, domains_handled); | 160 DCHECK_GE(new_name_count_, domains_handled); |
152 new_name_count_ -= domains_handled; | 161 new_name_count_ -= domains_handled; |
153 | 162 |
154 network_hints::LookupRequest request; | 163 network_hints::LookupRequest request; |
155 request.hostname_list = names; | 164 request.hostname_list = names; |
156 RenderThread::Get()->Send(new NetworkHintsMsg_DNSPrefetch(request)); | 165 EnsureConnected(); |
166 network_hints_->DNSPrefetch(request); | |
157 } | 167 } |
158 | 168 |
159 // is_numeric_ip() checks to see if all characters in name are either numeric, | 169 // is_numeric_ip() checks to see if all characters in name are either numeric, |
160 // or dots. Such a name will not actually be passed to DNS, as it is an IP | 170 // or dots. Such a name will not actually be passed to DNS, as it is an IP |
161 // address. | 171 // address. |
162 bool RendererDnsPrefetch::is_numeric_ip(const char* name, size_t length) { | 172 bool RendererDnsPrefetch::is_numeric_ip(const char* name, size_t length) { |
163 // Scan for a character outside our lookup list. | 173 // Scan for a character outside our lookup list. |
164 while (length-- > 0) { | 174 while (length-- > 0) { |
165 if (!isdigit(*name) && '.' != *name) | 175 if (!isdigit(*name) && '.' != *name) |
166 return false; | 176 return false; |
167 ++name; | 177 ++name; |
168 } | 178 } |
169 return true; | 179 return true; |
170 } | 180 } |
171 | 181 |
172 } // namespace predictor | 182 } // namespace predictor |
OLD | NEW |