File: ash_proxy_monitor.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (110 lines) | stat: -rw-r--r-- 3,607 bytes parent folder | download | duplicates (6)
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
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ASH_NET_ASH_PROXY_MONITOR_H_
#define CHROME_BROWSER_ASH_NET_ASH_PROXY_MONITOR_H_

#include <optional>

#include "base/component_export.h"
#include "base/memory/raw_ptr.h"
#include "base/observer_list.h"
#include "base/observer_list_types.h"
#include "base/scoped_observation.h"
#include "chrome/browser/profiles/profile_manager_observer.h"
#include "chromeos/ash/components/network/network_state_handler_observer.h"
#include "components/proxy_config/proxy_config_dictionary.h"
#include "url/gurl.h"

class PrefService;
class PrefChangeRegistrar;
class Profile;
class ProfileManager;

namespace ash {
class NetworkState;
class NetworkStateHandler;
}  // namespace ash

namespace ash {

// Monitors proxy changes coming from policies, extensions and the default
// network, and propagates the proxy configuration to observers. Can only be
// used inside the user session.
// TODO(b/290595436, acostinas) Allow using the AshProxyMonitor at the login
// screen.
class COMPONENT_EXPORT(CHROMEOS_NETWORK) AshProxyMonitor
    : public NetworkStateHandlerObserver,
      public ProfileManagerObserver {
 public:
  struct ExtensionMetadata {
    ExtensionMetadata(const std::string& name,
                      const std::string& id,
                      bool can_be_disabled);
    std::string name;
    std::string id;
    bool can_be_disabled;
  };
  class COMPONENT_EXPORT(CHROMEOS_NETWORK) Observer
      : public base::CheckedObserver {
   public:
    // Called when the effective proxy config changes.
    virtual void OnProxyChanged() = 0;
  };

  AshProxyMonitor(PrefService* local_state, ProfileManager* profile_manager);
  AshProxyMonitor(const AshProxyMonitor&) = delete;
  AshProxyMonitor& operator=(const AshProxyMonitor&) = delete;
  ~AshProxyMonitor() override;

  // Adds an observer. An observer is removed by calling `RemoveObserver`.
  // Multiple observers can be added.
  void AddObserver(Observer* observer);
  void RemoveObserver(Observer* observer);

  void SetProfileForTesting(Profile* profile);

  ProxyConfigDictionary* GetLatestProxyConfig() const;

  GURL GetLatestWpadUrl() const;

 private:
  void NotifyObservers();

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

  // ProfileManagerObserver:
  void OnProfileAdded(Profile* profile) override;
  void OnProfileMarkedForPermanentDeletion(Profile* profile) override;
  void OnProfileManagerDestroying() override;

  // Only sends an update to observers if the effective proxy config has
  // changed.
  void OnProxyChanged(std::optional<GURL> wpad_url);

  // The PAC URL associated with `default_network_name_`, received via the DHCP
  // discovery method.
  std::optional<GURL> cached_wpad_url_ = std::nullopt;
  std::unique_ptr<ProxyConfigDictionary> cached_proxy_config_ = nullptr;

  std::unique_ptr<PrefChangeRegistrar> profile_prefs_registrar_;

  raw_ptr<PrefService> local_state_ = nullptr;
  raw_ptr<ProfileManager> profile_manager_ = nullptr;
  raw_ptr<Profile> primary_profile_ = nullptr;

  base::ObserverList<Observer, /*check_empty=*/true> observers_;

  base::ScopedObservation<NetworkStateHandler, NetworkStateHandlerObserver>
      network_state_handler_observer_{this};

  base::ScopedObservation<ProfileManager, ProfileManagerObserver>
      profile_manager_observation_{this};
};

}  // namespace ash

#endif  // CHROME_BROWSER_ASH_NET_ASH_PROXY_MONITOR_H_