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

Side by Side Diff: chrome/browser/net/chrome_url_request_context.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
« no previous file with comments | « no previous file | chrome/browser/net/dns_global.cc » ('j') | net/base/address_list.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/browser/net/chrome_url_request_context.h" 5 #include "chrome/browser/net/chrome_url_request_context.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chrome_thread.h" 10 #include "chrome/browser/chrome_thread.h"
11 #include "chrome/browser/extensions/extensions_service.h" 11 #include "chrome/browser/extensions/extensions_service.h"
12 #include "chrome/browser/extensions/user_script_master.h" 12 #include "chrome/browser/extensions/user_script_master.h"
13 #include "chrome/browser/net/dns_global.h"
13 #include "chrome/browser/profile.h" 14 #include "chrome/browser/profile.h"
14 #include "chrome/common/chrome_constants.h" 15 #include "chrome/common/chrome_constants.h"
15 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
17 #include "chrome/common/notification_service.h" 18 #include "chrome/common/notification_service.h"
18 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
19 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
20 #include "net/ftp/ftp_network_layer.h" 21 #include "net/ftp/ftp_network_layer.h"
21 #include "net/http/http_cache.h" 22 #include "net/http/http_cache.h"
22 #include "net/http/http_network_layer.h" 23 #include "net/http/http_network_layer.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 g_browser_process->io_thread()->message_loop()); 103 g_browser_process->io_thread()->message_loop());
103 } 104 }
104 105
105 // static 106 // static
106 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal( 107 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal(
107 Profile* profile, const FilePath& cookie_store_path, 108 Profile* profile, const FilePath& cookie_store_path,
108 const FilePath& disk_cache_path) { 109 const FilePath& disk_cache_path) {
109 DCHECK(!profile->IsOffTheRecord()); 110 DCHECK(!profile->IsOffTheRecord());
110 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); 111 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile);
111 112
113 // Global host resolver for the context.
114 context->host_resolver_ = chrome_browser_net::GetGlobalHostResolver();
115
112 context->proxy_service_ = CreateProxyService( 116 context->proxy_service_ = CreateProxyService(
113 context, *CommandLine::ForCurrentProcess()); 117 context, *CommandLine::ForCurrentProcess());
114 118
115 net::HttpCache* cache = 119 net::HttpCache* cache =
116 new net::HttpCache(context->proxy_service_, 120 new net::HttpCache(context->host_resolver_,
121 context->proxy_service_,
117 disk_cache_path.ToWStringHack(), 0); 122 disk_cache_path.ToWStringHack(), 0);
118 123
119 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 124 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
120 bool record_mode = chrome::kRecordModeEnabled && 125 bool record_mode = chrome::kRecordModeEnabled &&
121 command_line.HasSwitch(switches::kRecordMode); 126 command_line.HasSwitch(switches::kRecordMode);
122 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); 127 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode);
123 128
124 if (record_mode || playback_mode) { 129 if (record_mode || playback_mode) {
125 // Don't use existing cookies and use an in-memory store. 130 // Don't use existing cookies and use an in-memory store.
126 context->cookie_store_ = new net::CookieMonster(); 131 context->cookie_store_ = new net::CookieMonster();
127 cache->set_mode( 132 cache->set_mode(
128 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); 133 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK);
129 } 134 }
130 context->http_transaction_factory_ = cache; 135 context->http_transaction_factory_ = cache;
131 136
132 // The kNewFtp switch is Windows specific only because we have multiple FTP 137 // The kNewFtp switch is Windows specific only because we have multiple FTP
133 // implementations on Windows. 138 // implementations on Windows.
134 #if defined(OS_WIN) 139 #if defined(OS_WIN)
135 if (command_line.HasSwitch(switches::kNewFtp)) 140 if (command_line.HasSwitch(switches::kNewFtp))
136 context->ftp_transaction_factory_ = new net::FtpNetworkLayer; 141 context->ftp_transaction_factory_ =
142 new net::FtpNetworkLayer(context->host_resolver_);
137 #else 143 #else
138 context->ftp_transaction_factory_ = new net::FtpNetworkLayer; 144 context->ftp_transaction_factory_ =
145 new net::FtpNetworkLayer(context->host_resolver_);
139 #endif 146 #endif
140 147
141 // setup cookie store 148 // setup cookie store
142 if (!context->cookie_store_) { 149 if (!context->cookie_store_) {
143 DCHECK(!cookie_store_path.empty()); 150 DCHECK(!cookie_store_path.empty());
144 context->cookie_db_.reset(new SQLitePersistentCookieStore( 151 context->cookie_db_.reset(new SQLitePersistentCookieStore(
145 cookie_store_path.ToWStringHack(), 152 cookie_store_path.ToWStringHack(),
146 g_browser_process->db_thread()->message_loop())); 153 g_browser_process->db_thread()->message_loop()));
147 context->cookie_store_ = new net::CookieMonster(context->cookie_db_.get()); 154 context->cookie_store_ = new net::CookieMonster(context->cookie_db_.get());
148 } 155 }
(...skipping 27 matching lines...) Expand all
176 183
177 return context; 184 return context;
178 } 185 }
179 186
180 // static 187 // static
181 ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecord( 188 ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecord(
182 Profile* profile) { 189 Profile* profile) {
183 DCHECK(profile->IsOffTheRecord()); 190 DCHECK(profile->IsOffTheRecord());
184 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); 191 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile);
185 192
186 // Share the same proxy service as the original profile. This proxy 193 // Share the same proxy service and host resolver as the original profile.
187 // service's lifespan is dependent on the lifespan of the original profile, 194 // This proxy service's lifespan is dependent on the lifespan of the original
188 // which we reference (see above). 195 // profile which we reference (see above).
196 context->host_resolver_ =
197 profile->GetOriginalProfile()->GetRequestContext()->host_resolver();
189 context->proxy_service_ = 198 context->proxy_service_ =
190 profile->GetOriginalProfile()->GetRequestContext()->proxy_service(); 199 profile->GetOriginalProfile()->GetRequestContext()->proxy_service();
191 200
192 context->http_transaction_factory_ = 201 context->http_transaction_factory_ =
193 new net::HttpCache(context->proxy_service_, 0); 202 new net::HttpCache(context->host_resolver_, context->proxy_service_, 0);
194 context->cookie_store_ = new net::CookieMonster; 203 context->cookie_store_ = new net::CookieMonster;
195 204
196 return context; 205 return context;
197 } 206 }
198 207
199 // static 208 // static
200 ChromeURLRequestContext* 209 ChromeURLRequestContext*
201 ChromeURLRequestContext::CreateOffTheRecordForExtensions(Profile* profile) { 210 ChromeURLRequestContext::CreateOffTheRecordForExtensions(Profile* profile) {
202 DCHECK(profile->IsOffTheRecord()); 211 DCHECK(profile->IsOffTheRecord());
203 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); 212 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile);
(...skipping 30 matching lines...) Expand all
234 // by HttpNetworkLayer so we can reuse HttpNetworkSession within it. This 243 // by HttpNetworkLayer so we can reuse HttpNetworkSession within it. This
235 // assumption will be invalid if the original HttpCache is constructed with 244 // assumption will be invalid if the original HttpCache is constructed with
236 // HttpCache(HttpTransactionFactory*, disk_cache::Backend*) constructor. 245 // HttpCache(HttpTransactionFactory*, disk_cache::Backend*) constructor.
237 net::HttpNetworkLayer* original_network_layer = 246 net::HttpNetworkLayer* original_network_layer =
238 static_cast<net::HttpNetworkLayer*>(original_cache->network_layer()); 247 static_cast<net::HttpNetworkLayer*>(original_cache->network_layer());
239 cache = new net::HttpCache(original_network_layer->GetSession(), 248 cache = new net::HttpCache(original_network_layer->GetSession(),
240 disk_cache_path.ToWStringHack(), 0); 249 disk_cache_path.ToWStringHack(), 0);
241 } else { 250 } else {
242 // If original HttpCache doesn't exist, simply construct one with a whole 251 // If original HttpCache doesn't exist, simply construct one with a whole
243 // new set of network stack. 252 // new set of network stack.
244 cache = new net::HttpCache(original_context->proxy_service(), 253 cache = new net::HttpCache(original_context->host_resolver(),
254 original_context->proxy_service(),
245 disk_cache_path.ToWStringHack(), 0); 255 disk_cache_path.ToWStringHack(), 0);
246 } 256 }
247 257
248 cache->set_type(net::MEDIA_CACHE); 258 cache->set_type(net::MEDIA_CACHE);
249 context->http_transaction_factory_ = cache; 259 context->http_transaction_factory_ = cache;
250 return context; 260 return context;
251 } 261 }
252 262
253 ChromeURLRequestContext::ChromeURLRequestContext(Profile* profile) 263 ChromeURLRequestContext::ChromeURLRequestContext(Profile* profile)
254 : prefs_(profile->GetPrefs()), 264 : prefs_(profile->GetPrefs()),
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 420
411 // Do not delete the cookie store in the case of the media context, as it is 421 // Do not delete the cookie store in the case of the media context, as it is
412 // owned by the original context. 422 // owned by the original context.
413 if (!is_media_) 423 if (!is_media_)
414 delete cookie_store_; 424 delete cookie_store_;
415 425
416 // Do not delete the proxy service in the case of OTR or media contexts, as 426 // Do not delete the proxy service in the case of OTR or media contexts, as
417 // it is owned by the original URLRequestContext. 427 // it is owned by the original URLRequestContext.
418 if (!is_off_the_record_ && !is_media_) 428 if (!is_off_the_record_ && !is_media_)
419 delete proxy_service_; 429 delete proxy_service_;
430
431 // Do not delete host_resolver_; it will be freed by FreeGlobalHostResolver()
432 // during the teardown of DNS prefetching.
420 } 433 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/net/dns_global.cc » ('j') | net/base/address_list.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698