Chromium Code Reviews| 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_H_ | |
| 6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/file_path.h" | |
| 11 #include "base/gtest_prod_util.h" | |
| 12 #include "base/ref_counted.h" | |
| 13 #include "base/scoped_ptr.h" | |
| 14 #include "base/synchronization/lock.h" | |
| 15 #include "base/time.h" | |
| 16 #include "chrome/browser/policy/configuration_policy_provider.h" | |
| 17 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | |
| 18 #include "policy/configuration_policy_type.h" | |
| 19 | |
| 20 class DictionaryValue; | |
| 21 class ListValue; | |
| 22 class Value; | |
| 23 | |
| 24 using google::protobuf::RepeatedPtrField; | |
| 25 | |
| 26 namespace policy { | |
| 27 | |
| 28 namespace em = enterprise_management; | |
| 29 | |
| 30 // Decodes a CloudPolicySettings object into two maps with mandatory and | |
| 31 // recommended settings, respectively. The implementation is generated code | |
| 32 // in policy/cloud_policy_generated.cc. | |
| 33 void DecodePolicy(const em::CloudPolicySettings& policy, | |
| 34 ConfigurationPolicyProvider::PolicyMapType* mandatory, | |
| 35 ConfigurationPolicyProvider::PolicyMapType* recommended); | |
|
Mattias Nissler (ping if slow)
2011/02/15 10:46:39
Do we need this declaration in the header? I think
Jakob Kummerow
2011/02/15 14:22:00
Done.
Mattias Nissler (ping if slow)
2011/02/15 14:55:19
not done?
| |
| 36 | |
| 37 // Keeps the authoritative copy of cloud policy information as read from the | |
| 38 // persistence file or determined by the policy backend. The cache doesn't talk | |
| 39 // to the service directly, but receives updated policy information through | |
| 40 // SetPolicy() calls, which is then persisted and decoded into the internal | |
| 41 // Value representation chrome uses. | |
| 42 class CloudPolicyCache { | |
| 43 public: | |
| 44 typedef ConfigurationPolicyProvider::PolicyMapType PolicyMapType; | |
| 45 | |
| 46 explicit CloudPolicyCache(const FilePath& backing_file_path); | |
| 47 ~CloudPolicyCache(); | |
| 48 | |
| 49 // Loads policy information from the backing file. Non-existing or erroneous | |
| 50 // cache files are ignored. | |
| 51 void LoadPolicyFromFile(); | |
| 52 | |
| 53 // Resets the policy information. Returns true if the new policy is different | |
| 54 // from the previously stored policy. | |
| 55 bool SetPolicy(const em::CloudPolicyResponse& policy); | |
| 56 bool SetDevicePolicy(const em::DevicePolicyResponse& policy); | |
| 57 | |
| 58 // Gets the policy information. Ownership of the return value is transferred | |
| 59 // to the caller. | |
| 60 DictionaryValue* GetDevicePolicy(); | |
| 61 const PolicyMapType* GetMandatoryPolicy() const; | |
| 62 const PolicyMapType* GetRecommendedPolicy() const; | |
| 63 | |
| 64 void SetUnmanaged(); | |
| 65 bool is_unmanaged() const { | |
| 66 return is_unmanaged_; | |
| 67 } | |
| 68 | |
| 69 // Returns the time at which the policy was last fetched. | |
| 70 base::Time last_policy_refresh_time() const { | |
| 71 return last_policy_refresh_time_; | |
| 72 } | |
| 73 | |
| 74 // Returns true if this cache holds (old-style) device policy that should be | |
| 75 // given preference over (new-style) mandatory/recommended policy. | |
| 76 bool has_device_policy() const { | |
| 77 return has_device_policy_; | |
| 78 } | |
| 79 | |
| 80 private: | |
| 81 friend class CloudPolicyCacheTest; | |
| 82 friend class DeviceManagementPolicyCacheDecodeTest; | |
| 83 | |
| 84 // Decodes a CloudPolicyResponse into two (ConfigurationPolicyType -> Value*) | |
| 85 // maps and a timestamp. Also performs verification, returns NULL if any | |
| 86 // check fails. | |
| 87 static bool DecodePolicyResponse( | |
| 88 const em::CloudPolicyResponse& policy_response, | |
| 89 PolicyMapType* mandatory, | |
| 90 PolicyMapType* recommended, | |
| 91 base::Time* timestamp); | |
| 92 | |
| 93 // Returns true if |certificate_chain| is trusted and a |signature| created | |
| 94 // from it matches |data|. | |
| 95 static bool VerifySignature( | |
| 96 const std::string& signature, | |
| 97 const std::string& data, | |
| 98 const RepeatedPtrField<std::string>& certificate_chain); | |
| 99 | |
| 100 // Returns true if |a| equals |b|. | |
| 101 static bool Equals(const PolicyMapType& a, const PolicyMapType& b); | |
| 102 | |
| 103 | |
| 104 // Decodes an int64 value. Checks whether the passed value fits the numeric | |
| 105 // limits of the value representation. Returns a value (ownership is | |
| 106 // transferred to the caller) on success, NULL on failure. | |
| 107 static Value* DecodeIntegerValue(google::protobuf::int64 value); | |
| 108 | |
| 109 // Decode a GenericValue message to the Value representation used internally. | |
| 110 // Returns NULL if |value| is invalid (i.e. contains no actual value). | |
| 111 static Value* DecodeValue(const em::GenericValue& value); | |
| 112 | |
| 113 // Decodes a policy message and returns it in Value representation. Ownership | |
| 114 // of the returned dictionary is transferred to the caller. | |
| 115 static DictionaryValue* DecodeDevicePolicy( | |
| 116 const em::DevicePolicyResponse& response); | |
| 117 | |
| 118 // The file in which we store a cached version of the policy information. | |
| 119 const FilePath backing_file_path_; | |
| 120 | |
| 121 // Protects both |mandatory_policy_| and |recommended_policy_| as well as | |
| 122 // |device_policy_|. | |
|
Mattias Nissler (ping if slow)
2011/02/15 10:46:39
both ... as well as?
Jakob Kummerow
2011/02/15 14:22:00
(both ... and ...) as well as (...) ;-)
But both |
Mattias Nissler (ping if slow)
2011/02/15 14:55:19
I can see that from a logic formula point of view
| |
| 123 base::Lock lock_; | |
| 124 | |
| 125 // Policy key-value information. | |
| 126 PolicyMapType mandatory_policy_; | |
| 127 PolicyMapType recommended_policy_; | |
| 128 scoped_ptr<DictionaryValue> device_policy_; | |
| 129 | |
| 130 // Tracks whether the store received a SetPolicy() call, which overrides any | |
| 131 // information loaded from the file. | |
| 132 bool fresh_policy_; | |
| 133 | |
| 134 bool is_unmanaged_; | |
| 135 | |
| 136 // Tracks whether the cache currently stores |device_policy_| that should be | |
| 137 // given preference over |mandatory_policy_| and |recommended_policy_|. | |
| 138 bool has_device_policy_; | |
| 139 | |
| 140 // The time at which the policy was last refreshed. | |
| 141 base::Time last_policy_refresh_time_; | |
| 142 }; | |
| 143 | |
| 144 } // namespace policy | |
| 145 | |
| 146 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_H_ | |
| OLD | NEW |