This source file includes following definitions.
- CreateProxyConfigService
- CreatePrefProxyConfigTrackerOfProfile
- CreatePrefProxyConfigTrackerOfLocalState
- CreateProxyService
#include "chrome/browser/net/proxy_service_factory.h"
#include "base/command_line.h"
#include "base/strings/string_number_conversions.h"
#include "base/threading/thread.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/io_thread.h"
#include "chrome/browser/net/pref_proxy_config_tracker_impl.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/browser_thread.h"
#include "net/base/net_log.h"
#include "net/proxy/dhcp_proxy_script_fetcher_factory.h"
#include "net/proxy/proxy_config_service.h"
#include "net/proxy/proxy_script_fetcher_impl.h"
#include "net/proxy/proxy_service.h"
#include "net/proxy/proxy_service_v8.h"
#include "net/url_request/url_request_context.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/proxy_config_service_impl.h"
#include "chromeos/network/dhcp_proxy_script_fetcher_chromeos.h"
#endif
#if defined(OS_WIN)
#include "win8/util/win8_util.h"
#endif
using content::BrowserThread;
net::ProxyConfigService* ProxyServiceFactory::CreateProxyConfigService(
PrefProxyConfigTracker* tracker) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
scoped_ptr<net::ProxyConfigService> base_service;
#if !defined(OS_CHROMEOS)
base_service.reset(net::ProxyService::CreateSystemProxyConfigService(
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get(),
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE)));
#endif
return tracker->CreateTrackingProxyConfigService(base_service.Pass())
.release();
}
PrefProxyConfigTracker*
ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile(
PrefService* profile_prefs,
PrefService* local_state_prefs) {
#if defined(OS_CHROMEOS)
return new chromeos::ProxyConfigServiceImpl(profile_prefs, local_state_prefs);
#else
return new PrefProxyConfigTrackerImpl(profile_prefs);
#endif
}
PrefProxyConfigTracker*
ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
PrefService* local_state_prefs) {
#if defined(OS_CHROMEOS)
return new chromeos::ProxyConfigServiceImpl(NULL, local_state_prefs);
#else
return new PrefProxyConfigTrackerImpl(local_state_prefs);
#endif
}
net::ProxyService* ProxyServiceFactory::CreateProxyService(
net::NetLog* net_log,
net::URLRequestContext* context,
net::NetworkDelegate* network_delegate,
net::ProxyConfigService* proxy_config_service,
const CommandLine& command_line,
bool quick_check_enabled) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
#if defined(OS_IOS)
bool use_v8 = false;
#else
bool use_v8 = !command_line.HasSwitch(switches::kWinHttpProxyResolver);
if (use_v8 && command_line.HasSwitch(switches::kSingleProcess)) {
LOG(ERROR) << "Cannot use V8 Proxy resolver in single process mode.";
use_v8 = false;
}
#endif
#if defined(OS_WIN)
if (use_v8 && win8::IsSingleWindowMetroMode())
use_v8 = false;
#endif
size_t num_pac_threads = 0u;
if (command_line.HasSwitch(switches::kNumPacThreads)) {
std::string s = command_line.GetSwitchValueASCII(switches::kNumPacThreads);
int n;
if (base::StringToInt(s, &n) && n > 0) {
num_pac_threads = static_cast<size_t>(n);
} else {
LOG(ERROR) << "Invalid switch for number of PAC threads: " << s;
}
}
net::ProxyService* proxy_service = NULL;
if (use_v8) {
#if defined(OS_IOS)
NOTREACHED();
#else
net::DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher;
#if defined(OS_CHROMEOS)
dhcp_proxy_script_fetcher =
new chromeos::DhcpProxyScriptFetcherChromeos(context);
#else
net::DhcpProxyScriptFetcherFactory dhcp_factory;
dhcp_proxy_script_fetcher = dhcp_factory.Create(context);
#endif
proxy_service = net::CreateProxyServiceUsingV8ProxyResolver(
proxy_config_service,
new net::ProxyScriptFetcherImpl(context),
dhcp_proxy_script_fetcher,
context->host_resolver(),
net_log,
network_delegate);
#endif
} else {
proxy_service = net::ProxyService::CreateUsingSystemProxyResolver(
proxy_config_service,
num_pac_threads,
net_log);
}
proxy_service->set_quick_check_enabled(quick_check_enabled);
return proxy_service;
}