• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PREF_STORE_H_
6 #define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PREF_STORE_H_
7 #pragma once
8 
9 #include <set>
10 #include <string>
11 
12 #include "base/basictypes.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/observer_list.h"
15 #include "base/values.h"
16 #include "chrome/browser/policy/configuration_policy_provider.h"
17 #include "chrome/browser/policy/configuration_policy_store_interface.h"
18 #include "chrome/common/pref_store.h"
19 
20 class Profile;
21 
22 namespace policy {
23 
24 class ConfigurationPolicyPrefKeeper;
25 
26 // An implementation of PrefStore that bridges policy settings as read from a
27 // ConfigurationPolicyProvider to preferences.
28 class ConfigurationPolicyPrefStore
29     : public PrefStore,
30       public ConfigurationPolicyProvider::Observer {
31  public:
32   // The ConfigurationPolicyPrefStore does not take ownership of the
33   // passed-in |provider|.
34   explicit ConfigurationPolicyPrefStore(ConfigurationPolicyProvider* provider);
35   virtual ~ConfigurationPolicyPrefStore();
36 
37   // PrefStore methods:
38   virtual void AddObserver(PrefStore::Observer* observer);
39   virtual void RemoveObserver(PrefStore::Observer* observer);
40   virtual bool IsInitializationComplete() const;
41   virtual ReadResult GetValue(const std::string& key,
42                               const Value** result) const;
43 
44   // ConfigurationPolicyProvider::Observer methods:
45   virtual void OnUpdatePolicy();
46   virtual void OnProviderGoingAway();
47 
48   // Creates a ConfigurationPolicyPrefStore that reads managed platform policy.
49   static ConfigurationPolicyPrefStore* CreateManagedPlatformPolicyPrefStore();
50 
51   // Creates a ConfigurationPolicyPrefStore that reads managed cloud policy.
52   static ConfigurationPolicyPrefStore* CreateManagedCloudPolicyPrefStore(
53       Profile* profile);
54 
55   // Creates a ConfigurationPolicyPrefStore that reads recommended platform
56   // policy.
57   static ConfigurationPolicyPrefStore*
58       CreateRecommendedPlatformPolicyPrefStore();
59 
60   // Creates a ConfigurationPolicyPrefStore that reads recommended cloud policy.
61   static ConfigurationPolicyPrefStore* CreateRecommendedCloudPolicyPrefStore(
62       Profile* profile);
63 
64   // Returns the default policy definition list for Chrome.
65   static const ConfigurationPolicyProvider::PolicyDefinitionList*
66       GetChromePolicyDefinitionList();
67 
68  private:
69   // Refreshes policy information, rereading policy from the provider and
70   // sending out change notifications as appropriate.
71   void Refresh();
72 
73   static const ConfigurationPolicyProvider::PolicyDefinitionList
74       kPolicyDefinitionList;
75 
76   // The policy provider from which policy settings are read.
77   ConfigurationPolicyProvider* provider_;
78 
79   // Initialization status as reported by the policy provider the last time we
80   // queried it.
81   bool initialization_complete_;
82 
83   // Current policy preferences.
84   scoped_ptr<ConfigurationPolicyPrefKeeper> policy_keeper_;
85 
86   ObserverList<PrefStore::Observer, true> observers_;
87 
88   ConfigurationPolicyObserverRegistrar registrar_;
89 
90   DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyPrefStore);
91 };
92 
93 }  // namespace policy
94 
95 #endif  // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PREF_STORE_H_
96