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

Side by Side Diff: components/dns_prefetch/renderer/renderer_net_predictor.cc

Issue 644123002: Componentize renderer side of DNS prefetching. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: trybot fixes: 1) hide gyp target from ios 2) UintToString --> SizeTToString Created 6 years, 1 month 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 RendererNetPredictor class 5 // See header file for description of RendererNetPredictor class
6 6
7 #include "chrome/renderer/net/renderer_net_predictor.h" 7 #include "components/dns_prefetch/renderer/renderer_net_predictor.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/logging.h" 12 #include "base/logging.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "chrome/common/net/predictor_common.h" 14 #include "components/dns_prefetch/common/prefetch_common.h"
15 #include "chrome/common/render_messages.h" 15 #include "components/dns_prefetch/common/prefetch_messages.h"
16 #include "chrome/renderer/net/predictor_queue.h" 16 #include "components/dns_prefetch/renderer/predictor_queue.h"
17 #include "content/public/renderer/render_thread.h" 17 #include "content/public/renderer/render_thread.h"
18 18
19 using content::RenderThread; 19 using content::RenderThread;
20 20
21 // The number of hostnames submitted to Browser DNS resolver per call to 21 namespace dns_prefetch {
22 // SubmitHostsnames() (which reads names from our queue).
23 static const size_t kMAX_SUBMISSION_PER_TASK = 30;
24 22
25 RendererNetPredictor::RendererNetPredictor() 23 RendererNetPredictor::RendererNetPredictor()
26 : c_string_queue_(1000), 24 : c_string_queue_(1000),
27 weak_factory_(this) { 25 weak_factory_(this) {
28 Reset(); 26 Reset();
29 } 27 }
30 28
31 RendererNetPredictor::~RendererNetPredictor() { 29 RendererNetPredictor::~RendererNetPredictor() {
32 } 30 }
33 31
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // going to send to the browser. That would cause a "silly" page with a TON 75 // going to send to the browser. That would cause a "silly" page with a TON
78 // of URLs to start to overrun the DnsQueue, which will cause the names to 76 // of URLs to start to overrun the DnsQueue, which will cause the names to
79 // be dropped (not stored in the queue). By fetching ALL names, we are 77 // be dropped (not stored in the queue). By fetching ALL names, we are
80 // taking on a lot of work, which may take a long time to process... perhaps 78 // taking on a lot of work, which may take a long time to process... perhaps
81 // longer than the page may be visible!?!?! If we implement a better 79 // longer than the page may be visible!?!?! If we implement a better
82 // mechanism for doing domain_map.clear() (see end of this method), then 80 // mechanism for doing domain_map.clear() (see end of this method), then
83 // we'd automatically flush such pending work from a ridiculously link-filled 81 // we'd automatically flush such pending work from a ridiculously link-filled
84 // page. 82 // page.
85 83
86 // Don't overload the browser DNS lookup facility, or take too long here, 84 // Don't overload the browser DNS lookup facility, or take too long here,
87 // by only sending off kMAX_SUBMISSION_PER_TASK names to the Browser. 85 // by only sending off kMaxDnsHostnamesPerRequest names to the Browser.
88 // This will help to avoid overloads when a page has a TON of links. 86 // This will help to avoid overloads when a page has a TON of links.
89 DnsPrefetchNames(kMAX_SUBMISSION_PER_TASK); 87 DnsPrefetchNames(kMaxDnsHostnamesPerRequest);
90 if (new_name_count_ > 0 || 0 < c_string_queue_.Size()) { 88 if (new_name_count_ > 0 || 0 < c_string_queue_.Size()) {
91 weak_factory_.InvalidateWeakPtrs(); 89 weak_factory_.InvalidateWeakPtrs();
92 RenderThread::Get()->GetMessageLoop()->PostDelayedTask( 90 RenderThread::Get()->GetMessageLoop()->PostDelayedTask(
93 FROM_HERE, base::Bind(&RendererNetPredictor::SubmitHostnames, 91 FROM_HERE, base::Bind(&RendererNetPredictor::SubmitHostnames,
94 weak_factory_.GetWeakPtr()), 92 weak_factory_.GetWeakPtr()),
95 base::TimeDelta::FromMilliseconds(10)); 93 base::TimeDelta::FromMilliseconds(10));
96 } else { 94 } else {
97 // TODO(JAR): Should we only clear the map when we navigate, or reload? 95 // TODO(JAR): Should we only clear the map when we navigate, or reload?
98 domain_map_.clear(); 96 domain_map_.clear();
99 } 97 }
(...skipping 23 matching lines...) Expand all
123 DCHECK_GT(count, 1u); 121 DCHECK_GT(count, 1u);
124 --count; 122 --count;
125 } else { 123 } else {
126 DCHECK(kPending == it->second || kLookupRequested == it->second); 124 DCHECK(kPending == it->second || kLookupRequested == it->second);
127 } 125 }
128 } 126 }
129 } 127 }
130 128
131 void RendererNetPredictor::DnsPrefetchNames(size_t max_count) { 129 void RendererNetPredictor::DnsPrefetchNames(size_t max_count) {
132 // We are on the renderer thread, and just need to send things to the browser. 130 // We are on the renderer thread, and just need to send things to the browser.
133 chrome_common_net::NameList names; 131 NameList names;
134 for (DomainUseMap::iterator it = domain_map_.begin(); 132 for (DomainUseMap::iterator it = domain_map_.begin();
135 it != domain_map_.end(); 133 it != domain_map_.end();
136 ++it) { 134 ++it) {
137 if (0 == (it->second & kLookupRequested)) { 135 if (0 == (it->second & kLookupRequested)) {
138 it->second |= kLookupRequested; 136 it->second |= kLookupRequested;
139 names.push_back(it->first); 137 names.push_back(it->first);
140 if (0 == max_count) continue; // Get all, independent of count. 138 if (0 == max_count) continue; // Get all, independent of count.
141 if (1 == max_count) break; 139 if (1 == max_count) break;
142 --max_count; 140 --max_count;
143 DCHECK_GE(max_count, 1u); 141 DCHECK_GE(max_count, 1u);
144 } 142 }
145 } 143 }
146 DCHECK_GE(new_name_count_, names.size()); 144 DCHECK_GE(new_name_count_, names.size());
147 new_name_count_ -= names.size(); 145 new_name_count_ -= names.size();
148 146
149 RenderThread::Get()->Send(new ChromeViewHostMsg_DnsPrefetch(names)); 147 dns_prefetch::LookupRequest request;
148 request.hostname_list = names;
149 RenderThread::Get()->Send(new DnsPrefetchMsg_RequestPrefetch(request));
150 } 150 }
151 151
152 // is_numeric_ip() checks to see if all characters in name are either numeric, 152 // is_numeric_ip() checks to see if all characters in name are either numeric,
153 // or dots. Such a name will not actually be passed to DNS, as it is an IP 153 // or dots. Such a name will not actually be passed to DNS, as it is an IP
154 // address. 154 // address.
155 bool RendererNetPredictor::is_numeric_ip(const char* name, size_t length) { 155 bool RendererNetPredictor::is_numeric_ip(const char* name, size_t length) {
156 // Scan for a character outside our lookup list. 156 // Scan for a character outside our lookup list.
157 while (length-- > 0) { 157 while (length-- > 0) {
158 if (!isdigit(*name) && '.' != *name) 158 if (!isdigit(*name) && '.' != *name)
159 return false; 159 return false;
160 ++name; 160 ++name;
161 } 161 }
162 return true; 162 return true;
163 } 163 }
164
165 } // namespcae predictor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698