[email protected] | 7672247 | 2012-05-24 08:26:46 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 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 | |
Ayu Ishii | 0c0a16a | 2018-12-19 16:45:03 | [diff] [blame] | 7 | #include <utility> |
| 8 | |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 9 | #include "base/task/post_task.h" |
Min Qin | f924267 | 2018-10-01 22:27:51 | [diff] [blame] | 10 | #include "base/threading/thread_task_runner_handle.h" |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 11 | #include "build/build_config.h" |
Yuta Hijikata | 128e447a | 2020-11-25 03:34:24 | [diff] [blame] | 12 | #include "build/chromeos_buildflags.h" |
abhishek.a21 | 71c61285 | 2015-08-31 10:48:19 | [diff] [blame] | 13 | #include "components/proxy_config/pref_proxy_config_tracker_impl.h" |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 14 | #include "content/public/browser/browser_task_traits.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 15 | #include "content/public/browser/browser_thread.h" |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 16 | #include "net/proxy_resolution/configured_proxy_resolution_service.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 17 | #include "net/proxy_resolution/proxy_config_service.h" |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 18 | |
Yuta Hijikata | 128e447a | 2020-11-25 03:34:24 | [diff] [blame] | 19 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
stevenjb | 100c620 | 2016-10-28 02:28:00 | [diff] [blame] | 20 | #include "chromeos/network/proxy/proxy_config_service_impl.h" |
Yuta Hijikata | 128e447a | 2020-11-25 03:34:24 | [diff] [blame] | 21 | #endif // BUILDFLAG(IS_CHROMEOS_ASH) |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 22 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 23 | using content::BrowserThread; |
| 24 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 25 | // static |
dcheng | 4e7c042 | 2016-04-14 00:59:05 | [diff] [blame] | 26 | std::unique_ptr<net::ProxyConfigService> |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 27 | ProxyServiceFactory::CreateProxyConfigService(PrefProxyConfigTracker* tracker) { |
Tim Brown | c182989 | 2017-12-13 22:04:34 | [diff] [blame] | 28 | // The linux gsettings-based proxy settings getter relies on being initialized |
Min Qin | f924267 | 2018-10-01 22:27:51 | [diff] [blame] | 29 | // 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] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 33 | |
dcheng | 4e7c042 | 2016-04-14 00:59:05 | [diff] [blame] | 34 | std::unique_ptr<net::ProxyConfigService> base_service; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 35 | |
Yuta Hijikata | 128e447a | 2020-11-25 03:34:24 | [diff] [blame] | 36 | #if !BUILDFLAG(IS_CHROMEOS_ASH) |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 37 | // On ChromeOS, base service is NULL; chromeos::ProxyConfigServiceImpl |
| 38 | // determines the effective proxy config to take effect in the network layer, |
[email protected] | 07c674cd | 2012-09-07 20:53:56 | [diff] [blame] | 39 | // be it from prefs or system (which is network shill on chromeos). |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 40 | |
| 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 Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 45 | base_service = |
| 46 | net::ConfiguredProxyResolutionService::CreateSystemProxyConfigService( |
| 47 | base::ThreadTaskRunnerHandle::Get()); |
Yuta Hijikata | 128e447a | 2020-11-25 03:34:24 | [diff] [blame] | 48 | #endif // !BUILDFLAG(IS_CHROMEOS_ASH) |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 49 | |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 50 | return tracker->CreateTrackingProxyConfigService(std::move(base_service)); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 51 | } |
| 52 | |
[email protected] | e2930d090 | 2013-07-17 05:25:42 | [diff] [blame] | 53 | // static |
Ayu Ishii | 0c0a16a | 2018-12-19 16:45:03 | [diff] [blame] | 54 | std::unique_ptr<PrefProxyConfigTracker> |
[email protected] | e2930d090 | 2013-07-17 05:25:42 | [diff] [blame] | 55 | ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile( |
| 56 | PrefService* profile_prefs, |
| 57 | PrefService* local_state_prefs) { |
Yuta Hijikata | 128e447a | 2020-11-25 03:34:24 | [diff] [blame] | 58 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Ayu Ishii | 0c0a16a | 2018-12-19 16:45:03 | [diff] [blame] | 59 | return std::make_unique<chromeos::ProxyConfigServiceImpl>( |
| 60 | profile_prefs, local_state_prefs, nullptr); |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 61 | #else |
Ayu Ishii | 0c0a16a | 2018-12-19 16:45:03 | [diff] [blame] | 62 | return std::make_unique<PrefProxyConfigTrackerImpl>(profile_prefs, nullptr); |
Yuta Hijikata | 128e447a | 2020-11-25 03:34:24 | [diff] [blame] | 63 | #endif // BUILDFLAG(IS_CHROMEOS_ASH) |
[email protected] | e2930d090 | 2013-07-17 05:25:42 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | // static |
Ayu Ishii | 0c0a16a | 2018-12-19 16:45:03 | [diff] [blame] | 67 | std::unique_ptr<PrefProxyConfigTracker> |
[email protected] | e2930d090 | 2013-07-17 05:25:42 | [diff] [blame] | 68 | ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState( |
| 69 | PrefService* local_state_prefs) { |
Yuta Hijikata | 128e447a | 2020-11-25 03:34:24 | [diff] [blame] | 70 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Ayu Ishii | 0c0a16a | 2018-12-19 16:45:03 | [diff] [blame] | 71 | return std::make_unique<chromeos::ProxyConfigServiceImpl>( |
| 72 | nullptr, local_state_prefs, nullptr); |
[email protected] | e2930d090 | 2013-07-17 05:25:42 | [diff] [blame] | 73 | #else |
Ayu Ishii | 0c0a16a | 2018-12-19 16:45:03 | [diff] [blame] | 74 | return std::make_unique<PrefProxyConfigTrackerImpl>(local_state_prefs, |
| 75 | nullptr); |
Yuta Hijikata | 128e447a | 2020-11-25 03:34:24 | [diff] [blame] | 76 | #endif // BUILDFLAG(IS_CHROMEOS_ASH) |
[email protected] | e2930d090 | 2013-07-17 05:25:42 | [diff] [blame] | 77 | } |