blob: 9f6edc517dc9b41cefc79a81f9bfaeaefc9f4e38 [file] [log] [blame]
[email protected]76722472012-05-24 08:26:461// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]db0e86dd2011-03-16 14:47:212// 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
Ayu Ishii0c0a16a2018-12-19 16:45:037#include <utility>
8
Eric Seckler8652dcd52018-09-20 10:42:289#include "base/task/post_task.h"
Min Qinf9242672018-10-01 22:27:5110#include "base/threading/thread_task_runner_handle.h"
avi6846aef2015-12-26 01:09:3811#include "build/build_config.h"
Yuta Hijikata128e447a2020-11-25 03:34:2412#include "build/chromeos_buildflags.h"
abhishek.a2171c612852015-08-31 10:48:1913#include "components/proxy_config/pref_proxy_config_tracker_impl.h"
Eric Seckler8652dcd52018-09-20 10:42:2814#include "content/public/browser/browser_task_traits.h"
[email protected]c38831a12011-10-28 12:44:4915#include "content/public/browser/browser_thread.h"
Nicolas Arciniegad2013f92020-02-07 23:00:5616#include "net/proxy_resolution/configured_proxy_resolution_service.h"
Lily Houghton582d4622018-01-22 22:43:4017#include "net/proxy_resolution/proxy_config_service.h"
[email protected]db0e86dd2011-03-16 14:47:2118
Yuta Hijikata128e447a2020-11-25 03:34:2419#if BUILDFLAG(IS_CHROMEOS_ASH)
stevenjb100c6202016-10-28 02:28:0020#include "chromeos/network/proxy/proxy_config_service_impl.h"
Yuta Hijikata128e447a2020-11-25 03:34:2421#endif // BUILDFLAG(IS_CHROMEOS_ASH)
[email protected]db0e86dd2011-03-16 14:47:2122
[email protected]631bb742011-11-02 11:29:3923using content::BrowserThread;
24
[email protected]db0e86dd2011-03-16 14:47:2125// static
dcheng4e7c0422016-04-14 00:59:0526std::unique_ptr<net::ProxyConfigService>
csharrisonb7e3a082015-09-22 19:13:0427ProxyServiceFactory::CreateProxyConfigService(PrefProxyConfigTracker* tracker) {
Tim Brownc1829892017-12-13 22:04:3428 // The linux gsettings-based proxy settings getter relies on being initialized
Min Qinf9242672018-10-01 22:27:5129 // from the UI thread. The system proxy config service could also get created
30 // without full browser process by launching service manager alone.
31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
32 !BrowserThread::IsThreadInitialized(BrowserThread::UI));
[email protected]db0e86dd2011-03-16 14:47:2133
dcheng4e7c0422016-04-14 00:59:0534 std::unique_ptr<net::ProxyConfigService> base_service;
[email protected]db0e86dd2011-03-16 14:47:2135
Yuta Hijikata128e447a2020-11-25 03:34:2436#if !BUILDFLAG(IS_CHROMEOS_ASH)
[email protected]6f96cbcb2011-11-04 02:26:0737 // On ChromeOS, base service is NULL; chromeos::ProxyConfigServiceImpl
38 // determines the effective proxy config to take effect in the network layer,
[email protected]07c674cd2012-09-07 20:53:5639 // be it from prefs or system (which is network shill on chromeos).
[email protected]6f96cbcb2011-11-04 02:26:0740
41 // For other platforms, create a baseline service that provides proxy
42 // configuration in case nothing is configured through prefs (Note: prefs
43 // include command line and configuration policy).
44
Nicolas Arciniegad2013f92020-02-07 23:00:5645 base_service =
46 net::ConfiguredProxyResolutionService::CreateSystemProxyConfigService(
47 base::ThreadTaskRunnerHandle::Get());
Yuta Hijikata128e447a2020-11-25 03:34:2448#endif // !BUILDFLAG(IS_CHROMEOS_ASH)
[email protected]db0e86dd2011-03-16 14:47:2149
dchenge73d8520c2015-12-27 01:19:0950 return tracker->CreateTrackingProxyConfigService(std::move(base_service));
[email protected]db0e86dd2011-03-16 14:47:2151}
52
[email protected]e2930d0902013-07-17 05:25:4253// static
Ayu Ishii0c0a16a2018-12-19 16:45:0354std::unique_ptr<PrefProxyConfigTracker>
[email protected]e2930d0902013-07-17 05:25:4255ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile(
56 PrefService* profile_prefs,
57 PrefService* local_state_prefs) {
Yuta Hijikata128e447a2020-11-25 03:34:2458#if BUILDFLAG(IS_CHROMEOS_ASH)
Ayu Ishii0c0a16a2018-12-19 16:45:0359 return std::make_unique<chromeos::ProxyConfigServiceImpl>(
60 profile_prefs, local_state_prefs, nullptr);
[email protected]6f96cbcb2011-11-04 02:26:0761#else
Ayu Ishii0c0a16a2018-12-19 16:45:0362 return std::make_unique<PrefProxyConfigTrackerImpl>(profile_prefs, nullptr);
Yuta Hijikata128e447a2020-11-25 03:34:2463#endif // BUILDFLAG(IS_CHROMEOS_ASH)
[email protected]e2930d0902013-07-17 05:25:4264}
65
66// static
Ayu Ishii0c0a16a2018-12-19 16:45:0367std::unique_ptr<PrefProxyConfigTracker>
[email protected]e2930d0902013-07-17 05:25:4268ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
69 PrefService* local_state_prefs) {
Yuta Hijikata128e447a2020-11-25 03:34:2470#if BUILDFLAG(IS_CHROMEOS_ASH)
Ayu Ishii0c0a16a2018-12-19 16:45:0371 return std::make_unique<chromeos::ProxyConfigServiceImpl>(
72 nullptr, local_state_prefs, nullptr);
[email protected]e2930d0902013-07-17 05:25:4273#else
Ayu Ishii0c0a16a2018-12-19 16:45:0374 return std::make_unique<PrefProxyConfigTrackerImpl>(local_state_prefs,
75 nullptr);
Yuta Hijikata128e447a2020-11-25 03:34:2476#endif // BUILDFLAG(IS_CHROMEOS_ASH)
[email protected]e2930d0902013-07-17 05:25:4277}