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

Side by Side Diff: net/tools/fetch/fetch_client.cc

Issue 118100: Avoid doing concurrent DNS resolves of the same hostname (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Get compiling on mac Created 11 years, 6 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "base/at_exit.h" 5 #include "base/at_exit.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/singleton.h" 8 #include "base/singleton.h"
9 #include "base/stats_counters.h" 9 #include "base/stats_counters.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "net/base/completion_callback.h" 11 #include "net/base/completion_callback.h"
12 #include "net/base/host_resolver.h"
12 #include "net/base/io_buffer.h" 13 #include "net/base/io_buffer.h"
13 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
14 #include "net/http/http_cache.h" 15 #include "net/http/http_cache.h"
15 #include "net/http/http_network_layer.h" 16 #include "net/http/http_network_layer.h"
16 #include "net/http/http_request_info.h" 17 #include "net/http/http_request_info.h"
17 #include "net/http/http_transaction.h" 18 #include "net/http/http_transaction.h"
18 #include "net/proxy/proxy_service.h" 19 #include "net/proxy/proxy_service.h"
19 20
20 void usage(const char* program_name) { 21 void usage(const char* program_name) {
21 printf("usage: %s --url=<url> [--n=<clients>] [--stats] [--use_cache]\n", 22 printf("usage: %s --url=<url> [--n=<clients>] [--stats] [--use_cache]\n",
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 usage(argv[0]); 119 usage(argv[0]);
119 int client_limit = 1; 120 int client_limit = 1;
120 if (parsed_command_line.HasSwitch(L"n")) 121 if (parsed_command_line.HasSwitch(L"n"))
121 StringToInt(WideToASCII(parsed_command_line.GetSwitchValue(L"n")), 122 StringToInt(WideToASCII(parsed_command_line.GetSwitchValue(L"n")),
122 &client_limit); 123 &client_limit);
123 bool use_cache = parsed_command_line.HasSwitch(L"use-cache"); 124 bool use_cache = parsed_command_line.HasSwitch(L"use-cache");
124 125
125 // Do work here. 126 // Do work here.
126 MessageLoop loop; 127 MessageLoop loop;
127 128
129 net::HostResolver host_resolver;
128 scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull()); 130 scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull());
129 net::HttpTransactionFactory* factory = NULL; 131 net::HttpTransactionFactory* factory = NULL;
130 if (use_cache) 132 if (use_cache)
131 factory = new net::HttpCache(proxy_service.get(), 0); 133 factory = new net::HttpCache(&host_resolver, proxy_service.get(), 0);
132 else 134 else
133 factory = new net::HttpNetworkLayer(proxy_service.get()); 135 factory = new net::HttpNetworkLayer(&host_resolver, proxy_service.get());
134 136
135 { 137 {
136 StatsCounterTimer driver_time("FetchClient.total_time"); 138 StatsCounterTimer driver_time("FetchClient.total_time");
137 StatsScope<StatsCounterTimer> scope(driver_time); 139 StatsScope<StatsCounterTimer> scope(driver_time);
138 140
139 Client** clients = new Client*[client_limit]; 141 Client** clients = new Client*[client_limit];
140 for (int i = 0; i < client_limit; i++) 142 for (int i = 0; i < client_limit; i++)
141 clients[i] = new Client(factory, url); 143 clients[i] = new Client(factory, url);
142 144
143 MessageLoop::current()->Run(); 145 MessageLoop::current()->Run();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 std::string name(table.GetRowName(index)); 177 std::string name(table.GetRowName(index));
176 if (name.length() > 0) { 178 if (name.length() > 0) {
177 int value = table.GetRowValue(index); 179 int value = table.GetRowValue(index);
178 printf("%s:\t%d\n", name.c_str(), value); 180 printf("%s:\t%d\n", name.c_str(), value);
179 } 181 }
180 } 182 }
181 printf("</stats>\n"); 183 printf("</stats>\n");
182 } 184 }
183 return 0; 185 return 0;
184 } 186 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698