1// Copyright 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef COMPONENTS_POLICY_CORE_COMMON_FORWARDING_POLICY_PROVIDER_H_ 6#define COMPONENTS_POLICY_CORE_COMMON_FORWARDING_POLICY_PROVIDER_H_ 7 8#include "base/basictypes.h" 9#include "base/compiler_specific.h" 10#include "components/policy/core/common/configuration_policy_provider.h" 11#include "components/policy/core/common/policy_namespace.h" 12#include "components/policy/policy_export.h" 13 14namespace policy { 15 16// A policy provider that forwards calls to another provider. 17// This provider also tracks the SchemaRegistry, and becomes ready after making 18// sure the delegate provider has refreshed its policies with an updated view 19// of the complete schema. It is expected that the delegate's SchemaRegistry 20// is a CombinedSchemaRegistry tracking the forwarding provider's registry. 21class POLICY_EXPORT ForwardingPolicyProvider 22 : public ConfigurationPolicyProvider, 23 public ConfigurationPolicyProvider::Observer { 24 public: 25 // The |delegate| must outlive this provider. 26 explicit ForwardingPolicyProvider(ConfigurationPolicyProvider* delegate); 27 virtual ~ForwardingPolicyProvider(); 28 29 // ConfigurationPolicyProvider: 30 // 31 // Note that Init() and Shutdown() are not forwarded to the |delegate_|, since 32 // this provider does not own it and its up to the |delegate_|'s owner to 33 // initialize it and shut it down. 34 // 35 // Note also that this provider may have a SchemaRegistry passed in Init() 36 // that doesn't match the |delegate_|'s; therefore OnSchemaRegistryUpdated() 37 // and OnSchemaRegistryReady() are not forwarded either. It is assumed that 38 // the |delegate_|'s SchemaRegistry contains a superset of this provider's 39 // SchemaRegistry though (i.e. it's a CombinedSchemaRegistry that contains 40 // this provider's SchemaRegistry). 41 // 42 // This provider manages its own initialization state for all policy domains 43 // except POLICY_DOMAIN_CHROME, whose status is always queried from the 44 // |delegate_|. RefreshPolicies() calls are also forwarded, since this 45 // provider doesn't have a "real" policy source of its own. 46 virtual void Init(SchemaRegistry* registry) OVERRIDE; 47 virtual bool IsInitializationComplete(PolicyDomain domain) const OVERRIDE; 48 virtual void RefreshPolicies() OVERRIDE; 49 virtual void OnSchemaRegistryReady() OVERRIDE; 50 virtual void OnSchemaRegistryUpdated(bool has_new_schemas) OVERRIDE; 51 52 // ConfigurationPolicyProvider::Observer: 53 virtual void OnUpdatePolicy(ConfigurationPolicyProvider* provider) OVERRIDE; 54 55 private: 56 enum InitializationState { 57 WAITING_FOR_REGISTRY_READY, 58 WAITING_FOR_REFRESH, 59 READY, 60 }; 61 62 ConfigurationPolicyProvider* delegate_; 63 InitializationState state_; 64 65 DISALLOW_COPY_AND_ASSIGN(ForwardingPolicyProvider); 66}; 67 68} // namespace policy 69 70#endif // COMPONENTS_POLICY_CORE_COMMON_FORWARDING_POLICY_PROVIDER_H_ 71