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 <map> | |
|
Mattias Nissler (ping if slow)
2011/02/03 16:23:41
do you need this?
Jakob Kummerow
2011/02/08 16:15:43
No, I don't. Done.
| |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/file_path.h" | |
| 12 #include "base/gtest_prod_util.h" | |
| 13 #include "base/ref_counted.h" | |
| 14 #include "base/scoped_ptr.h" | |
| 15 #include "base/synchronization/lock.h" | |
| 16 #include "base/time.h" | |
| 17 #include "chrome/browser/policy/configuration_policy_provider.h" | |
| 18 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | |
| 19 #include "policy/configuration_policy_type.h" | |
| 20 | |
| 21 class DictionaryValue; | |
| 22 class ListValue; | |
| 23 class Value; | |
| 24 | |
| 25 using google::protobuf::RepeatedPtrField; | |
| 26 | |
| 27 namespace policy { | |
| 28 | |
| 29 namespace em = enterprise_management; | |
| 30 | |
| 31 // Decodes a CloudPolicySettings object into two maps with mandatory and | |
| 32 // recommended settings, respectively. The implementation is generated code. | |
|
Mattias Nissler (ping if slow)
2011/02/03 16:23:41
maybe also add the file name to look at?
Jakob Kummerow
2011/02/08 16:15:43
Done.
| |
| 33 void DecodePolicy(const em::CloudPolicySettings& policy, | |
| 34 ConfigurationPolicyProvider::PolicyMapType* mandatory, | |
| 35 ConfigurationPolicyProvider::PolicyMapType* recommended); | |
| 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 explicit CloudPolicyCache(const FilePath& backing_file_path); | |
| 45 ~CloudPolicyCache(); | |
| 46 | |
| 47 // Loads policy information from the backing file. Non-existing or erroneous | |
| 48 // cache files are ignored. | |
| 49 void LoadPolicyFromFile(); | |
| 50 | |
| 51 // Resets the policy information. Returns true if the new policy is different | |
| 52 // from the previously stored policy. | |
| 53 bool SetPolicy(const em::CloudPolicyResponse& policy); | |
| 54 bool SetPolicy(const em::DevicePolicyResponse& policy); | |
|
Mattias Nissler (ping if slow)
2011/02/03 16:23:41
we generally discourage overloads (see the style g
Jakob Kummerow
2011/02/08 16:15:43
Done.
| |
| 55 | |
| 56 // Gets the policy information. Ownership of the return value is transferred | |
| 57 // to the caller. | |
| 58 DictionaryValue* GetDevicePolicy(); | |
|
Mattias Nissler (ping if slow)
2011/02/03 16:23:41
Why do we still need this?
Jakob Kummerow
2011/02/08 16:15:43
Because for the time being, DMServer only gives us
| |
| 59 ConfigurationPolicyProvider::PolicyMapType* GetMandatoryPolicy(); | |
| 60 ConfigurationPolicyProvider::PolicyMapType* GetRecommendedPolicy(); | |
| 61 | |
| 62 void SetUnmanaged(); | |
| 63 bool is_unmanaged() const { | |
| 64 return is_unmanaged_; | |
| 65 } | |
| 66 | |
| 67 // Returns the time as which the policy was last fetched. | |
| 68 base::Time last_policy_refresh_time() const { | |
| 69 return last_policy_refresh_time_; | |
| 70 } | |
| 71 | |
| 72 // Returns true if this cache holds (old-style) device policy that should be | |
| 73 // given preference over (new-style) mandatory/recommended policy. | |
| 74 bool has_device_policy() const { | |
|
Mattias Nissler (ping if slow)
2011/02/03 16:23:41
Why would we need this? Can't the provider just as
Jakob Kummerow
2011/02/08 16:15:43
Currently no policy ever returns null; it'll just
| |
| 75 return has_device_policy_; | |
| 76 } | |
| 77 | |
| 78 private: | |
| 79 friend class CloudPolicyCacheTest; | |
| 80 friend class DeviceManagementPolicyCacheDecodeTest; | |
| 81 | |
| 82 // Decodes a CloudPolicyResponse into two (ConfigurationPolicyType -> Value*) | |
| 83 // maps and a timestamp. Also performs verification, returns NULL if any | |
| 84 // check fails. | |
| 85 static bool DecodePolicyResponse( | |
| 86 const em::CloudPolicyResponse& policy_response, | |
| 87 ConfigurationPolicyProvider::PolicyMapType* mandatory, | |
| 88 ConfigurationPolicyProvider::PolicyMapType* recommended, | |
| 89 base::Time* timestamp); | |
| 90 | |
| 91 // Returns true if |certificate_chain| is trusted and a |signature| created | |
| 92 // from it matches |data|. | |
| 93 static bool VerifySignature( | |
| 94 const std::string& signature, | |
| 95 const std::string& data, | |
| 96 const RepeatedPtrField<std::string>& certificate_chain); | |
| 97 | |
| 98 // Returns true if |a| equals |b|. | |
| 99 static bool Equals(const ConfigurationPolicyProvider::PolicyMapType* a, | |
| 100 const ConfigurationPolicyProvider::PolicyMapType* b); | |
|
Mattias Nissler (ping if slow)
2011/02/03 16:23:41
can you use std::equal from <algorithm> instead?
Jakob Kummerow
2011/02/08 16:15:43
No, because I need Value::Equals(). |operator=| is
| |
| 101 | |
| 102 // Returns a copy of the |original| PolicyMapType. Caller takes ownership. | |
| 103 ConfigurationPolicyProvider::PolicyMapType* CopyPolicyMap( | |
| 104 const ConfigurationPolicyProvider::PolicyMapType* original); | |
|
Mattias Nissler (ping if slow)
2011/02/03 16:23:41
also looks like std::copy could help here.
Jakob Kummerow
2011/02/08 16:15:43
No, because Value::DeepCopy() was needed. However,
| |
| 105 | |
| 106 // Decodes an int64 value. Checks whether the passed value fits the numeric | |
| 107 // limits of the value representation. Returns a value (ownership is | |
| 108 // transferred to the caller) on success, NULL on failure. | |
| 109 static Value* DecodeIntegerValue(google::protobuf::int64 value); | |
| 110 | |
| 111 // Decode a GenericValue message to the Value representation used internally. | |
| 112 // Returns NULL if |value| is invalid (i.e. contains no actual value). | |
| 113 static Value* DecodeValue(const em::GenericValue& value); | |
| 114 | |
| 115 // Decodes a policy message and returns it in Value representation. Ownership | |
| 116 // of the returned dictionary is transferred to the caller. | |
| 117 static DictionaryValue* DecodeDevicePolicy( | |
| 118 const em::DevicePolicyResponse& response); | |
| 119 | |
| 120 // The file in which we store a cached version of the policy information. | |
| 121 const FilePath backing_file_path_; | |
| 122 | |
| 123 // Protects both |mandatory_policy_| and |recommended_policy_| as well as | |
| 124 // |device_policy_|. | |
| 125 base::Lock lock_; | |
|
Mattias Nissler (ping if slow)
2011/02/03 16:23:41
do we still need locking here?
Jakob Kummerow
2011/02/08 16:15:43
I guess we don't (would need to take a closer look
| |
| 126 | |
| 127 // Policy key-value information. | |
| 128 scoped_ptr<ConfigurationPolicyProvider::PolicyMapType> mandatory_policy_; | |
| 129 scoped_ptr<ConfigurationPolicyProvider::PolicyMapType> recommended_policy_; | |
| 130 scoped_ptr<DictionaryValue> device_policy_; | |
|
Mattias Nissler (ping if slow)
2011/02/03 16:23:41
why is this still needed?
Jakob Kummerow
2011/02/08 16:15:43
To store old-style policy until support for that i
| |
| 131 | |
| 132 // Tracks whether the store received a SetPolicy() call, which overrides any | |
| 133 // information loaded from the file. | |
| 134 bool fresh_policy_; | |
| 135 | |
| 136 bool is_unmanaged_; | |
| 137 | |
| 138 // Tracks whether the cache currently stores |device_policy_| that should be | |
| 139 // given preference over |mandatory_policy_| and |recommended_policy_|. | |
| 140 bool has_device_policy_; | |
| 141 | |
| 142 // The time at which the policy was last refreshed. | |
| 143 base::Time last_policy_refresh_time_; | |
| 144 }; | |
| 145 | |
| 146 } // namespace policy | |
| 147 | |
| 148 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_H_ | |
| OLD | NEW |