| OLD | NEW |
| 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/profile.h" | 13 #include "chrome/browser/profile.h" |
| 14 #include "chrome/common/chrome_constants.h" | 14 #include "chrome/common/chrome_constants.h" |
| 15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 17 #include "net/http/http_cache.h" | 17 #include "net/http/http_cache.h" |
| 18 #include "net/proxy/proxy_service.h" | 18 #include "net/proxy/proxy_service.h" |
| 19 #include "webkit/glue/webkit_glue.h" | 19 #include "webkit/glue/webkit_glue.h" |
| 20 | 20 |
| 21 // Sets up proxy info if it was specified, otherwise returns NULL. The | 21 // Sets up proxy info if it was specified, otherwise returns NULL. The |
| 22 // returned pointer MUST be deleted by the caller if non-NULL. | 22 // returned pointer MUST be deleted by the caller if non-NULL. |
| 23 static net::ProxyInfo* CreateProxyInfo() { | 23 static net::ProxyInfo* CreateProxyInfo() { |
| 24 net::ProxyInfo* proxy_info = NULL; | 24 net::ProxyInfo* proxy_info = NULL; |
| 25 | 25 |
| 26 CommandLine command_line; | 26 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 27 if (command_line.HasSwitch(switches::kProxyServer)) { | 27 if (command_line.HasSwitch(switches::kProxyServer)) { |
| 28 proxy_info = new net::ProxyInfo(); | 28 proxy_info = new net::ProxyInfo(); |
| 29 const std::wstring& proxy_server = | 29 const std::wstring& proxy_server = |
| 30 command_line.GetSwitchValue(switches::kProxyServer); | 30 command_line.GetSwitchValue(switches::kProxyServer); |
| 31 proxy_info->UseNamedProxy(WideToASCII(proxy_server)); | 31 proxy_info->UseNamedProxy(WideToASCII(proxy_server)); |
| 32 } | 32 } |
| 33 | 33 |
| 34 return proxy_info; | 34 return proxy_info; |
| 35 } | 35 } |
| 36 | 36 |
| 37 // static | 37 // static |
| 38 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal( | 38 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal( |
| 39 Profile* profile, const std::wstring& cookie_store_path, | 39 Profile* profile, const std::wstring& cookie_store_path, |
| 40 const std::wstring& disk_cache_path) { | 40 const std::wstring& disk_cache_path) { |
| 41 DCHECK(!profile->IsOffTheRecord()); | 41 DCHECK(!profile->IsOffTheRecord()); |
| 42 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); | 42 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); |
| 43 | 43 |
| 44 scoped_ptr<net::ProxyInfo> proxy_info(CreateProxyInfo()); | 44 scoped_ptr<net::ProxyInfo> proxy_info(CreateProxyInfo()); |
| 45 context->proxy_service_ = net::ProxyService::Create(proxy_info.get()); | 45 context->proxy_service_ = net::ProxyService::Create(proxy_info.get()); |
| 46 | 46 |
| 47 net::HttpCache* cache = | 47 net::HttpCache* cache = |
| 48 new net::HttpCache(context->proxy_service_, disk_cache_path, 0); | 48 new net::HttpCache(context->proxy_service_, disk_cache_path, 0); |
| 49 | 49 |
| 50 CommandLine command_line; | 50 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 51 bool record_mode = chrome::kRecordModeEnabled && | 51 bool record_mode = chrome::kRecordModeEnabled && |
| 52 command_line.HasSwitch(switches::kRecordMode); | 52 command_line.HasSwitch(switches::kRecordMode); |
| 53 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); | 53 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); |
| 54 | 54 |
| 55 if (record_mode || playback_mode) { | 55 if (record_mode || playback_mode) { |
| 56 // Don't use existing cookies and use an in-memory store. | 56 // Don't use existing cookies and use an in-memory store. |
| 57 context->cookie_store_ = new net::CookieMonster(); | 57 context->cookie_store_ = new net::CookieMonster(); |
| 58 cache->set_mode( | 58 cache->set_mode( |
| 59 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); | 59 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); |
| 60 } | 60 } |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 NotificationService::NoDetails()); | 205 NotificationService::NoDetails()); |
| 206 | 206 |
| 207 delete cookie_store_; | 207 delete cookie_store_; |
| 208 delete http_transaction_factory_; | 208 delete http_transaction_factory_; |
| 209 | 209 |
| 210 // Do not delete the proxy service in the case of OTR, as it is owned by the | 210 // Do not delete the proxy service in the case of OTR, as it is owned by the |
| 211 // original URLRequestContext. | 211 // original URLRequestContext. |
| 212 if (!is_off_the_record_) | 212 if (!is_off_the_record_) |
| 213 delete proxy_service_; | 213 delete proxy_service_; |
| 214 } | 214 } |
| OLD | NEW |