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
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_POLICY_CORE_COMMON_PROXY_POLICY_PROVIDER_H_
#define COMPONENTS_POLICY_CORE_COMMON_PROXY_POLICY_PROVIDER_H_
#include <memory>
#include <variant>
#include "base/memory/raw_ptr.h"
#include "components/policy/core/common/configuration_policy_provider.h"
#include "components/policy/policy_export.h"
namespace policy {
// A policy provider implementation that acts as a proxy for another policy
// provider, swappable at any point.
//
// Note that ProxyPolicyProvider correctly forwards RefreshPolicies() calls to
// the delegate if present. If there is no delegate, the refresh results in an
// immediate (empty) policy update.
//
// Furthermore, IsInitializationComplete() is implemented trivially - it always
// returns true. Given that the delegate may be swapped at any point, there's no
// point in trying to carry over initialization status from the delegate.
//
// This policy provider implementation is used to inject browser-global policy
// originating from the user policy configured on the primary Chrome OS user
// (i.e. the user logging in from the login screen). This way, policy settings
// on the primary user propagate into g_browser_process->local_state_().
//
// The bizarre situation of user-scoped policy settings which are implemented
// browser-global wouldn't exist in an ideal world. However, for historic
// and technical reasons there are policy settings that are scoped to the user
// but are implemented to take effect for the entire browser instance. A good
// example for this are policies that affect the Chrome network stack in areas
// where there's no profile-specific context. The meta data in
// policy_templates.json allows to identify the policies in this bucket; they'll
// have per_profile set to False, supported_on including chrome_os, and
// dynamic_refresh set to True.
class POLICY_EXPORT ProxyPolicyProvider
: public ConfigurationPolicyProvider,
public ConfigurationPolicyProvider::Observer {
public:
using OwnedDelegate = std::unique_ptr<ConfigurationPolicyProvider>;
using UnownedDelegate = raw_ptr<ConfigurationPolicyProvider>;
ProxyPolicyProvider();
ProxyPolicyProvider(const ProxyPolicyProvider&) = delete;
ProxyPolicyProvider& operator=(const ProxyPolicyProvider&) = delete;
~ProxyPolicyProvider() override;
// Updates the provider this proxy delegates to.
void SetOwnedDelegate(OwnedDelegate delegate);
void SetUnownedDelegate(UnownedDelegate delegate);
// ConfigurationPolicyProvider:
void Shutdown() override;
void RefreshPolicies(PolicyFetchReason reason) override;
bool IsFirstPolicyLoadComplete(PolicyDomain domain) const override;
// ConfigurationPolicyProvider::Observer:
void OnUpdatePolicy(ConfigurationPolicyProvider* provider) override;
// When set to true, this ProxyPolicyProvider will ignore subsequent policy
// updates.
void SetBlockPolicyUpdatesForTesting(bool block_policy_updates_for_testing) {
block_policy_updates_for_testing_ = block_policy_updates_for_testing;
}
private:
ConfigurationPolicyProvider* delegate();
const ConfigurationPolicyProvider* delegate() const;
void ResetDelegate();
void OnDelegateChanged();
std::variant<UnownedDelegate, OwnedDelegate> delegate_ =
UnownedDelegate(nullptr);
bool block_policy_updates_for_testing_ = false;
};
} // namespace policy
#endif // COMPONENTS_POLICY_CORE_COMMON_PROXY_POLICY_PROVIDER_H_
|