Home | History | Annotate | Download | only in policy
      1 // Copyright (c) 2011 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 CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_STORE_INTERFACE_H_
      6 #define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_STORE_INTERFACE_H_
      7 #pragma once
      8 
      9 #include "base/basictypes.h"
     10 #include "base/compiler_specific.h"
     11 #include "policy/configuration_policy_type.h"
     12 
     13 class Value;
     14 
     15 namespace policy {
     16 
     17 // Constants for the "Proxy Server Mode" defined in the policies.
     18 // Note that these diverge from internal presentation defined in
     19 // ProxyPrefs::ProxyMode for legacy reasons. The following four
     20 // PolicyProxyModeType types were not very precise and had overlapping use
     21 // cases.
     22 enum PolicyProxyModeType {
     23   // Disable Proxy, connect directly.
     24   kPolicyNoProxyServerMode = 0,
     25   // Auto detect proxy or use specific PAC script if given.
     26   kPolicyAutoDetectProxyServerMode = 1,
     27   // Use manually configured proxy servers (fixed servers).
     28   kPolicyManuallyConfiguredProxyServerMode = 2,
     29   // Use system proxy server.
     30   kPolicyUseSystemProxyServerMode = 3,
     31 
     32   MODE_COUNT
     33 };
     34 
     35 // An abstract super class for policy stores that provides a method that can be
     36 // called by a |ConfigurationPolicyProvider| to specify a policy.
     37 class ConfigurationPolicyStoreInterface {
     38  public:
     39   virtual ~ConfigurationPolicyStoreInterface() {}
     40 
     41   // A |ConfigurationPolicyProvider| specifies the value of a policy
     42   // setting through a call to |Apply|.  The configuration policy pref
     43   // store takes over the ownership of |value|.
     44   virtual void Apply(ConfigurationPolicyType policy, Value* value) = 0;
     45 
     46  protected:
     47   ConfigurationPolicyStoreInterface() {}
     48 
     49  private:
     50   DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyStoreInterface);
     51 };
     52 
     53 // Helper class. A pass-through ConfigurationPolicyStoreInterface, that observes
     54 // the application of well-known policies.
     55 class ObservingPolicyStoreInterface: public ConfigurationPolicyStoreInterface {
     56  public:
     57   explicit ObservingPolicyStoreInterface(
     58       ConfigurationPolicyStoreInterface* next)
     59       : next_(next),
     60         proxy_policy_applied_(false) {}
     61 
     62   // ConfigurationPolicyStoreInterface methods:
     63   virtual void Apply(ConfigurationPolicyType policy, Value* value) OVERRIDE;
     64 
     65   bool IsProxyPolicyApplied() const {
     66     return proxy_policy_applied_;
     67   }
     68 
     69  private:
     70   ConfigurationPolicyStoreInterface* next_;
     71   bool proxy_policy_applied_;
     72 
     73   DISALLOW_COPY_AND_ASSIGN(ObservingPolicyStoreInterface);
     74 };
     75 
     76 // Helper class. A ConfigurationPolicyStoreInterface that filters out most
     77 // policies, and only applies well-known policies.
     78 class FilteringPolicyStoreInterface: public ConfigurationPolicyStoreInterface {
     79  public:
     80   FilteringPolicyStoreInterface(ConfigurationPolicyStoreInterface* next,
     81                                 bool apply_proxy_policies)
     82       : next_(next),
     83         apply_proxy_policies_(apply_proxy_policies) {}
     84 
     85   // ConfigurationPolicyStoreInterface methods:
     86   virtual void Apply(ConfigurationPolicyType policy, Value* value) OVERRIDE;
     87 
     88  private:
     89   ConfigurationPolicyStoreInterface* next_;
     90   bool apply_proxy_policies_;
     91 
     92   DISALLOW_COPY_AND_ASSIGN(FilteringPolicyStoreInterface);
     93 };
     94 
     95 }  // namespace policy
     96 
     97 #endif  // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_STORE_INTERFACE_H_
     98