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

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

Issue 27365: Add a command line flag --v8-proxy-resolver, to select the new PAC implementa... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Address wtc's comments Created 11 years, 9 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/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/notification_service.h" 16 #include "chrome/common/notification_service.h"
17 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "net/http/http_cache.h" 18 #include "net/http/http_cache.h"
19 #include "net/http/http_network_layer.h" 19 #include "net/http/http_network_layer.h"
20 #include "net/http/http_util.h" 20 #include "net/http/http_util.h"
21 #include "net/proxy/proxy_service.h" 21 #include "net/proxy/proxy_service.h"
22 #include "webkit/glue/webkit_glue.h" 22 #include "webkit/glue/webkit_glue.h"
23 23
24 // Sets up proxy info if it was specified, otherwise returns NULL. The 24 // Sets up proxy info if overrides were specified on the command line.
25 // returned pointer MUST be deleted by the caller if non-NULL. 25 // Otherwise returns NULL (meaning we should use the system defaults).
26 static net::ProxyInfo* CreateProxyInfo() { 26 // The caller is responsible for deleting returned pointer.
27 static net::ProxyInfo* CreateProxyInfo(const CommandLine& command_line) {
27 net::ProxyInfo* proxy_info = NULL; 28 net::ProxyInfo* proxy_info = NULL;
28 29
29 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
30 if (command_line.HasSwitch(switches::kProxyServer)) { 30 if (command_line.HasSwitch(switches::kProxyServer)) {
31 proxy_info = new net::ProxyInfo(); 31 proxy_info = new net::ProxyInfo();
32 const std::wstring& proxy_server = 32 const std::wstring& proxy_server =
33 command_line.GetSwitchValue(switches::kProxyServer); 33 command_line.GetSwitchValue(switches::kProxyServer);
34 proxy_info->UseNamedProxy(WideToASCII(proxy_server)); 34 proxy_info->UseNamedProxy(WideToASCII(proxy_server));
35 } 35 }
36 36
37 return proxy_info; 37 return proxy_info;
38 } 38 }
39 39
40 // Create a proxy service according to the options on command line.
41 static net::ProxyService* CreateProxyService(URLRequestContext* context,
42 const CommandLine& command_line) {
43 scoped_ptr<net::ProxyInfo> proxy_info(CreateProxyInfo(command_line));
44
45 bool use_v8 = command_line.HasSwitch(switches::kV8ProxyResolver);
46 if (use_v8 && command_line.HasSwitch(switches::kSingleProcess)) {
47 // See the note about V8 multithreading in net/proxy/proxy_resolver_v8.h
48 // to understand why we have this limitation.
49 LOG(ERROR) << "Cannot use V8 Proxy resolver in single process mode.";
50 use_v8 = false; // Fallback to non-v8 implementation.
51 }
52
53 return use_v8 ?
54 net::ProxyService::CreateUsingV8Resolver(proxy_info.get(), context) :
55 net::ProxyService::Create(proxy_info.get());
56 }
57
40 // static 58 // static
41 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal( 59 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal(
42 Profile* profile, const FilePath& cookie_store_path, 60 Profile* profile, const FilePath& cookie_store_path,
43 const FilePath& disk_cache_path) { 61 const FilePath& disk_cache_path) {
44 DCHECK(!profile->IsOffTheRecord()); 62 DCHECK(!profile->IsOffTheRecord());
45 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); 63 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile);
46 64
47 scoped_ptr<net::ProxyInfo> proxy_info(CreateProxyInfo()); 65 context->proxy_service_ = CreateProxyService(
48 context->proxy_service_ = net::ProxyService::Create(proxy_info.get()); 66 context, *CommandLine::ForCurrentProcess());
49 67
50 net::HttpCache* cache = 68 net::HttpCache* cache =
51 new net::HttpCache(context->proxy_service_, 69 new net::HttpCache(context->proxy_service_,
52 disk_cache_path.ToWStringHack(), 0); 70 disk_cache_path.ToWStringHack(), 0);
53 71
54 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 72 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
55 bool record_mode = chrome::kRecordModeEnabled && 73 bool record_mode = chrome::kRecordModeEnabled &&
56 command_line.HasSwitch(switches::kRecordMode); 74 command_line.HasSwitch(switches::kRecordMode);
57 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); 75 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode);
58 76
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 NotificationService::NoDetails()); 288 NotificationService::NoDetails());
271 289
272 delete cookie_store_; 290 delete cookie_store_;
273 delete http_transaction_factory_; 291 delete http_transaction_factory_;
274 292
275 // Do not delete the proxy service in the case of OTR, as it is owned by the 293 // Do not delete the proxy service in the case of OTR, as it is owned by the
276 // original URLRequestContext. 294 // original URLRequestContext.
277 if (!is_off_the_record_) 295 if (!is_off_the_record_)
278 delete proxy_service_; 296 delete proxy_service_;
279 } 297 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698