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

Side by Side Diff: chrome/browser/net/chrome_url_request_context.cc

Issue 258008: Move initialization of ChromeURLRequestContexts to the IO thread. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync again, just in case Created 11 years, 2 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 "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/privacy_blacklist/blacklist.h" 10 #include "chrome/browser/privacy_blacklist/blacklist.h"
11 #include "chrome/browser/chrome_thread.h" 11 #include "chrome/browser/chrome_thread.h"
12 #include "chrome/browser/extensions/extensions_service.h" 12 #include "chrome/browser/extensions/extensions_service.h"
13 #include "chrome/browser/extensions/user_script_master.h" 13 #include "chrome/browser/extensions/user_script_master.h"
14 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" 14 #include "chrome/browser/net/sqlite_persistent_cookie_store.h"
15 #include "chrome/browser/net/dns_global.h" 15 #include "chrome/browser/net/dns_global.h"
16 #include "chrome/browser/profile.h" 16 #include "chrome/browser/profile.h"
17 #include "chrome/common/chrome_constants.h" 17 #include "chrome/common/chrome_constants.h"
18 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/extensions/extension.h" 19 #include "chrome/common/extensions/extension.h"
20 #include "chrome/common/notification_service.h" 20 #include "chrome/common/notification_service.h"
21 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
22 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
23 #include "net/ftp/ftp_network_layer.h" 23 #include "net/ftp/ftp_network_layer.h"
24 #include "net/http/http_cache.h" 24 #include "net/http/http_cache.h"
25 #include "net/http/http_network_layer.h" 25 #include "net/http/http_network_layer.h"
26 #include "net/http/http_util.h" 26 #include "net/http/http_util.h"
27 #include "net/proxy/proxy_config_service_fixed.h"
27 #include "net/proxy/proxy_service.h" 28 #include "net/proxy/proxy_service.h"
28 #include "net/url_request/url_request.h" 29 #include "net/url_request/url_request.h"
29 #include "webkit/glue/webkit_glue.h" 30 #include "webkit/glue/webkit_glue.h"
30 31
32 #if defined(OS_LINUX)
33 #include "net/ocsp/nss_ocsp.h"
34 #endif
35
36 // TODO(eroman): Fix the definition ordering to match-up with the declaration
37 // ordering (this was done to help keep the diffs simple during
38 // refactor).
39
40 // TODO(eroman): The ChromeURLRequestContext's Blacklist* is shared with the
41 // Profile... This is a problem since the Profile dies before
42 // the IO thread, so we may end up accessing a deleted variable.
43
44 static void CheckCurrentlyOnIOThread() {
45 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
46 }
47
48 static void CheckCurrentlyOnMainThread() {
49 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
50 }
51
31 net::ProxyConfig* CreateProxyConfig(const CommandLine& command_line) { 52 net::ProxyConfig* CreateProxyConfig(const CommandLine& command_line) {
32 // Scan for all "enable" type proxy switches. 53 // Scan for all "enable" type proxy switches.
33 static const char* proxy_switches[] = { 54 static const char* proxy_switches[] = {
34 switches::kProxyServer, 55 switches::kProxyServer,
35 switches::kProxyPacUrl, 56 switches::kProxyPacUrl,
36 switches::kProxyAutoDetect, 57 switches::kProxyAutoDetect,
37 switches::kProxyBypassList 58 switches::kProxyBypassList
38 }; 59 };
39 60
40 bool found_enable_proxy_switch = false; 61 bool found_enable_proxy_switch = false;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 100
80 if (command_line.HasSwitch(switches::kProxyBypassList)) { 101 if (command_line.HasSwitch(switches::kProxyBypassList)) {
81 proxy_config->ParseNoProxyList( 102 proxy_config->ParseNoProxyList(
82 WideToASCII(command_line.GetSwitchValue( 103 WideToASCII(command_line.GetSwitchValue(
83 switches::kProxyBypassList))); 104 switches::kProxyBypassList)));
84 } 105 }
85 106
86 return proxy_config; 107 return proxy_config;
87 } 108 }
88 109
110 static net::ProxyConfigService* CreateProxyConfigService(
111 const CommandLine& command_line) {
112 // The linux gconf-based proxy settings getter relies on being initialized
113 // from the UI thread.
114 CheckCurrentlyOnMainThread();
115
116 scoped_ptr<net::ProxyConfig> proxy_config_from_cmd_line(
117 CreateProxyConfig(command_line));
118
119 if (!proxy_config_from_cmd_line.get()) {
120 // Use system settings.
121 return net::ProxyService::CreateSystemProxyConfigService(
122 g_browser_process->io_thread()->message_loop(),
123 g_browser_process->file_thread()->message_loop());
124 }
125
126 // Otherwise use the fixed settings from the command line.
127 return new net::ProxyConfigServiceFixed(*proxy_config_from_cmd_line.get());
128 }
129
89 // Create a proxy service according to the options on command line. 130 // Create a proxy service according to the options on command line.
90 static net::ProxyService* CreateProxyService(URLRequestContext* context, 131 static net::ProxyService* CreateProxyService(
91 const CommandLine& command_line) { 132 URLRequestContext* context,
92 scoped_ptr<net::ProxyConfig> proxy_config(CreateProxyConfig(command_line)); 133 net::ProxyConfigService* proxy_config_service,
134 const CommandLine& command_line,
135 MessageLoop* io_loop) {
136 CheckCurrentlyOnIOThread();
93 137
94 bool use_v8 = !command_line.HasSwitch(switches::kWinHttpProxyResolver); 138 bool use_v8 = !command_line.HasSwitch(switches::kWinHttpProxyResolver);
95 if (use_v8 && command_line.HasSwitch(switches::kSingleProcess)) { 139 if (use_v8 && command_line.HasSwitch(switches::kSingleProcess)) {
96 // See the note about V8 multithreading in net/proxy/proxy_resolver_v8.h 140 // See the note about V8 multithreading in net/proxy/proxy_resolver_v8.h
97 // to understand why we have this limitation. 141 // to understand why we have this limitation.
98 LOG(ERROR) << "Cannot use V8 Proxy resolver in single process mode."; 142 LOG(ERROR) << "Cannot use V8 Proxy resolver in single process mode.";
99 use_v8 = false; // Fallback to non-v8 implementation. 143 use_v8 = false; // Fallback to non-v8 implementation.
100 } 144 }
101 145
102 return net::ProxyService::Create( 146 return net::ProxyService::Create(
103 proxy_config.get(), 147 proxy_config_service,
104 use_v8, 148 use_v8,
105 context, 149 context,
106 g_browser_process->io_thread()->message_loop(), 150 io_loop);
107 g_browser_process->file_thread()->message_loop());
108 } 151 }
109 152
153 // Lazily create a ChromeURLRequestContext using our factory.
154 URLRequestContext* ChromeURLRequestContextGetter::GetURLRequestContext() {
155 CheckCurrentlyOnIOThread();
156
157 if (!url_request_context_) {
158 DCHECK(factory_.get());
159 url_request_context_ = factory_->Create();
160 factory_.reset();
161 }
162
163 return url_request_context_;
164 }
165
166 // Factory that creates the main ChromeURLRequestContext.
167 class FactoryForOriginal : public ChromeURLRequestContextFactory {
168 public:
169 FactoryForOriginal(Profile* profile,
170 const FilePath& cookie_store_path,
171 const FilePath& disk_cache_path,
172 int cache_size)
173 : ChromeURLRequestContextFactory(profile),
174 cookie_store_path_(cookie_store_path),
175 disk_cache_path_(disk_cache_path),
176 cache_size_(cache_size),
177 // We need to initialize the ProxyConfigService from the UI thread
178 // because on linux it relies on initializing things through gconf,
179 // and needs to be on the main thread.
180 proxy_config_service_(
181 CreateProxyConfigService(
182 *CommandLine::ForCurrentProcess())) {
183 }
184
185 virtual ChromeURLRequestContext* Create();
186
187 private:
188 FilePath cookie_store_path_;
189 FilePath disk_cache_path_;
190 int cache_size_;
191
192 scoped_ptr<net::ProxyConfigService> proxy_config_service_;
193 };
194
110 // static 195 // static
111 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal( 196 ChromeURLRequestContextGetter* ChromeURLRequestContextGetter::CreateOriginal(
112 Profile* profile, const FilePath& cookie_store_path, 197 Profile* profile, const FilePath& cookie_store_path,
113 const FilePath& disk_cache_path, int cache_size, 198 const FilePath& disk_cache_path, int cache_size) {
114 ChromeAppCacheService* appcache_service) {
115 DCHECK(!profile->IsOffTheRecord()); 199 DCHECK(!profile->IsOffTheRecord());
116 ChromeURLRequestContext* context = new ChromeURLRequestContext( 200 return new ChromeURLRequestContextGetter(
117 profile, appcache_service); 201 profile,
202 new FactoryForOriginal(profile,
203 cookie_store_path,
204 disk_cache_path,
205 cache_size));
206 }
118 207
119 // The appcache service uses the profile's original context for UpdateJobs. 208 ChromeURLRequestContext* FactoryForOriginal::Create() {
120 DCHECK(!appcache_service->request_context()); 209 ChromeURLRequestContext* context = new ChromeURLRequestContext;
121 appcache_service->set_request_context(context); 210 ApplyProfileParametersToContext(context);
122 211
123 // Global host resolver for the context. 212 // Global host resolver for the context.
124 context->host_resolver_ = chrome_browser_net::GetGlobalHostResolver(); 213 context->set_host_resolver(chrome_browser_net::GetGlobalHostResolver());
125 214
126 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 215 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
127 216
128 context->proxy_service_ = CreateProxyService(context, command_line); 217 context->set_proxy_service(
218 CreateProxyService(context,
219 proxy_config_service_.release(),
220 command_line,
221 MessageLoop::current() /*io_loop*/));
129 222
130 net::HttpCache* cache = 223 net::HttpCache* cache =
131 new net::HttpCache(context->host_resolver_, 224 new net::HttpCache(context->host_resolver(),
132 context->proxy_service_, 225 context->proxy_service(),
133 context->ssl_config_service_, 226 context->ssl_config_service(),
134 disk_cache_path, cache_size); 227 disk_cache_path_, cache_size_);
135 228
136 if (command_line.HasSwitch(switches::kDisableByteRangeSupport)) 229 if (command_line.HasSwitch(switches::kDisableByteRangeSupport))
137 cache->set_enable_range_support(false); 230 cache->set_enable_range_support(false);
138 231
139 bool record_mode = chrome::kRecordModeEnabled && 232 bool record_mode = chrome::kRecordModeEnabled &&
140 command_line.HasSwitch(switches::kRecordMode); 233 command_line.HasSwitch(switches::kRecordMode);
141 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); 234 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode);
142 235
143 if (record_mode || playback_mode) { 236 if (record_mode || playback_mode) {
144 // Don't use existing cookies and use an in-memory store. 237 // Don't use existing cookies and use an in-memory store.
145 context->cookie_store_ = new net::CookieMonster(); 238 context->set_cookie_store(new net::CookieMonster());
146 cache->set_mode( 239 cache->set_mode(
147 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); 240 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK);
148 } 241 }
149 context->http_transaction_factory_ = cache; 242 context->set_http_transaction_factory(cache);
150 243
151 // The kWininetFtp switch is Windows specific because we have two FTP 244 // The kWininetFtp switch is Windows specific because we have two FTP
152 // implementations on Windows. 245 // implementations on Windows.
153 #if defined(OS_WIN) 246 #if defined(OS_WIN)
154 if (!command_line.HasSwitch(switches::kWininetFtp)) 247 if (!command_line.HasSwitch(switches::kWininetFtp))
155 context->ftp_transaction_factory_ = 248 context->set_ftp_transaction_factory(
156 new net::FtpNetworkLayer(context->host_resolver_); 249 new net::FtpNetworkLayer(context->host_resolver()));
157 #else 250 #else
158 context->ftp_transaction_factory_ = 251 context->set_ftp_transaction_factory(
159 new net::FtpNetworkLayer(context->host_resolver_); 252 new net::FtpNetworkLayer(context->host_resolver()));
160 #endif 253 #endif
161 254
162 // setup cookie store 255 // setup cookie store
163 if (!context->cookie_store_) { 256 if (!context->cookie_store()) {
164 DCHECK(!cookie_store_path.empty()); 257 DCHECK(!cookie_store_path_.empty());
165 258
166 scoped_refptr<SQLitePersistentCookieStore> cookie_db = 259 scoped_refptr<SQLitePersistentCookieStore> cookie_db =
167 new SQLitePersistentCookieStore( 260 new SQLitePersistentCookieStore(
168 cookie_store_path, 261 cookie_store_path_,
169 g_browser_process->db_thread()->message_loop()); 262 db_loop_);
170 context->cookie_store_ = new net::CookieMonster(cookie_db.get()); 263 context->set_cookie_store(new net::CookieMonster(cookie_db.get()));
171 } 264 }
172 265
266 // Create a new AppCacheService (issues fetches through the
267 // main URLRequestContext that we just created).
268 context->set_appcache_service(
269 new ChromeAppCacheService(profile_dir_path_, false));
270 context->appcache_service()->set_request_context(context);
271
272 #if defined(OS_LINUX)
273 // TODO(ukai): find a better way to set the URLRequestContext for OCSP.
274 net::SetURLRequestContextForOCSP(context);
275 #endif
276
173 return context; 277 return context;
174 } 278 }
175 279
176 // static 280 // static
177 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForMedia( 281 ChromeURLRequestContextGetter*
178 Profile* profile, const FilePath& disk_cache_path, int cache_size, 282 ChromeURLRequestContextGetter::CreateOriginalForMedia(
179 ChromeAppCacheService* appcache_service) { 283 Profile* profile, const FilePath& disk_cache_path, int cache_size) {
180 DCHECK(!profile->IsOffTheRecord()); 284 DCHECK(!profile->IsOffTheRecord());
181 return CreateRequestContextForMedia(profile, disk_cache_path, cache_size, 285 return CreateRequestContextForMedia(profile, disk_cache_path, cache_size,
182 false, appcache_service); 286 false);
183 } 287 }
184 288
289 // Factory that creates the ChromeURLRequestContext for extensions.
290 class FactoryForExtensions : public ChromeURLRequestContextFactory {
291 public:
292 FactoryForExtensions(Profile* profile, const FilePath& cookie_store_path)
293 : ChromeURLRequestContextFactory(profile),
294 cookie_store_path_(cookie_store_path) {
295 }
296
297 virtual ChromeURLRequestContext* Create();
298
299 private:
300 FilePath cookie_store_path_;
301 };
302
185 // static 303 // static
186 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForExtensions( 304 ChromeURLRequestContextGetter*
305 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
187 Profile* profile, const FilePath& cookie_store_path) { 306 Profile* profile, const FilePath& cookie_store_path) {
188 DCHECK(!profile->IsOffTheRecord()); 307 DCHECK(!profile->IsOffTheRecord());
189 ChromeURLRequestContext* context = new ChromeURLRequestContext( 308 return new ChromeURLRequestContextGetter(
190 profile, NULL); 309 profile,
310 new FactoryForExtensions(profile, cookie_store_path));
311 }
312
313 ChromeURLRequestContext* FactoryForExtensions::Create() {
314 ChromeURLRequestContext* context = new ChromeURLRequestContext;
315 ApplyProfileParametersToContext(context);
191 316
192 // All we care about for extensions is the cookie store. 317 // All we care about for extensions is the cookie store.
193 DCHECK(!cookie_store_path.empty()); 318 DCHECK(!cookie_store_path_.empty());
194 319
195 scoped_refptr<SQLitePersistentCookieStore> cookie_db = 320 scoped_refptr<SQLitePersistentCookieStore> cookie_db =
196 new SQLitePersistentCookieStore( 321 new SQLitePersistentCookieStore(cookie_store_path_, db_loop_);
197 cookie_store_path,
198 g_browser_process->db_thread()->message_loop());
199 net::CookieMonster* cookie_monster = new net::CookieMonster(cookie_db.get()); 322 net::CookieMonster* cookie_monster = new net::CookieMonster(cookie_db.get());
200 323
201 // Enable cookies for extension URLs only. 324 // Enable cookies for extension URLs only.
202 const char* schemes[] = {chrome::kExtensionScheme}; 325 const char* schemes[] = {chrome::kExtensionScheme};
203 cookie_monster->SetCookieableSchemes(schemes, 1); 326 cookie_monster->SetCookieableSchemes(schemes, 1);
204 context->cookie_store_ = cookie_monster; 327 context->set_cookie_store(cookie_monster);
205 328
206 return context; 329 return context;
207 } 330 }
208 331
332 // Factory that creates the ChromeURLRequestContext for incognito profile.
333 class FactoryForOffTheRecord : public ChromeURLRequestContextFactory {
334 public:
335 FactoryForOffTheRecord(Profile* profile)
336 : ChromeURLRequestContextFactory(profile),
337 original_context_getter_(
338 static_cast<ChromeURLRequestContextGetter*>(
339 profile->GetOriginalProfile()->GetRequestContext())) {
340 }
341
342 virtual ChromeURLRequestContext* Create();
343
344 private:
345 scoped_refptr<ChromeURLRequestContextGetter> original_context_getter_;
346 };
347
209 // static 348 // static
210 ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecord( 349 ChromeURLRequestContextGetter* ChromeURLRequestContextGetter::CreateOffTheRecord (
211 Profile* profile, ChromeAppCacheService* appcache_service) { 350 Profile* profile) {
212 DCHECK(profile->IsOffTheRecord()); 351 DCHECK(profile->IsOffTheRecord());
213 ChromeURLRequestContext* context = new ChromeURLRequestContext( 352 return new ChromeURLRequestContextGetter(
214 profile, appcache_service); 353 profile, new FactoryForOffTheRecord(profile));
354 }
215 355
216 // The appcache service uses the profile's original context for UpdateJobs. 356 ChromeURLRequestContext* FactoryForOffTheRecord::Create() {
217 DCHECK(!appcache_service->request_context()); 357 ChromeURLRequestContext* context = new ChromeURLRequestContext;
218 appcache_service->set_request_context(context); 358 ApplyProfileParametersToContext(context);
359
360 ChromeURLRequestContext* original_context =
361 original_context_getter_->GetIOContext();
219 362
220 // Share the same proxy service and host resolver as the original profile. 363 // Share the same proxy service and host resolver as the original profile.
221 // TODO(eroman): although ProxyService is reference counted, this sharing 364 // TODO(eroman): although ProxyService is reference counted, this sharing
222 // still has a subtle dependency on the lifespan of the original profile -- 365 // still has a subtle dependency on the lifespan of the original profile --
223 // ProxyService holds a (non referencing) pointer to the URLRequestContext 366 // ProxyService holds a (non referencing) pointer to the URLRequestContext
224 // it uses to download PAC scripts, which in this case is the original 367 // it uses to download PAC scripts, which in this case is the original
225 // profile... 368 // profile...
226 context->host_resolver_ = 369 context->set_host_resolver(original_context->host_resolver());
227 profile->GetOriginalProfile()->GetRequestContext()->host_resolver(); 370 context->set_proxy_service(original_context->proxy_service());
228 context->proxy_service_ =
229 profile->GetOriginalProfile()->GetRequestContext()->proxy_service();
230 371
231 net::HttpCache* cache = 372 net::HttpCache* cache =
232 new net::HttpCache(context->host_resolver_, context->proxy_service_, 373 new net::HttpCache(context->host_resolver(), context->proxy_service(),
233 context->ssl_config_service_, 0); 374 context->ssl_config_service(), 0);
234 context->cookie_store_ = new net::CookieMonster; 375 context->set_cookie_store(new net::CookieMonster);
235 context->http_transaction_factory_ = cache; 376 context->set_http_transaction_factory(cache);
236 377
237 if (CommandLine::ForCurrentProcess()->HasSwitch( 378 if (CommandLine::ForCurrentProcess()->HasSwitch(
238 switches::kDisableByteRangeSupport)) 379 switches::kDisableByteRangeSupport))
239 cache->set_enable_range_support(false); 380 cache->set_enable_range_support(false);
240 381
241 // The kWininetFtp switch is Windows specific because we have two FTP 382 // The kWininetFtp switch is Windows specific because we have two FTP
242 // implementations on Windows. 383 // implementations on Windows.
243 #if defined(OS_WIN) 384 #if defined(OS_WIN)
244 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kWininetFtp)) 385 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kWininetFtp))
245 context->ftp_transaction_factory_ = 386 context->set_ftp_transaction_factory(
246 new net::FtpNetworkLayer(context->host_resolver_); 387 new net::FtpNetworkLayer(context->host_resolver()));
247 #else 388 #else
248 context->ftp_transaction_factory_ = 389 context->set_ftp_transaction_factory(
249 new net::FtpNetworkLayer(context->host_resolver_); 390 new net::FtpNetworkLayer(context->host_resolver()));
250 #endif 391 #endif
251 392
393 // Create a separate AppCacheService for OTR mode.
394 context->set_appcache_service(
395 new ChromeAppCacheService(profile_dir_path_, true));
396 context->appcache_service()->set_request_context(context);
397
252 return context; 398 return context;
253 } 399 }
254 400
401 // Factory that creates the ChromeURLRequestContext for extensions in incognito
402 // mode.
403 class FactoryForOffTheRecordExtensions
404 : public ChromeURLRequestContextFactory {
405 public:
406 FactoryForOffTheRecordExtensions(Profile* profile)
407 : ChromeURLRequestContextFactory(profile) {}
408
409 virtual ChromeURLRequestContext* Create();
410 };
411
255 // static 412 // static
256 ChromeURLRequestContext* 413 ChromeURLRequestContextGetter*
257 ChromeURLRequestContext::CreateOffTheRecordForExtensions(Profile* profile) { 414 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions(Profile* profile) {
258 DCHECK(profile->IsOffTheRecord()); 415 DCHECK(profile->IsOffTheRecord());
259 ChromeURLRequestContext* context = 416 return new ChromeURLRequestContextGetter(
260 new ChromeURLRequestContext(profile, NULL); 417 profile,
418 new FactoryForOffTheRecordExtensions(profile));
419 }
420
421 ChromeURLRequestContext* FactoryForOffTheRecordExtensions::Create() {
422 ChromeURLRequestContext* context = new ChromeURLRequestContext;
423 ApplyProfileParametersToContext(context);
424
261 net::CookieMonster* cookie_monster = new net::CookieMonster; 425 net::CookieMonster* cookie_monster = new net::CookieMonster;
262 426
263 // Enable cookies for extension URLs only. 427 // Enable cookies for extension URLs only.
264 const char* schemes[] = {chrome::kExtensionScheme}; 428 const char* schemes[] = {chrome::kExtensionScheme};
265 cookie_monster->SetCookieableSchemes(schemes, 1); 429 cookie_monster->SetCookieableSchemes(schemes, 1);
266 context->cookie_store_ = cookie_monster; 430 context->set_cookie_store(cookie_monster);
267 431
268 return context; 432 return context;
269 } 433 }
270 434
435 // Factory that creates the ChromeURLRequestContext for media.
436 class FactoryForMedia : public ChromeURLRequestContextFactory {
437 public:
438 FactoryForMedia(Profile* profile,
439 const FilePath& disk_cache_path,
440 int cache_size,
441 bool off_the_record)
442 : ChromeURLRequestContextFactory(profile),
443 main_context_getter_(
444 static_cast<ChromeURLRequestContextGetter*>(
445 profile->GetRequestContext())) {
446 is_media_ = true;
447 is_off_the_record_ = off_the_record;
448 }
449
450 virtual ChromeURLRequestContext* Create();
451
452 private:
453 scoped_refptr<ChromeURLRequestContextGetter> main_context_getter_;
454
455 FilePath disk_cache_path_;
456 int cache_size_;
457 };
458
271 // static 459 // static
272 ChromeURLRequestContext* ChromeURLRequestContext::CreateRequestContextForMedia( 460 ChromeURLRequestContextGetter*
461 ChromeURLRequestContextGetter::CreateRequestContextForMedia(
273 Profile* profile, const FilePath& disk_cache_path, int cache_size, 462 Profile* profile, const FilePath& disk_cache_path, int cache_size,
274 bool off_the_record, ChromeAppCacheService* appcache_service) { 463 bool off_the_record) {
275 URLRequestContext* original_context = 464 return new ChromeURLRequestContextGetter(
276 profile->GetOriginalProfile()->GetRequestContext(); 465 profile,
277 ChromeURLRequestContext* context = 466 new FactoryForMedia(profile,
278 new ChromeURLRequestContext(profile, appcache_service); 467 disk_cache_path,
279 context->is_media_ = true; 468 cache_size,
469 off_the_record));
470 }
471
472 ChromeURLRequestContext* FactoryForMedia::Create() {
473 ChromeURLRequestContext* context = new ChromeURLRequestContext;
474 ApplyProfileParametersToContext(context);
475
476 ChromeURLRequestContext* main_context =
477 main_context_getter_->GetIOContext();
280 478
281 // Share the same proxy service of the common profile. 479 // Share the same proxy service of the common profile.
282 context->proxy_service_ = original_context->proxy_service(); 480 context->set_proxy_service(main_context->proxy_service());
283 // Also share the cookie store of the common profile. 481 // Also share the cookie store of the common profile.
284 context->cookie_store_ = original_context->cookie_store(); 482 context->set_cookie_store(main_context->cookie_store());
285 483
286 // Create a media cache with default size. 484 // Create a media cache with default size.
287 // TODO(hclam): make the maximum size of media cache configurable. 485 // TODO(hclam): make the maximum size of media cache configurable.
288 net::HttpCache* original_cache = 486 net::HttpCache* main_cache =
289 original_context->http_transaction_factory()->GetCache(); 487 main_context->http_transaction_factory()->GetCache();
290 net::HttpCache* cache; 488 net::HttpCache* cache;
291 if (original_cache) { 489 if (main_cache) {
292 // Try to reuse HttpNetworkSession in the original context, assuming that 490 // Try to reuse HttpNetworkSession in the main context, assuming that
293 // HttpTransactionFactory (network_layer()) of HttpCache is implemented 491 // HttpTransactionFactory (network_layer()) of HttpCache is implemented
294 // by HttpNetworkLayer so we can reuse HttpNetworkSession within it. This 492 // by HttpNetworkLayer so we can reuse HttpNetworkSession within it. This
295 // assumption will be invalid if the original HttpCache is constructed with 493 // assumption will be invalid if the original HttpCache is constructed with
296 // HttpCache(HttpTransactionFactory*, disk_cache::Backend*) constructor. 494 // HttpCache(HttpTransactionFactory*, disk_cache::Backend*) constructor.
297 net::HttpNetworkLayer* original_network_layer = 495 net::HttpNetworkLayer* main_network_layer =
298 static_cast<net::HttpNetworkLayer*>(original_cache->network_layer()); 496 static_cast<net::HttpNetworkLayer*>(main_cache->network_layer());
299 cache = new net::HttpCache(original_network_layer->GetSession(), 497 cache = new net::HttpCache(main_network_layer->GetSession(),
300 disk_cache_path, cache_size); 498 disk_cache_path_, cache_size_);
499 // TODO(eroman): Since this is poaching the session from the main
500 // context, it should hold a reference to that context preventing the
501 // session from getting deleted.
301 } else { 502 } else {
302 // If original HttpCache doesn't exist, simply construct one with a whole 503 // If original HttpCache doesn't exist, simply construct one with a whole
303 // new set of network stack. 504 // new set of network stack.
304 cache = new net::HttpCache(original_context->host_resolver(), 505 cache = new net::HttpCache(main_context->host_resolver(),
305 original_context->proxy_service(), 506 main_context->proxy_service(),
306 original_context->ssl_config_service(), 507 main_context->ssl_config_service(),
307 disk_cache_path, cache_size); 508 disk_cache_path_, cache_size_);
308 } 509 }
309 510
310 if (CommandLine::ForCurrentProcess()->HasSwitch( 511 if (CommandLine::ForCurrentProcess()->HasSwitch(
311 switches::kDisableByteRangeSupport)) 512 switches::kDisableByteRangeSupport))
312 cache->set_enable_range_support(false); 513 cache->set_enable_range_support(false);
313 514
314 cache->set_type(net::MEDIA_CACHE); 515 cache->set_type(net::MEDIA_CACHE);
315 context->http_transaction_factory_ = cache; 516 context->set_http_transaction_factory(cache);
517
518 // Use the same appcache service as the profile's main context.
519 context->set_appcache_service(main_context->appcache_service());
520
316 return context; 521 return context;
317 } 522 }
318 523
319 ChromeURLRequestContext::ChromeURLRequestContext( 524 ChromeURLRequestContextGetter::ChromeURLRequestContextGetter(
320 Profile* profile, ChromeAppCacheService* appcache_service) 525 Profile* profile,
321 : appcache_service_(appcache_service), 526 ChromeURLRequestContextFactory* factory)
322 prefs_(profile->GetPrefs()), 527 : prefs_(NULL),
323 is_media_(false), 528 factory_(factory),
529 url_request_context_(NULL) {
530 DCHECK(factory);
531
532 // If a base profile was specified, listen for changes to the preferences.
533 if (profile)
534 RegisterPrefsObserver(profile);
535 }
536
537 // Extract values from |profile| and copy them into
538 // ChromeURLRequestContextFactory. We will use them later when constructing the
539 // ChromeURLRequestContext on the IO thread (see
540 // ApplyProfileParametersToContext() which reverses this).
541 ChromeURLRequestContextFactory::ChromeURLRequestContextFactory(Profile* profile)
542 : is_media_(false),
324 is_off_the_record_(profile->IsOffTheRecord()) { 543 is_off_the_record_(profile->IsOffTheRecord()) {
544 CheckCurrentlyOnMainThread();
545 PrefService* prefs = profile->GetPrefs();
546
325 // Set up Accept-Language and Accept-Charset header values 547 // Set up Accept-Language and Accept-Charset header values
326 accept_language_ = net::HttpUtil::GenerateAcceptLanguageHeader( 548 accept_language_ = net::HttpUtil::GenerateAcceptLanguageHeader(
327 WideToASCII(prefs_->GetString(prefs::kAcceptLanguages))); 549 WideToASCII(prefs->GetString(prefs::kAcceptLanguages)));
328 std::string default_charset = 550 std::string default_charset =
329 WideToASCII(prefs_->GetString(prefs::kDefaultCharset)); 551 WideToASCII(prefs->GetString(prefs::kDefaultCharset));
330 accept_charset_ = 552 accept_charset_ =
331 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset); 553 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset);
332 554
333 // At this point, we don't know the charset of the referring page 555 // At this point, we don't know the charset of the referring page
334 // where a url request originates from. This is used to get a suggested 556 // where a url request originates from. This is used to get a suggested
335 // filename from Content-Disposition header made of raw 8bit characters. 557 // filename from Content-Disposition header made of raw 8bit characters.
336 // Down the road, it can be overriden if it becomes known (for instance, 558 // Down the road, it can be overriden if it becomes known (for instance,
337 // when download request is made through the context menu in a web page). 559 // when download request is made through the context menu in a web page).
338 // At the moment, it'll remain 'undeterministic' when a user 560 // At the moment, it'll remain 'undeterministic' when a user
339 // types a URL in the omnibar or click on a download link in a page. 561 // types a URL in the omnibar or click on a download link in a page.
340 // For the latter, we need a change on the webkit-side. 562 // For the latter, we need a change on the webkit-side.
341 // We initialize it to the default charset here and a user will 563 // We initialize it to the default charset here and a user will
342 // have an *arguably* better default charset for interpreting a raw 8bit 564 // have an *arguably* better default charset for interpreting a raw 8bit
343 // C-D header field. It means the native OS codepage fallback in 565 // C-D header field. It means the native OS codepage fallback in
344 // net_util::GetSuggestedFilename is unlikely to be taken. 566 // net_util::GetSuggestedFilename is unlikely to be taken.
345 referrer_charset_ = default_charset; 567 referrer_charset_ = default_charset;
346 568
347 cookie_policy_.set_type(net::CookiePolicy::FromInt( 569 cookie_policy_type_ = net::CookiePolicy::FromInt(
348 prefs_->GetInteger(prefs::kCookieBehavior))); 570 prefs->GetInteger(prefs::kCookieBehavior));
349 571
572 // TODO(eroman): this doesn't look safe; sharing between IO and UI threads!
350 blacklist_ = profile->GetBlacklist(); 573 blacklist_ = profile->GetBlacklist();
351 574
575 // TODO(eroman): this doesn't look safe; sharing between IO and UI threads!
352 strict_transport_security_state_ = profile->GetStrictTransportSecurityState(); 576 strict_transport_security_state_ = profile->GetStrictTransportSecurityState();
353 577
354 if (profile->GetExtensionsService()) { 578 if (profile->GetExtensionsService()) {
355 const ExtensionList* extensions = 579 const ExtensionList* extensions =
356 profile->GetExtensionsService()->extensions(); 580 profile->GetExtensionsService()->extensions();
357 for (ExtensionList::const_iterator iter = extensions->begin(); 581 for (ExtensionList::const_iterator iter = extensions->begin();
358 iter != extensions->end(); ++iter) { 582 iter != extensions->end(); ++iter) {
359 extension_paths_[(*iter)->id()] = (*iter)->path(); 583 extension_paths_[(*iter)->id()] = (*iter)->path();
360 } 584 }
361 } 585 }
362 586
363 if (profile->GetUserScriptMaster()) 587 if (profile->GetUserScriptMaster())
364 user_script_dir_path_ = profile->GetUserScriptMaster()->user_script_dir(); 588 user_script_dir_path_ = profile->GetUserScriptMaster()->user_script_dir();
365 589
590 // TODO(eroman): this doesn't look safe; sharing between IO and UI threads!
591 ssl_config_service_ = profile->GetSSLConfigService();
592
593 profile_dir_path_ = profile->GetPath();
594
595 // Get references to the database and file threads.
596 db_loop_ = g_browser_process->db_thread()->message_loop();
597 }
598
599 ChromeURLRequestContextFactory::~ChromeURLRequestContextFactory() {
600 CheckCurrentlyOnIOThread();
601 }
602
603 void ChromeURLRequestContextFactory::ApplyProfileParametersToContext(
604 ChromeURLRequestContext* context) {
605 // Apply all the parameters. NOTE: keep this in sync with
606 // ChromeURLRequestContextFactory(Profile*).
607 context->set_is_media(is_media_);
608 context->set_is_off_the_record(is_off_the_record_);
609 context->set_accept_language(accept_language_);
610 context->set_accept_charset(accept_charset_);
611 context->set_referrer_charset(referrer_charset_);
612 context->set_cookie_policy_type(cookie_policy_type_);
613 context->set_extension_paths(extension_paths_);
614 context->set_user_script_dir_path(user_script_dir_path_);
615 context->set_blacklist(blacklist_);
616 context->set_strict_transport_security_state(
617 strict_transport_security_state_);
618 context->set_ssl_config_service(ssl_config_service_);
619 }
620
621 void ChromeURLRequestContextGetter::RegisterPrefsObserver(Profile* profile) {
622 CheckCurrentlyOnMainThread();
623
624 prefs_ = profile->GetPrefs();
625
366 prefs_->AddPrefObserver(prefs::kAcceptLanguages, this); 626 prefs_->AddPrefObserver(prefs::kAcceptLanguages, this);
367 prefs_->AddPrefObserver(prefs::kCookieBehavior, this); 627 prefs_->AddPrefObserver(prefs::kCookieBehavior, this);
368 prefs_->AddPrefObserver(prefs::kDefaultCharset, this); 628 prefs_->AddPrefObserver(prefs::kDefaultCharset, this);
369
370 ssl_config_service_ = profile->GetSSLConfigService();
371 } 629 }
372 630
373 ChromeURLRequestContext::ChromeURLRequestContext( 631 ChromeURLRequestContext::ChromeURLRequestContext(
374 ChromeURLRequestContext* other) { 632 ChromeURLRequestContext* other) {
633 CheckCurrentlyOnIOThread();
634
375 // Set URLRequestContext members 635 // Set URLRequestContext members
376 host_resolver_ = other->host_resolver_; 636 host_resolver_ = other->host_resolver_;
377 proxy_service_ = other->proxy_service_; 637 proxy_service_ = other->proxy_service_;
378 ssl_config_service_ = other->ssl_config_service_; 638 ssl_config_service_ = other->ssl_config_service_;
379 http_transaction_factory_ = other->http_transaction_factory_; 639 http_transaction_factory_ = other->http_transaction_factory_;
380 ftp_transaction_factory_ = other->ftp_transaction_factory_; 640 ftp_transaction_factory_ = other->ftp_transaction_factory_;
381 cookie_store_ = other->cookie_store_; 641 cookie_store_ = other->cookie_store_;
382 cookie_policy_.set_type(other->cookie_policy_.type()); 642 cookie_policy_.set_type(other->cookie_policy_.type());
383 strict_transport_security_state_ = other->strict_transport_security_state_; 643 strict_transport_security_state_ = other->strict_transport_security_state_;
384 accept_language_ = other->accept_language_; 644 accept_language_ = other->accept_language_;
385 accept_charset_ = other->accept_charset_; 645 accept_charset_ = other->accept_charset_;
386 referrer_charset_ = other->referrer_charset_; 646 referrer_charset_ = other->referrer_charset_;
387 647
388 // Set ChromeURLRequestContext members 648 // Set ChromeURLRequestContext members
389 appcache_service_ = other->appcache_service_; 649 appcache_service_ = other->appcache_service_;
390 extension_paths_ = other->extension_paths_; 650 extension_paths_ = other->extension_paths_;
391 user_script_dir_path_ = other->user_script_dir_path_; 651 user_script_dir_path_ = other->user_script_dir_path_;
392 prefs_ = other->prefs_;
393 blacklist_ = other->blacklist_; 652 blacklist_ = other->blacklist_;
394 is_media_ = other->is_media_; 653 is_media_ = other->is_media_;
395 is_off_the_record_ = other->is_off_the_record_; 654 is_off_the_record_ = other->is_off_the_record_;
396 } 655 }
397 656
398 // NotificationObserver implementation. 657 // NotificationObserver implementation.
399 void ChromeURLRequestContext::Observe(NotificationType type, 658 void ChromeURLRequestContextGetter::Observe(NotificationType type,
400 const NotificationSource& source, 659 const NotificationSource& source,
401 const NotificationDetails& details) { 660 const NotificationDetails& details) {
661 CheckCurrentlyOnMainThread();
662
402 if (NotificationType::PREF_CHANGED == type) { 663 if (NotificationType::PREF_CHANGED == type) {
403 std::wstring* pref_name_in = Details<std::wstring>(details).ptr(); 664 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
404 PrefService* prefs = Source<PrefService>(source).ptr(); 665 PrefService* prefs = Source<PrefService>(source).ptr();
405 DCHECK(pref_name_in && prefs); 666 DCHECK(pref_name_in && prefs);
406 if (*pref_name_in == prefs::kAcceptLanguages) { 667 if (*pref_name_in == prefs::kAcceptLanguages) {
407 std::string accept_language = 668 std::string accept_language =
408 WideToASCII(prefs->GetString(prefs::kAcceptLanguages)); 669 WideToASCII(prefs->GetString(prefs::kAcceptLanguages));
409 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, 670 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
410 NewRunnableMethod(this, 671 NewRunnableMethod(
411 &ChromeURLRequestContext::OnAcceptLanguageChange, 672 this,
412 accept_language)); 673 &ChromeURLRequestContextGetter::OnAcceptLanguageChange,
674 accept_language));
413 } else if (*pref_name_in == prefs::kCookieBehavior) { 675 } else if (*pref_name_in == prefs::kCookieBehavior) {
414 net::CookiePolicy::Type policy_type = net::CookiePolicy::FromInt( 676 net::CookiePolicy::Type policy_type = net::CookiePolicy::FromInt(
415 prefs_->GetInteger(prefs::kCookieBehavior)); 677 prefs_->GetInteger(prefs::kCookieBehavior));
416 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, 678 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
417 NewRunnableMethod(this, 679 NewRunnableMethod(
418 &ChromeURLRequestContext::OnCookiePolicyChange, 680 this,
419 policy_type)); 681 &ChromeURLRequestContextGetter::OnCookiePolicyChange,
682 policy_type));
420 } else if (*pref_name_in == prefs::kDefaultCharset) { 683 } else if (*pref_name_in == prefs::kDefaultCharset) {
421 std::string default_charset = 684 std::string default_charset =
422 WideToASCII(prefs->GetString(prefs::kDefaultCharset)); 685 WideToASCII(prefs->GetString(prefs::kDefaultCharset));
423 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, 686 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
424 NewRunnableMethod(this, 687 NewRunnableMethod(
425 &ChromeURLRequestContext::OnDefaultCharsetChange, 688 this,
426 default_charset)); 689 &ChromeURLRequestContextGetter::OnDefaultCharsetChange,
690 default_charset));
427 } 691 }
428 } else { 692 } else {
429 NOTREACHED(); 693 NOTREACHED();
430 } 694 }
431 } 695 }
432 696
433 void ChromeURLRequestContext::CleanupOnUIThread() { 697 void ChromeURLRequestContextGetter::OnAcceptLanguageChange(
434 // Unregister for pref notifications. 698 const std::string& accept_language) {
435 prefs_->RemovePrefObserver(prefs::kAcceptLanguages, this); 699 GetIOContext()->OnAcceptLanguageChange(accept_language);
436 prefs_->RemovePrefObserver(prefs::kCookieBehavior, this); 700 }
437 prefs_->RemovePrefObserver(prefs::kDefaultCharset, this);
438 prefs_ = NULL;
439 701
702 void ChromeURLRequestContextGetter::OnCookiePolicyChange(
703 net::CookiePolicy::Type type) {
704 GetIOContext()->OnCookiePolicyChange(type);
705 }
706
707 void ChromeURLRequestContextGetter::OnDefaultCharsetChange(
708 const std::string& default_charset) {
709 GetIOContext()->OnDefaultCharsetChange(default_charset);
710 }
711
712 void ChromeURLRequestContextGetter::OnNewExtensions(const std::string& id,
713 const FilePath& path) {
714 GetIOContext()->OnNewExtensions(id, path);
715 }
716
717 void ChromeURLRequestContextGetter::OnUnloadedExtension(
718 const std::string& id) {
719 GetIOContext()->OnUnloadedExtension(id);
720 }
721
722 void ChromeURLRequestContextGetter::CleanupOnUIThread() {
723 CheckCurrentlyOnMainThread();
724
725 if (prefs_) {
726 // Unregister for pref notifications.
727 prefs_->RemovePrefObserver(prefs::kAcceptLanguages, this);
728 prefs_->RemovePrefObserver(prefs::kCookieBehavior, this);
729 prefs_->RemovePrefObserver(prefs::kDefaultCharset, this);
730 prefs_ = NULL;
731 }
732
733 // TODO(eroman): Doesn't look like this member is even used...
734 // can probably be deleted.
440 registrar_.RemoveAll(); 735 registrar_.RemoveAll();
441 } 736 }
442 737
738 ChromeURLRequestContextGetter::~ChromeURLRequestContextGetter() {
739 CheckCurrentlyOnIOThread();
740
741 DCHECK(!prefs_) << "Probably didn't call CleanupOnUIThread";
742
743 // Either we already transformed the factory into a URLRequestContext, or
744 // we still have a pending factory.
745 DCHECK((factory_.get() && !url_request_context_.get()) ||
746 (!factory_.get() && url_request_context_.get()));
747
748 // The scoped_refptr / scoped_ptr destructors take care of releasing
749 // |factory_| and |url_request_context_| now.
750 }
751
752 ChromeURLRequestContext::ChromeURLRequestContext() {
753 CheckCurrentlyOnIOThread();
754 }
755
443 FilePath ChromeURLRequestContext::GetPathForExtension(const std::string& id) { 756 FilePath ChromeURLRequestContext::GetPathForExtension(const std::string& id) {
444 ExtensionPaths::iterator iter = extension_paths_.find(id); 757 ExtensionPaths::iterator iter = extension_paths_.find(id);
445 if (iter != extension_paths_.end()) { 758 if (iter != extension_paths_.end()) {
446 return iter->second; 759 return iter->second;
447 } else { 760 } else {
448 return FilePath(); 761 return FilePath();
449 } 762 }
450 } 763 }
451 764
452 const std::string& ChromeURLRequestContext::GetUserAgent( 765 const std::string& ChromeURLRequestContext::GetUserAgent(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 Details<const URLRequest>(request)); 802 Details<const URLRequest>(request));
490 803
491 return false; 804 return false;
492 } 805 }
493 } 806 }
494 return true; 807 return true;
495 } 808 }
496 809
497 void ChromeURLRequestContext::OnAcceptLanguageChange( 810 void ChromeURLRequestContext::OnAcceptLanguageChange(
498 const std::string& accept_language) { 811 const std::string& accept_language) {
499 DCHECK(MessageLoop::current() == 812 CheckCurrentlyOnIOThread();
500 ChromeThread::GetMessageLoop(ChromeThread::IO));
501 accept_language_ = 813 accept_language_ =
502 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language); 814 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language);
503 } 815 }
504 816
505 void ChromeURLRequestContext::OnCookiePolicyChange( 817 void ChromeURLRequestContext::OnCookiePolicyChange(
506 net::CookiePolicy::Type type) { 818 net::CookiePolicy::Type type) {
507 DCHECK(MessageLoop::current() == 819 CheckCurrentlyOnIOThread();
508 ChromeThread::GetMessageLoop(ChromeThread::IO));
509 cookie_policy_.set_type(type); 820 cookie_policy_.set_type(type);
510 } 821 }
511 822
512 void ChromeURLRequestContext::OnDefaultCharsetChange( 823 void ChromeURLRequestContext::OnDefaultCharsetChange(
513 const std::string& default_charset) { 824 const std::string& default_charset) {
514 DCHECK(MessageLoop::current() == 825 CheckCurrentlyOnIOThread();
515 ChromeThread::GetMessageLoop(ChromeThread::IO));
516 referrer_charset_ = default_charset; 826 referrer_charset_ = default_charset;
517 accept_charset_ = 827 accept_charset_ =
518 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset); 828 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset);
519 } 829 }
520 830
521 void ChromeURLRequestContext::OnNewExtensions(const std::string& id, 831 void ChromeURLRequestContext::OnNewExtensions(const std::string& id,
522 const FilePath& path) { 832 const FilePath& path) {
523 if (!is_off_the_record_) 833 if (!is_off_the_record_)
524 extension_paths_[id] = path; 834 extension_paths_[id] = path;
525 } 835 }
526 836
527 void ChromeURLRequestContext::OnUnloadedExtension(const std::string& id) { 837 void ChromeURLRequestContext::OnUnloadedExtension(const std::string& id) {
838 CheckCurrentlyOnIOThread();
528 if (is_off_the_record_) 839 if (is_off_the_record_)
529 return; 840 return;
530 ExtensionPaths::iterator iter = extension_paths_.find(id); 841 ExtensionPaths::iterator iter = extension_paths_.find(id);
531 DCHECK(iter != extension_paths_.end()); 842 DCHECK(iter != extension_paths_.end());
532 extension_paths_.erase(iter); 843 extension_paths_.erase(iter);
533 } 844 }
534 845
535 ChromeURLRequestContext::~ChromeURLRequestContext() { 846 ChromeURLRequestContext::~ChromeURLRequestContext() {
536 DCHECK(NULL == prefs_); 847 CheckCurrentlyOnIOThread();
537
538 if (appcache_service_.get() && appcache_service_->request_context() == this) 848 if (appcache_service_.get() && appcache_service_->request_context() == this)
539 appcache_service_->set_request_context(NULL); 849 appcache_service_->set_request_context(NULL);
540 850
541 NotificationService::current()->Notify( 851 NotificationService::current()->Notify(
542 NotificationType::URL_REQUEST_CONTEXT_RELEASED, 852 NotificationType::URL_REQUEST_CONTEXT_RELEASED,
543 Source<URLRequestContext>(this), 853 Source<URLRequestContext>(this),
544 NotificationService::NoDetails()); 854 NotificationService::NoDetails());
545 855
546 delete ftp_transaction_factory_; 856 delete ftp_transaction_factory_;
547 delete http_transaction_factory_; 857 delete http_transaction_factory_;
548 } 858 }
859
860 net::CookieStore* ChromeURLRequestContextGetter::GetCookieStore() {
861 // If we are running on the IO thread this is real easy.
862 if (ChromeThread::CurrentlyOn(ChromeThread::IO))
863 return GetURLRequestContext()->cookie_store();
864
865 // If we aren't running on the IO thread, we cannot call
866 // GetURLRequestContext(). Instead we will post a task to the IO loop
867 // and wait for it to complete.
868
869 base::WaitableEvent completion(false, false);
870 net::CookieStore* result = NULL;
871
872 g_browser_process->io_thread()->message_loop()->PostTask(
873 FROM_HERE,
874 NewRunnableMethod(this,
875 &ChromeURLRequestContextGetter::GetCookieStoreAsyncHelper,
876 &completion,
877 &result));
878
879 completion.Wait();
880 DCHECK(result);
881 return result;
882 }
883
884 void ChromeURLRequestContextGetter::GetCookieStoreAsyncHelper(
885 base::WaitableEvent* completion,
886 net::CookieStore** result) {
887 // Note that CookieStore is refcounted, yet we do not add a reference.
888 *result = GetURLRequestContext()->cookie_store();
889 completion->Signal();
890 }
OLDNEW
« no previous file with comments | « chrome/browser/net/chrome_url_request_context.h ('k') | chrome/browser/net/resolve_proxy_msg_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698