OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 g_browser_process->io_thread()->message_loop(), | 76 g_browser_process->io_thread()->message_loop(), |
77 g_browser_process->file_thread()->message_loop()); | 77 g_browser_process->file_thread()->message_loop()); |
78 } | 78 } |
79 | 79 |
80 // Otherwise use the fixed settings from the command line. | 80 // Otherwise use the fixed settings from the command line. |
81 return new net::ProxyConfigServiceFixed(*proxy_config.get()); | 81 return new net::ProxyConfigServiceFixed(*proxy_config.get()); |
82 } | 82 } |
83 | 83 |
84 // Create a proxy service according to the options on command line. | 84 // Create a proxy service according to the options on command line. |
85 net::ProxyService* CreateProxyService( | 85 net::ProxyService* CreateProxyService( |
86 net::NetworkChangeNotifier* network_change_notifier, | |
87 net::NetLog* net_log, | 86 net::NetLog* net_log, |
88 URLRequestContext* context, | 87 URLRequestContext* context, |
89 net::ProxyConfigService* proxy_config_service, | 88 net::ProxyConfigService* proxy_config_service, |
90 const CommandLine& command_line, | 89 const CommandLine& command_line, |
91 MessageLoop* io_loop) { | 90 MessageLoop* io_loop) { |
92 CheckCurrentlyOnIOThread(); | 91 CheckCurrentlyOnIOThread(); |
93 | 92 |
94 bool use_v8 = !command_line.HasSwitch(switches::kWinHttpProxyResolver); | 93 bool use_v8 = !command_line.HasSwitch(switches::kWinHttpProxyResolver); |
95 if (use_v8 && command_line.HasSwitch(switches::kSingleProcess)) { | 94 if (use_v8 && command_line.HasSwitch(switches::kSingleProcess)) { |
96 // See the note about V8 multithreading in net/proxy/proxy_resolver_v8.h | 95 // See the note about V8 multithreading in net/proxy/proxy_resolver_v8.h |
97 // to understand why we have this limitation. | 96 // to understand why we have this limitation. |
98 LOG(ERROR) << "Cannot use V8 Proxy resolver in single process mode."; | 97 LOG(ERROR) << "Cannot use V8 Proxy resolver in single process mode."; |
99 use_v8 = false; // Fallback to non-v8 implementation. | 98 use_v8 = false; // Fallback to non-v8 implementation. |
100 } | 99 } |
101 | 100 |
102 return net::ProxyService::Create( | 101 return net::ProxyService::Create( |
103 proxy_config_service, | 102 proxy_config_service, |
104 use_v8, | 103 use_v8, |
105 context, | 104 context, |
106 network_change_notifier, | |
107 net_log, | 105 net_log, |
108 io_loop); | 106 io_loop); |
109 } | 107 } |
110 | 108 |
111 // ---------------------------------------------------------------------------- | 109 // ---------------------------------------------------------------------------- |
112 // CookieMonster::Delegate implementation | 110 // CookieMonster::Delegate implementation |
113 // ---------------------------------------------------------------------------- | 111 // ---------------------------------------------------------------------------- |
114 class ChromeCookieMonsterDelegate : public net::CookieMonster::Delegate { | 112 class ChromeCookieMonsterDelegate : public net::CookieMonster::Delegate { |
115 public: | 113 public: |
116 explicit ChromeCookieMonsterDelegate(Profile* profile) { | 114 explicit ChromeCookieMonsterDelegate(Profile* profile) { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 IOThread::Globals* io_thread_globals = io_thread()->globals(); | 230 IOThread::Globals* io_thread_globals = io_thread()->globals(); |
233 | 231 |
234 // Global host resolver for the context. | 232 // Global host resolver for the context. |
235 context->set_host_resolver(io_thread_globals->host_resolver); | 233 context->set_host_resolver(io_thread_globals->host_resolver); |
236 context->set_http_auth_handler_factory( | 234 context->set_http_auth_handler_factory( |
237 io_thread_globals->http_auth_handler_factory.get()); | 235 io_thread_globals->http_auth_handler_factory.get()); |
238 | 236 |
239 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 237 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
240 | 238 |
241 context->set_proxy_service( | 239 context->set_proxy_service( |
242 CreateProxyService(io_thread_globals->network_change_notifier.get(), | 240 CreateProxyService(io_thread_globals->net_log.get(), |
243 io_thread_globals->net_log.get(), | |
244 context, | 241 context, |
245 proxy_config_service_.release(), | 242 proxy_config_service_.release(), |
246 command_line, | 243 command_line, |
247 MessageLoop::current() /*io_loop*/)); | 244 MessageLoop::current() /*io_loop*/)); |
248 | 245 |
249 net::HttpCache::DefaultBackend* backend = new net::HttpCache::DefaultBackend( | 246 net::HttpCache::DefaultBackend* backend = new net::HttpCache::DefaultBackend( |
250 net::DISK_CACHE, disk_cache_path_, cache_size_, | 247 net::DISK_CACHE, disk_cache_path_, cache_size_, |
251 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::CACHE)); | 248 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::CACHE)); |
252 net::HttpCache* cache = | 249 net::HttpCache* cache = |
253 new net::HttpCache(io_thread_globals->network_change_notifier.get(), | 250 new net::HttpCache(context->host_resolver(), |
254 context->host_resolver(), | |
255 context->proxy_service(), | 251 context->proxy_service(), |
256 context->ssl_config_service(), | 252 context->ssl_config_service(), |
257 context->http_auth_handler_factory(), | 253 context->http_auth_handler_factory(), |
258 &io_thread_globals->network_delegate, | 254 &io_thread_globals->network_delegate, |
259 io_thread_globals->net_log.get(), | 255 io_thread_globals->net_log.get(), |
260 backend); | 256 backend); |
261 | 257 |
262 if (command_line.HasSwitch(switches::kDisableByteRangeSupport)) | 258 if (command_line.HasSwitch(switches::kDisableByteRangeSupport)) |
263 cache->set_enable_range_support(false); | 259 cache->set_enable_range_support(false); |
264 | 260 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 // as the original profile. | 368 // as the original profile. |
373 context->set_host_resolver(original_context->host_resolver()); | 369 context->set_host_resolver(original_context->host_resolver()); |
374 context->set_proxy_service(original_context->proxy_service()); | 370 context->set_proxy_service(original_context->proxy_service()); |
375 context->set_http_auth_handler_factory( | 371 context->set_http_auth_handler_factory( |
376 original_context->http_auth_handler_factory()); | 372 original_context->http_auth_handler_factory()); |
377 | 373 |
378 net::HttpCache::BackendFactory* backend = | 374 net::HttpCache::BackendFactory* backend = |
379 net::HttpCache::DefaultBackend::InMemory(0); | 375 net::HttpCache::DefaultBackend::InMemory(0); |
380 | 376 |
381 net::HttpCache* cache = | 377 net::HttpCache* cache = |
382 new net::HttpCache(io_thread_globals->network_change_notifier.get(), | 378 new net::HttpCache(context->host_resolver(), |
383 context->host_resolver(), | |
384 context->proxy_service(), | 379 context->proxy_service(), |
385 context->ssl_config_service(), | 380 context->ssl_config_service(), |
386 context->http_auth_handler_factory(), | 381 context->http_auth_handler_factory(), |
387 &io_thread_globals->network_delegate, | 382 &io_thread_globals->network_delegate, |
388 io_thread_globals->net_log.get(), | 383 io_thread_globals->net_log.get(), |
389 backend); | 384 backend); |
390 context->set_cookie_store(new net::CookieMonster(NULL, | 385 context->set_cookie_store(new net::CookieMonster(NULL, |
391 cookie_monster_delegate_)); | 386 cookie_monster_delegate_)); |
392 context->set_cookie_policy( | 387 context->set_cookie_policy( |
393 new ChromeCookiePolicy(host_content_settings_map_)); | 388 new ChromeCookiePolicy(host_content_settings_map_)); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 // HttpCache(HttpTransactionFactory*, BackendFactory*) constructor. | 465 // HttpCache(HttpTransactionFactory*, BackendFactory*) constructor. |
471 net::HttpNetworkLayer* main_network_layer = | 466 net::HttpNetworkLayer* main_network_layer = |
472 static_cast<net::HttpNetworkLayer*>(main_cache->network_layer()); | 467 static_cast<net::HttpNetworkLayer*>(main_cache->network_layer()); |
473 cache = new net::HttpCache(main_network_layer->GetSession(), backend); | 468 cache = new net::HttpCache(main_network_layer->GetSession(), backend); |
474 // TODO(eroman): Since this is poaching the session from the main | 469 // TODO(eroman): Since this is poaching the session from the main |
475 // context, it should hold a reference to that context preventing the | 470 // context, it should hold a reference to that context preventing the |
476 // session from getting deleted. | 471 // session from getting deleted. |
477 } else { | 472 } else { |
478 // If original HttpCache doesn't exist, simply construct one with a whole | 473 // If original HttpCache doesn't exist, simply construct one with a whole |
479 // new set of network stack. | 474 // new set of network stack. |
480 cache = new net::HttpCache( | 475 cache = new net::HttpCache(main_context->host_resolver(), |
481 io_thread_globals->network_change_notifier.get(), | 476 main_context->proxy_service(), |
482 main_context->host_resolver(), | 477 main_context->ssl_config_service(), |
483 main_context->proxy_service(), | 478 main_context->http_auth_handler_factory(), |
484 main_context->ssl_config_service(), | 479 &io_thread_globals->network_delegate, |
485 main_context->http_auth_handler_factory(), | 480 io_thread_globals->net_log.get(), |
486 &io_thread_globals->network_delegate, | 481 backend); |
487 io_thread_globals->net_log.get(), | |
488 backend); | |
489 } | 482 } |
490 | 483 |
491 if (CommandLine::ForCurrentProcess()->HasSwitch( | 484 if (CommandLine::ForCurrentProcess()->HasSwitch( |
492 switches::kDisableByteRangeSupport)) | 485 switches::kDisableByteRangeSupport)) |
493 cache->set_enable_range_support(false); | 486 cache->set_enable_range_support(false); |
494 | 487 |
495 context->set_http_transaction_factory(cache); | 488 context->set_http_transaction_factory(cache); |
496 | 489 |
497 // Use the same appcache service as the profile's main context. | 490 // Use the same appcache service as the profile's main context. |
498 context->set_appcache_service(main_context->appcache_service()); | 491 context->set_appcache_service(main_context->appcache_service()); |
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1074 | 1067 |
1075 if (pref_service->HasPrefPath(prefs::kProxyBypassList)) { | 1068 if (pref_service->HasPrefPath(prefs::kProxyBypassList)) { |
1076 std::wstring proxy_bypass = | 1069 std::wstring proxy_bypass = |
1077 pref_service->GetString(prefs::kProxyBypassList); | 1070 pref_service->GetString(prefs::kProxyBypassList); |
1078 proxy_config->proxy_rules().bypass_rules.ParseFromString( | 1071 proxy_config->proxy_rules().bypass_rules.ParseFromString( |
1079 WideToASCII(proxy_bypass)); | 1072 WideToASCII(proxy_bypass)); |
1080 } | 1073 } |
1081 | 1074 |
1082 return proxy_config; | 1075 return proxy_config; |
1083 } | 1076 } |
OLD | NEW |