| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 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_MANAGED_MODE_POLICY_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_POLICY_MANAGED_MODE_POLICY_PROVIDER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "chrome/browser/policy/configuration_policy_provider.h" |
| 11 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 12 #include "chrome/common/persistent_pref_store.h" |
| 13 |
| 14 class Profile; |
| 15 |
| 16 namespace policy { |
| 17 |
| 18 // This class sets policies that are defined by a local user via "Managed Mode". |
| 19 // It offers methods to set and read policies, and persists them on disk in |
| 20 // JSON format. |
| 21 class ManagedModePolicyProvider |
| 22 : public ProfileKeyedService, |
| 23 public ConfigurationPolicyProvider, |
| 24 public PrefStore::Observer { |
| 25 public: |
| 26 // The dictionary key under which we store the policy dictionary. Public for |
| 27 // testing. |
| 28 static const char kPolicies[]; |
| 29 |
| 30 // Creates a new ManagedModePolicyProvider that caches its policies in a JSON |
| 31 // file inside the profile folder. |
| 32 static ManagedModePolicyProvider* Create(Profile* profile); |
| 33 |
| 34 // Use this constructor to inject a different PrefStore (e.g. for testing). |
| 35 explicit ManagedModePolicyProvider(PersistentPrefStore* store); |
| 36 virtual ~ManagedModePolicyProvider(); |
| 37 |
| 38 // Returns the stored value for a policy with the given |key|, or NULL if no |
| 39 // such policy is defined. |
| 40 const base::Value* GetPolicy(const std::string& key) const; |
| 41 // Sets the policy with the given |key| to a copy of the given |value|. |
| 42 void SetPolicy(const std::string& key, const base::Value* value); |
| 43 |
| 44 // ConfigurationPolicyProvider implementation: |
| 45 virtual void RefreshPolicies() OVERRIDE; |
| 46 virtual bool IsInitializationComplete() const OVERRIDE; |
| 47 |
| 48 // PrefStore::Observer implementation: |
| 49 virtual void OnPrefValueChanged(const std::string& key) OVERRIDE; |
| 50 virtual void OnInitializationCompleted(bool success) OVERRIDE; |
| 51 |
| 52 private: |
| 53 base::DictionaryValue* GetCachedPolicy() const; |
| 54 void UpdatePolicyFromCache(); |
| 55 |
| 56 // Used for persisting policies. Unlike other PrefStores, this one is not |
| 57 // hooked up to the PrefService. |
| 58 scoped_refptr<PersistentPrefStore> store_; |
| 59 }; |
| 60 |
| 61 } // namespace policy |
| 62 |
| 63 #endif // CHROME_BROWSER_POLICY_MANAGED_MODE_POLICY_PROVIDER_H_ |
| OLD | NEW |