Remove the old signature of NotificationManager::closePersistent().
[chromium-blink-merge.git] / chrome / browser / net / proxy_service_factory.cc
blob8bef0a8f4d70baae6d5ba44e252d01a93b9d2689
1 // Copyright (c) 2012 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.
5 #include "chrome/browser/net/proxy_service_factory.h"
7 #include <string>
9 #include "base/command_line.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/threading/thread.h"
12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/io_thread.h"
14 #include "chrome/browser/net/pref_proxy_config_tracker_impl.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "net/base/net_log.h"
18 #include "net/proxy/dhcp_proxy_script_fetcher_factory.h"
19 #include "net/proxy/proxy_config_service.h"
20 #include "net/proxy/proxy_script_fetcher_impl.h"
21 #include "net/proxy/proxy_service.h"
22 #include "net/proxy/proxy_service_v8.h"
23 #include "net/url_request/url_request_context.h"
25 #if defined(OS_CHROMEOS)
26 #include "chrome/browser/chromeos/proxy_config_service_impl.h"
27 #include "chromeos/network/dhcp_proxy_script_fetcher_chromeos.h"
28 #endif // defined(OS_CHROMEOS)
30 #if !defined(OS_IOS)
31 #include "net/proxy/proxy_resolver_v8.h"
32 #endif
34 #if !defined(OS_IOS) && !defined(OS_ANDROID)
35 #include "chrome/browser/net/utility_process_mojo_proxy_resolver_factory.h"
36 #include "net/proxy/proxy_service_mojo.h"
37 #endif
39 using content::BrowserThread;
41 // static
42 net::ProxyConfigService* ProxyServiceFactory::CreateProxyConfigService(
43 PrefProxyConfigTracker* tracker) {
44 // The linux gconf-based proxy settings getter relies on being initialized
45 // from the UI thread.
46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
48 scoped_ptr<net::ProxyConfigService> base_service;
50 #if !defined(OS_CHROMEOS)
51 // On ChromeOS, base service is NULL; chromeos::ProxyConfigServiceImpl
52 // determines the effective proxy config to take effect in the network layer,
53 // be it from prefs or system (which is network shill on chromeos).
55 // For other platforms, create a baseline service that provides proxy
56 // configuration in case nothing is configured through prefs (Note: prefs
57 // include command line and configuration policy).
59 // TODO(port): the IO and FILE message loops are only used by Linux. Can
60 // that code be moved to chrome/browser instead of being in net, so that it
61 // can use BrowserThread instead of raw MessageLoop pointers? See bug 25354.
62 base_service.reset(net::ProxyService::CreateSystemProxyConfigService(
63 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
64 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)));
65 #endif // !defined(OS_CHROMEOS)
67 return tracker->CreateTrackingProxyConfigService(base_service.Pass())
68 .release();
71 // static
72 PrefProxyConfigTracker*
73 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile(
74 PrefService* profile_prefs,
75 PrefService* local_state_prefs) {
76 #if defined(OS_CHROMEOS)
77 return new chromeos::ProxyConfigServiceImpl(profile_prefs, local_state_prefs);
78 #else
79 return new PrefProxyConfigTrackerImpl(profile_prefs);
80 #endif // defined(OS_CHROMEOS)
83 // static
84 PrefProxyConfigTracker*
85 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
86 PrefService* local_state_prefs) {
87 #if defined(OS_CHROMEOS)
88 return new chromeos::ProxyConfigServiceImpl(NULL, local_state_prefs);
89 #else
90 return new PrefProxyConfigTrackerImpl(local_state_prefs);
91 #endif // defined(OS_CHROMEOS)
94 // static
95 net::ProxyService* ProxyServiceFactory::CreateProxyService(
96 net::NetLog* net_log,
97 net::URLRequestContext* context,
98 net::NetworkDelegate* network_delegate,
99 net::ProxyConfigService* proxy_config_service,
100 const base::CommandLine& command_line,
101 bool quick_check_enabled) {
102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
103 #if defined(OS_IOS)
104 bool use_v8 = false;
105 #else
106 bool use_v8 = !command_line.HasSwitch(switches::kWinHttpProxyResolver);
107 #endif // defined(OS_IOS)
109 size_t num_pac_threads = 0u; // Use default number of threads.
111 // Check the command line for an override on the number of proxy resolver
112 // threads to use.
113 if (command_line.HasSwitch(switches::kNumPacThreads)) {
114 std::string s = command_line.GetSwitchValueASCII(switches::kNumPacThreads);
116 // Parse the switch (it should be a positive integer formatted as decimal).
117 int n;
118 if (base::StringToInt(s, &n) && n > 0) {
119 num_pac_threads = static_cast<size_t>(n);
120 } else {
121 LOG(ERROR) << "Invalid switch for number of PAC threads: " << s;
125 net::ProxyService* proxy_service = NULL;
126 if (use_v8) {
127 #if defined(OS_IOS)
128 NOTREACHED();
129 #else
130 net::DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher;
131 #if defined(OS_CHROMEOS)
132 dhcp_proxy_script_fetcher =
133 new chromeos::DhcpProxyScriptFetcherChromeos(context);
134 #else
135 net::DhcpProxyScriptFetcherFactory dhcp_factory;
136 dhcp_proxy_script_fetcher = dhcp_factory.Create(context);
137 #endif
139 #if !defined(OS_ANDROID)
140 if (command_line.HasSwitch(switches::kV8PacMojoOutOfProcess)) {
141 proxy_service = net::CreateProxyServiceUsingMojoFactory(
142 UtilityProcessMojoProxyResolverFactory::GetInstance(),
143 proxy_config_service, new net::ProxyScriptFetcherImpl(context),
144 dhcp_proxy_script_fetcher, context->host_resolver(), net_log,
145 network_delegate);
146 } else if (command_line.HasSwitch(switches::kV8PacMojoInProcess)) {
147 proxy_service = net::CreateProxyServiceUsingMojoInProcess(
148 proxy_config_service, new net::ProxyScriptFetcherImpl(context),
149 dhcp_proxy_script_fetcher, context->host_resolver(), net_log,
150 network_delegate);
152 #endif // !defined(OS_ANDROID)
154 if (!proxy_service) {
155 proxy_service = net::CreateProxyServiceUsingV8ProxyResolver(
156 proxy_config_service, new net::ProxyScriptFetcherImpl(context),
157 dhcp_proxy_script_fetcher, context->host_resolver(), net_log,
158 network_delegate);
160 #endif // defined(OS_IOS)
161 } else {
162 proxy_service = net::ProxyService::CreateUsingSystemProxyResolver(
163 proxy_config_service,
164 num_pac_threads,
165 net_log);
168 proxy_service->set_quick_check_enabled(quick_check_enabled);
170 return proxy_service;