OLD | NEW |
(Empty) | |
| 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_CLOUD_POLICY_CACHE_BASE_H_ |
| 6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_BASE_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/gtest_prod_util.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/observer_list.h" |
| 12 #include "base/threading/non_thread_safe.h" |
| 13 #include "base/time.h" |
| 14 #include "chrome/browser/policy/configuration_policy_provider.h" |
| 15 #include "chrome/browser/policy/policy_map.h" |
| 16 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
| 17 |
| 18 namespace policy { |
| 19 |
| 20 class PolicyMap; |
| 21 |
| 22 namespace em = enterprise_management; |
| 23 |
| 24 // Caches policy information, as set by calls to |SetPolicy()|, persists |
| 25 // it to disk or session_manager (depending on subclass implementation), |
| 26 // and makes it available via policy providers. |
| 27 class CloudPolicyCacheBase : public base::NonThreadSafe { |
| 28 public: |
| 29 // Used to distinguish mandatory from recommended policies. |
| 30 enum PolicyLevel { |
| 31 // Policy is forced upon the user and should always take effect. |
| 32 POLICY_LEVEL_MANDATORY, |
| 33 // The value is just a recommendation that the user may override. |
| 34 POLICY_LEVEL_RECOMMENDED, |
| 35 }; |
| 36 |
| 37 CloudPolicyCacheBase(); |
| 38 virtual ~CloudPolicyCacheBase(); |
| 39 |
| 40 // Loads persisted policy information. |
| 41 virtual void Load() = 0; |
| 42 |
| 43 // Resets the policy information. |
| 44 virtual void SetPolicy(const em::PolicyFetchResponse& policy) = 0; |
| 45 |
| 46 ConfigurationPolicyProvider* GetManagedPolicyProvider(); |
| 47 ConfigurationPolicyProvider* GetRecommendedPolicyProvider(); |
| 48 |
| 49 virtual void SetUnmanaged() = 0; |
| 50 bool is_unmanaged() const { |
| 51 return is_unmanaged_; |
| 52 } |
| 53 |
| 54 // Returns the time at which the policy was last fetched. |
| 55 base::Time last_policy_refresh_time() const { |
| 56 return last_policy_refresh_time_; |
| 57 } |
| 58 |
| 59 protected: |
| 60 // Decodes the given |policy| using |DecodePolicyResponse()|, applies the |
| 61 // contents to |{mandatory,recommended}_policy_|, and notifies observers. |
| 62 // |timestamp| returns the timestamp embedded in |policy|, callers can pass |
| 63 // NULL if they don't care. |check_for_timestamp_validity| tells this method |
| 64 // to discard policy data with a timestamp from the future. |
| 65 // Returns true upon success. |
| 66 bool SetPolicyInternal(const em::PolicyFetchResponse& policy, |
| 67 base::Time* timestamp, |
| 68 bool check_for_timestamp_validity); |
| 69 |
| 70 void SetUnmanagedInternal(const base::Time& timestamp); |
| 71 |
| 72 // Decodes |policy_data|, populating |mandatory| and |recommended| with |
| 73 // the results. |
| 74 virtual bool DecodePolicyData(const em::PolicyData& policy_data, |
| 75 PolicyMap* mandatory, |
| 76 PolicyMap* recommended) = 0; |
| 77 |
| 78 // Decodes a PolicyFetchResponse into two PolicyMaps and a timestamp. |
| 79 // Also performs verification, returns NULL if any check fails. |
| 80 bool DecodePolicyResponse(const em::PolicyFetchResponse& policy_response, |
| 81 PolicyMap* mandatory, |
| 82 PolicyMap* recommended, |
| 83 base::Time* timestamp); |
| 84 |
| 85 // See comment for |initialization_complete_|. |
| 86 bool initialization_complete() { |
| 87 return initialization_complete_; |
| 88 } |
| 89 |
| 90 void set_last_policy_refresh_time(base::Time timestamp) { |
| 91 last_policy_refresh_time_ = timestamp; |
| 92 } |
| 93 |
| 94 private: |
| 95 class CloudPolicyProvider; |
| 96 |
| 97 friend class DevicePolicyCacheTest; |
| 98 friend class UserPolicyCacheTest; |
| 99 |
| 100 // Policy key-value information. |
| 101 PolicyMap mandatory_policy_; |
| 102 PolicyMap recommended_policy_; |
| 103 |
| 104 // Policy providers. |
| 105 scoped_ptr<ConfigurationPolicyProvider> managed_policy_provider_; |
| 106 scoped_ptr<ConfigurationPolicyProvider> recommended_policy_provider_; |
| 107 |
| 108 // The time at which the policy was last refreshed. Is updated both upon |
| 109 // successful and unsuccessful refresh attempts. |
| 110 base::Time last_policy_refresh_time_; |
| 111 |
| 112 // Whether initialization has been completed. This is the case when we have |
| 113 // valid policy, learned that the device is unmanaged or ran into |
| 114 // unrecoverable errors. |
| 115 bool initialization_complete_; |
| 116 |
| 117 // Whether the the server has indicated this device is unmanaged. |
| 118 bool is_unmanaged_; |
| 119 |
| 120 // Provider observers that are registered with this cache's providers. |
| 121 ObserverList<ConfigurationPolicyProvider::Observer, true> observer_list_; |
| 122 |
| 123 DISALLOW_COPY_AND_ASSIGN(CloudPolicyCacheBase); |
| 124 }; |
| 125 |
| 126 } // namespace policy |
| 127 |
| 128 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_BASE_H_ |
OLD | NEW |