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

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

Issue 115029: Making command-line specified proxy settings more flexible - allowing for set... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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) 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/extension.h" 11 #include "chrome/browser/extensions/extension.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/profile.h" 14 #include "chrome/browser/profile.h"
15 #include "chrome/common/chrome_constants.h" 15 #include "chrome/common/chrome_constants.h"
16 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/notification_service.h" 17 #include "chrome/common/notification_service.h"
18 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
19 #include "net/ftp/ftp_network_layer.h" 19 #include "net/ftp/ftp_network_layer.h"
20 #include "net/http/http_cache.h" 20 #include "net/http/http_cache.h"
21 #include "net/http/http_network_layer.h" 21 #include "net/http/http_network_layer.h"
22 #include "net/http/http_util.h" 22 #include "net/http/http_util.h"
23 #include "net/proxy/proxy_service.h" 23 #include "net/proxy/proxy_service.h"
24 #include "webkit/glue/webkit_glue.h" 24 #include "webkit/glue/webkit_glue.h"
25 25
26 // Sets up proxy info if overrides were specified on the command line. 26 net::ProxyConfig* CreateProxyConfig(const CommandLine& command_line) {
27 // Otherwise returns NULL (meaning we should use the system defaults). 27 // Scan for all "enable" type proxy switches.
28 // The caller is responsible for deleting returned pointer. 28 static const wchar_t* proxy_switches[] = {
29 static net::ProxyInfo* CreateProxyInfo(const CommandLine& command_line) { 29 switches::kProxyServer,
30 net::ProxyInfo* proxy_info = NULL; 30 switches::kProxyServerPacUrl,
31 switches::kProxyServerAutoDetect,
32 switches::kProxyServerBypassUrls
33 };
34
35 bool found_enable_proxy_switch = false;
36 for (size_t i = 0; i < arraysize(proxy_switches); i++) {
37 if (command_line.HasSwitch(proxy_switches[i])) {
38 found_enable_proxy_switch = true;
39 break;
40 }
41 }
42
43 if (!found_enable_proxy_switch &&
44 !command_line.HasSwitch(switches::kNoProxyServer)) {
45 return NULL;
46 }
47
48 net::ProxyConfig* proxy_config = new net::ProxyConfig();
49 if (command_line.HasSwitch(switches::kNoProxyServer)) {
50 // Ignore (and warn about) all the other proxy config switches we get if
51 // the no-proxy-server command line argument is present.
52 if (found_enable_proxy_switch) {
53 LOG(WARNING) << "Additional command line proxy switches found when --"
54 << switches::kNoProxyServer << " was specified.";
55 }
56 return proxy_config;
57 }
31 58
32 if (command_line.HasSwitch(switches::kProxyServer)) { 59 if (command_line.HasSwitch(switches::kProxyServer)) {
33 proxy_info = new net::ProxyInfo();
34 const std::wstring& proxy_server = 60 const std::wstring& proxy_server =
35 command_line.GetSwitchValue(switches::kProxyServer); 61 command_line.GetSwitchValue(switches::kProxyServer);
36 proxy_info->UseNamedProxy(WideToASCII(proxy_server)); 62 proxy_config->proxy_rules.ParseFromString(WideToASCII(proxy_server));
37 } 63 }
38 64
39 return proxy_info; 65 if (command_line.HasSwitch(switches::kProxyServerPacUrl)) {
66 proxy_config->pac_url =
67 GURL(WideToASCII(command_line.GetSwitchValue(
68 switches::kProxyServerPacUrl)));
69 }
70
71 if (command_line.HasSwitch(switches::kProxyServerAutoDetect)) {
72 proxy_config->auto_detect = true;
73 }
74
75 if (command_line.HasSwitch(switches::kProxyServerBypassUrls)) {
76 proxy_config->ParseNoProxyList(
77 WideToASCII(command_line.GetSwitchValue(
78 switches::kProxyServerBypassUrls)));
79 }
80
81 return proxy_config;
40 } 82 }
41 83
42 // Create a proxy service according to the options on command line. 84 // Create a proxy service according to the options on command line.
43 static net::ProxyService* CreateProxyService(URLRequestContext* context, 85 static net::ProxyService* CreateProxyService(URLRequestContext* context,
44 const CommandLine& command_line) { 86 const CommandLine& command_line) {
45 scoped_ptr<net::ProxyInfo> proxy_info(CreateProxyInfo(command_line)); 87 scoped_ptr<net::ProxyConfig> proxy_config(CreateProxyConfig(command_line));
46 88
47 bool use_v8 = !command_line.HasSwitch(switches::kWinHttpProxyResolver); 89 bool use_v8 = !command_line.HasSwitch(switches::kWinHttpProxyResolver);
48 if (use_v8 && command_line.HasSwitch(switches::kSingleProcess)) { 90 if (use_v8 && command_line.HasSwitch(switches::kSingleProcess)) {
49 // See the note about V8 multithreading in net/proxy/proxy_resolver_v8.h 91 // See the note about V8 multithreading in net/proxy/proxy_resolver_v8.h
50 // to understand why we have this limitation. 92 // to understand why we have this limitation.
51 LOG(ERROR) << "Cannot use V8 Proxy resolver in single process mode."; 93 LOG(ERROR) << "Cannot use V8 Proxy resolver in single process mode.";
52 use_v8 = false; // Fallback to non-v8 implementation. 94 use_v8 = false; // Fallback to non-v8 implementation.
53 } 95 }
54 96
55 return use_v8 ? 97 return use_v8 ?
56 net::ProxyService::CreateUsingV8Resolver(proxy_info.get(), context) : 98 net::ProxyService::CreateUsingV8Resolver(proxy_config.get(), context) :
57 net::ProxyService::Create(proxy_info.get()); 99 net::ProxyService::Create(proxy_config.get());
58 } 100 }
59 101
60 // static 102 // static
61 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal( 103 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal(
62 Profile* profile, const FilePath& cookie_store_path, 104 Profile* profile, const FilePath& cookie_store_path,
63 const FilePath& disk_cache_path) { 105 const FilePath& disk_cache_path) {
64 DCHECK(!profile->IsOffTheRecord()); 106 DCHECK(!profile->IsOffTheRecord());
65 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); 107 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile);
66 108
67 context->proxy_service_ = CreateProxyService( 109 context->proxy_service_ = CreateProxyService(
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 // Do not delete the cookie store in the case of the media context, as it is 376 // Do not delete the cookie store in the case of the media context, as it is
335 // owned by the original context. 377 // owned by the original context.
336 if (!is_media_) 378 if (!is_media_)
337 delete cookie_store_; 379 delete cookie_store_;
338 380
339 // Do not delete the proxy service in the case of OTR or media contexts, as 381 // Do not delete the proxy service in the case of OTR or media contexts, as
340 // it is owned by the original URLRequestContext. 382 // it is owned by the original URLRequestContext.
341 if (!is_off_the_record_ && !is_media_) 383 if (!is_off_the_record_ && !is_media_)
342 delete proxy_service_; 384 delete proxy_service_;
343 } 385 }
OLDNEW
« no previous file with comments | « chrome/browser/net/chrome_url_request_context.h ('k') | chrome/browser/net/chrome_url_request_context_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698