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_
|