File: proxy_config_service_impl.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (115 lines) | stat: -rw-r--r-- 4,799 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_ASH_COMPONENTS_NETWORK_PROXY_PROXY_CONFIG_SERVICE_IMPL_H_
#define CHROMEOS_ASH_COMPONENTS_NETWORK_PROXY_PROXY_CONFIG_SERVICE_IMPL_H_

#include <string>

#include "base/component_export.h"
#include "base/memory/raw_ptr.h"
#include "base/task/single_thread_task_runner.h"
#include "chromeos/ash/components/network/network_state_handler_observer.h"
#include "components/onc/onc_constants.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/proxy_config/pref_proxy_config_tracker_impl.h"

namespace ash {

class NetworkState;
class NetworkStateHandler;

// Implementation of proxy config service for chromeos that:
// - extends PrefProxyConfigTrackerImpl (and so lives and runs entirely on UI
//   thread) to handle proxy from prefs (via PrefProxyConfigTrackerImpl) and
//   system i.e. network (via shill notifications)
// - exists one per profile and one per local state
// - persists proxy setting per network in flimflim
// - provides network stack with latest effective proxy configuration for
//   currently active network via PrefProxyConfigTrackerImpl's mechanism of
//   pushing config to ChromeProxyConfigService
class COMPONENT_EXPORT(CHROMEOS_NETWORK) ProxyConfigServiceImpl
    : public PrefProxyConfigTrackerImpl,
      public NetworkStateHandlerObserver {
 public:
  // ProxyConfigServiceImpl is created in ProxyServiceFactory::
  // CreatePrefProxyConfigTrackerImpl via Profile::GetProxyConfigTracker() for
  // profile or via IOThread constructor for local state and is owned by the
  // respective classes.
  //
  // The user's proxy config, proxy policies and proxy from prefs, are used to
  // determine the effective proxy config, which is then pushed through
  // PrefProxyConfigTrackerImpl to ChromeProxyConfigService to the
  // network stack.
  //
  // |profile_prefs| can be NULL if this object should only track prefs from
  // local state (e.g., for system request context or sigin-in screen).
  ProxyConfigServiceImpl(
      PrefService* profile_prefs,
      PrefService* local_state_prefs,
      scoped_refptr<base::SingleThreadTaskRunner> io_task_runner);

  ProxyConfigServiceImpl(const ProxyConfigServiceImpl&) = delete;
  ProxyConfigServiceImpl& operator=(const ProxyConfigServiceImpl&) = delete;

  ~ProxyConfigServiceImpl() override;

  // PrefProxyConfigTrackerImpl implementation.
  void OnProxyConfigChanged(
      ProxyPrefs::ConfigState config_state,
      const net::ProxyConfigWithAnnotation& config) override;

  // NetworkStateHandlerObserver implementation.
  void DefaultNetworkChanged(const NetworkState* network) override;
  void OnShuttingDown() override;

  // Returns true if proxy is to be ignored for this network profile and
  // |onc_source|, e.g. this happens if the network is shared and
  // use-shared-proxies is turned off. |profile_prefs| may be NULL.
  static bool IgnoreProxy(const PrefService* profile_prefs,
                          const std::string network_profile_path,
                          ::onc::ONCSource onc_source);

  // Returns Pref Proxy configuration if available or a proxy config dictionary
  // applied to the default network.
  // Returns null if no Pref Proxy configuration and no active network.
  // |profile_prefs| and |local_state_prefs| must be not null.
  static std::unique_ptr<ProxyConfigDictionary> GetActiveProxyConfigDictionary(
      const PrefService* profile_prefs,
      const PrefService* local_state_prefs);

 private:
  friend class ProxyConfigServiceImplTest;

  // Called when any proxy preference changes.
  void OnProxyPrefChanged();

  // Determines effective proxy config based on prefs from config tracker, the
  // current default network and if user is using shared proxies.  The effective
  // config is stored in |active_config_| and activated on network stack, and
  // hence, picked up by observers.
  void DetermineEffectiveConfigFromDefaultNetwork();

  // Track changes in profile preferences: UseSharedProxies and
  // OpenNetworkConfiguration.
  PrefChangeRegistrar profile_pref_registrar_;

  // Track changes in local state preferences: DeviceOpenNetworkConfiguration.
  PrefChangeRegistrar local_state_pref_registrar_;

  // Not owned. NULL if tracking only local state prefs (e.g. in the system
  // request context or sign-in screen).
  raw_ptr<PrefService> profile_prefs_;

  // Not owned.
  raw_ptr<PrefService> local_state_prefs_;

  NetworkStateHandlerScopedObservation network_state_handler_observer_{this};

  base::WeakPtrFactory<ProxyConfigServiceImpl> pointer_factory_{this};
};

}  // namespace ash

#endif  // CHROMEOS_ASH_COMPONENTS_NETWORK_PROXY_PROXY_CONFIG_SERVICE_IMPL_H_