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

Side by Side Diff: components/network_hints/renderer/renderer_dns_prefetch.cc

Issue 2179693002: Revert of Convert network hints to Mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
OLDNEW
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/renderer/dns_prefetch_queue.h" 18 #include "components/network_hints/renderer/dns_prefetch_queue.h"
18 #include "content/public/renderer/render_thread.h" 19 #include "content/public/renderer/render_thread.h"
19 #include "services/shell/public/cpp/interface_provider.h"
20 20
21 using content::RenderThread; 21 using content::RenderThread;
22 22
23 namespace network_hints { 23 namespace network_hints {
24 24
25 RendererDnsPrefetch::RendererDnsPrefetch() 25 RendererDnsPrefetch::RendererDnsPrefetch()
26 : c_string_queue_(1000), 26 : c_string_queue_(1000),
27 weak_factory_(this) { 27 weak_factory_(this) {
28 Reset(); 28 Reset();
29 } 29 }
30 30
31 RendererDnsPrefetch::~RendererDnsPrefetch() { 31 RendererDnsPrefetch::~RendererDnsPrefetch() {
32 } 32 }
33 33
34 void RendererDnsPrefetch::Reset() { 34 void RendererDnsPrefetch::Reset() {
35 domain_map_.clear(); 35 domain_map_.clear();
36 c_string_queue_.Clear(); 36 c_string_queue_.Clear();
37 buffer_full_discard_count_ = 0; 37 buffer_full_discard_count_ = 0;
38 numeric_ip_discard_count_ = 0; 38 numeric_ip_discard_count_ = 0;
39 new_name_count_ = 0; 39 new_name_count_ = 0;
40 } 40 }
41 41
42 mojom::NetworkHints& RendererDnsPrefetch::GetNetworkHints() {
43 DCHECK(content::RenderThread::Get());
44 if (!network_hints_) {
45 RenderThread::Get()->GetRemoteInterfaces()->GetInterface(
46 mojo::GetProxy(&network_hints_));
47 }
48 return *network_hints_;
49 }
50
51 // Push names into queue quickly! 42 // Push names into queue quickly!
52 void RendererDnsPrefetch::Resolve(const char* name, size_t length) { 43 void RendererDnsPrefetch::Resolve(const char* name, size_t length) {
53 DCHECK(content::RenderThread::Get()); 44 DCHECK(content::RenderThread::Get());
54 if (!length) 45 if (!length)
55 return; // Don't store empty strings in buffer. 46 return; // Don't store empty strings in buffer.
56 if (is_numeric_ip(name, length)) 47 if (is_numeric_ip(name, length))
57 return; // Numeric IPs have no DNS lookup significance. 48 return; // Numeric IPs have no DNS lookup significance.
58 49
59 size_t old_size = c_string_queue_.Size(); 50 size_t old_size = c_string_queue_.Size();
60 DnsQueue::PushResult result = c_string_queue_.Push(name, length); 51 DnsQueue::PushResult result = c_string_queue_.Push(name, length);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 if (1 == max_count) break; 146 if (1 == max_count) break;
156 --max_count; 147 --max_count;
157 DCHECK_GE(max_count, 1u); 148 DCHECK_GE(max_count, 1u);
158 } 149 }
159 } 150 }
160 DCHECK_GE(new_name_count_, domains_handled); 151 DCHECK_GE(new_name_count_, domains_handled);
161 new_name_count_ -= domains_handled; 152 new_name_count_ -= domains_handled;
162 153
163 network_hints::LookupRequest request; 154 network_hints::LookupRequest request;
164 request.hostname_list = names; 155 request.hostname_list = names;
165 GetNetworkHints().DNSPrefetch(request); 156 RenderThread::Get()->Send(new NetworkHintsMsg_DNSPrefetch(request));
166 } 157 }
167 158
168 // is_numeric_ip() checks to see if all characters in name are either numeric, 159 // is_numeric_ip() checks to see if all characters in name are either numeric,
169 // or dots. Such a name will not actually be passed to DNS, as it is an IP 160 // or dots. Such a name will not actually be passed to DNS, as it is an IP
170 // address. 161 // address.
171 bool RendererDnsPrefetch::is_numeric_ip(const char* name, size_t length) { 162 bool RendererDnsPrefetch::is_numeric_ip(const char* name, size_t length) {
172 // Scan for a character outside our lookup list. 163 // Scan for a character outside our lookup list.
173 while (length-- > 0) { 164 while (length-- > 0) {
174 if (!isdigit(*name) && '.' != *name) 165 if (!isdigit(*name) && '.' != *name)
175 return false; 166 return false;
176 ++name; 167 ++name;
177 } 168 }
178 return true; 169 return true;
179 } 170 }
180 171
181 } // namespace predictor 172 } // namespace predictor
OLDNEW
« no previous file with comments | « components/network_hints/renderer/renderer_dns_prefetch.h ('k') | components/network_hints/renderer/renderer_preconnect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698