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

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

Issue 6292017: Extended: Add "system" URLRequestContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup Created 9 years, 10 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
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/net/proxy_service_factory.h"
6
7 #include "base/command_line.h"
8 #include "base/string_number_conversions.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/browser_thread.h"
11 #include "chrome/browser/net/pref_proxy_config_service.h"
12 #include "chrome/browser/io_thread.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/common/chrome_switches.h"
15 #include "net/base/net_log.h"
16 #include "net/proxy/proxy_config_service.h"
17 #include "net/proxy/proxy_script_fetcher_impl.h"
18 #include "net/url_request/url_request_context.h"
19
20 #if defined(OS_CHROMEOS)
21 #include "chrome/browser/chromeos/cros/cros_library.h"
22 #include "chrome/browser/chromeos/cros/libcros_service_library.h"
23 #include "chrome/browser/chromeos/proxy_config_service.h"
24 #endif // defined(OS_CHROMEOS)
25
26 // static
27 net::ProxyConfigService* ProxyServiceFactory::CreateProxyConfigService(
28 MessageLoop* io_message_loop, MessageLoop* file_message_loop,
29 PrefProxyConfigTracker* proxy_config_tracker) {
30 // The linux gconf-based proxy settings getter relies on being initialized
31 // from the UI thread.
32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
33
34 // Create a baseline service that provides proxy configuration in case nothing
35 // is configured through prefs (Note: prefs include command line and
36 // configuration policy).
37 net::ProxyConfigService* base_service = NULL;
38
39 // TODO(port): the IO and FILE message loops are only used by Linux. Can
40 // that code be moved to chrome/browser instead of being in net, so that it
41 // can use BrowserThread instead of raw MessageLoop pointers? See bug 25354.
42 #if defined(OS_CHROMEOS)
43 base_service = new chromeos::ProxyConfigService(
44 profile->GetChromeOSProxyConfigServiceImpl());
45 #else
46 base_service = net::ProxyService::CreateSystemProxyConfigService(
47 io_message_loop, file_message_loop);
48 #endif // defined(OS_CHROMEOS)
49
50 return new PrefProxyConfigService(proxy_config_tracker, base_service);
51 }
52
53 // static
54 net::ProxyService* ProxyServiceFactory::CreateProxyService(
55 net::NetLog* net_log,
56 net::URLRequestContext* context,
57 net::ProxyConfigService* proxy_config_service,
58 const CommandLine& command_line) {
59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
60
61 bool use_v8 = !command_line.HasSwitch(switches::kWinHttpProxyResolver);
62 if (use_v8 && command_line.HasSwitch(switches::kSingleProcess)) {
63 // See the note about V8 multithreading in net/proxy/proxy_resolver_v8.h
64 // to understand why we have this limitation.
65 LOG(ERROR) << "Cannot use V8 Proxy resolver in single process mode.";
66 use_v8 = false; // Fallback to non-v8 implementation.
67 }
68
69 size_t num_pac_threads = 0u; // Use default number of threads.
70
71 // Check the command line for an override on the number of proxy resolver
72 // threads to use.
73 if (command_line.HasSwitch(switches::kNumPacThreads)) {
74 std::string s = command_line.GetSwitchValueASCII(switches::kNumPacThreads);
75
76 // Parse the switch (it should be a positive integer formatted as decimal).
77 int n;
78 if (base::StringToInt(s, &n) && n > 0) {
79 num_pac_threads = static_cast<size_t>(n);
80 } else {
81 LOG(ERROR) << "Invalid switch for number of PAC threads: " << s;
82 }
83 }
84
85 net::ProxyService* proxy_service;
86 if (use_v8) {
87 proxy_service = net::ProxyService::CreateUsingV8ProxyResolver(
88 proxy_config_service,
89 num_pac_threads,
90 new net::ProxyScriptFetcherImpl(context),
91 context->host_resolver(),
92 net_log);
93 } else {
94 proxy_service = net::ProxyService::CreateUsingSystemProxyResolver(
95 proxy_config_service,
96 num_pac_threads,
97 net_log);
98 }
99
100 #if defined(OS_CHROMEOS)
101 if (chromeos::CrosLibrary::Get()->EnsureLoaded()) {
102 chromeos::CrosLibrary::Get()->GetLibCrosServiceLibrary()->
103 RegisterNetworkProxyHandler(proxy_service);
104 }
105 #endif // defined(OS_CHROMEOS)
106
107 return proxy_service;
108 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698