File: configuration_policy_provider.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 (125 lines) | stat: -rw-r--r-- 5,124 bytes parent folder | download | duplicates (9)
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
116
117
118
119
120
121
122
123
124
125
// Copyright 2013 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_CONFIGURATION_POLICY_PROVIDER_H_
#define COMPONENTS_POLICY_CORE_COMMON_CONFIGURATION_POLICY_PROVIDER_H_

#include "base/memory/raw_ptr.h"
#include "base/observer_list.h"
#include "build/build_config.h"
#include "components/policy/core/common/policy_bundle.h"
#include "components/policy/core/common/policy_namespace.h"
#include "components/policy/core/common/schema_registry.h"
#include "components/policy/policy_export.h"

namespace policy {

enum class PolicyFetchReason;

// A mostly-abstract super class for platform-specific policy providers.
// Platform-specific policy providers (Windows Group Policy, gconf,
// etc.) should implement a subclass of this class.
class POLICY_EXPORT ConfigurationPolicyProvider
    : public SchemaRegistry::Observer {
 public:
  class POLICY_EXPORT Observer {
   public:
    virtual ~Observer();
    virtual void OnUpdatePolicy(ConfigurationPolicyProvider* provider) = 0;
  };

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

  // Policy providers can be deleted quite late during shutdown of the browser,
  // and it's not guaranteed that the message loops will still be running when
  // this is invoked. Override Shutdown() instead for cleanup code that needs
  // to post to the FILE thread, for example.
  ~ConfigurationPolicyProvider() override;

  // Invoked as soon as the main message loops are spinning. Policy providers
  // are created early during startup to provide the initial policies; the
  // Init() call allows them to perform initialization tasks that require
  // running message loops.
  // The policy provider will load policy for the components registered in
  // the |schema_registry| whose domain is supported by this provider.
  virtual void Init(SchemaRegistry* registry);

  // Must be invoked before deleting the provider. Implementations can override
  // this method to do appropriate cleanup while threads are still running, and
  // must also invoke ConfigurationPolicyProvider::Shutdown().
  // The provider should keep providing the current policies after Shutdown()
  // is invoked, it only has to stop updating.
  virtual void Shutdown();

  // Returns the current PolicyBundle.
  const PolicyBundle& policies() const { return policy_bundle_; }

  // Check whether this provider has completed initialization for the given
  // policy |domain|. This is used to detect whether initialization is done in
  // case implementations need to do asynchronous operations for initialization.
  virtual bool IsInitializationComplete(PolicyDomain domain) const;

  // Check whether this provider has loaded its first policies for the given
  // policy |domain|. This is used to detect whether policies have been loaded
  // is done in case implementations need to do asynchronous operations to get
  // the policies.
  virtual bool IsFirstPolicyLoadComplete(PolicyDomain domain) const;

  // Asks the provider to refresh its policies. All the updates caused by this
  // call will be visible on the next call of OnUpdatePolicy on the observers,
  // which are guaranteed to happen even if the refresh fails.
  // It is possible that Shutdown() is called first though, and
  // OnUpdatePolicy won't be called if that happens.
  //
  // The |reason| parameter can be used to tag the request to DMServer.
  // Providers that do not communicate with DMServer may ignore the parameter.
  virtual void RefreshPolicies(PolicyFetchReason reason) = 0;

  // Observers must detach themselves before the provider is deleted.
  virtual void AddObserver(Observer* observer);
  virtual void RemoveObserver(Observer* observer);

  // SchemaRegistry::Observer:
  void OnSchemaRegistryUpdated(bool has_new_schemas) override;
  void OnSchemaRegistryReady() override;

#if BUILDFLAG(IS_ANDROID)
  void ShutdownForTesting();
#endif  // BUILDFLAG(IS_ANDROID)

  bool is_active() const { return is_active_; }

  void set_active(bool active) { is_active_ = active; }

 protected:
  // Subclasses must invoke this to update the policies currently served by
  // this provider. UpdatePolicy() takes ownership of |policies|.
  // The observers are notified after the policies are updated.
  void UpdatePolicy(PolicyBundle bundle);

  SchemaRegistry* schema_registry() const;

  const scoped_refptr<SchemaMap>& schema_map() const;

 private:
  // The policies currently configured at this provider.
  PolicyBundle policy_bundle_;

  // Used to validate proper Init() and Shutdown() nesting. This flag is set by
  // Init() and cleared by Shutdown() and needs to be false in the destructor.
  bool initialized_;

  raw_ptr<SchemaRegistry> schema_registry_;

  bool is_active_ = true;

  base::ObserverList<Observer, true>::Unchecked observer_list_;
};

}  // namespace policy

#endif  // COMPONENTS_POLICY_CORE_COMMON_CONFIGURATION_POLICY_PROVIDER_H_