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> | |
| 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 // configuration_policy_type.h is generated. See policy_templates.json for | |
| 20 // policy definitions. | |
| 21 #include "policy/configuration_policy_type.h" | |
| 22 | |
| 23 class DictionaryValue; | |
| 24 class ListValue; | |
| 25 class Value; | |
| 26 | |
| 27 using google::protobuf::RepeatedPtrField; | |
| 28 | |
| 29 namespace policy { | |
| 30 | |
| 31 namespace em = enterprise_management; | |
| 32 | |
| 33 // Decodes a CloudPolicySettings object into two maps with mandatory and | |
| 34 // recommended settings, respectively. The implementation is generated code. | |
| 35 void DecodePolicy(const em::CloudPolicySettings& policy, | |
| 36 PolicyMapType* mandatory, PolicyMapType* recommended); | |
|
gfeher
2011/02/02 08:42:45
Please hide this in an anonymous namespace.
Jakob Kummerow
2011/02/03 14:36:52
Can't. See the comment: the implementation is gene
| |
| 37 | |
| 38 // Keeps the authoritative copy of cloud policy information as read from the | |
| 39 // persistence file or determined by the policy backend. The cache doesn't talk | |
| 40 // to the service directly, but receives updated policy information through | |
| 41 // SetPolicy() calls, which is then persisted and decoded into the internal | |
| 42 // Value representation chrome uses. | |
| 43 class CloudPolicyCache { | |
| 44 public: | |
| 45 explicit CloudPolicyCache(const FilePath& backing_file_path); | |
| 46 ~CloudPolicyCache(); | |
| 47 | |
| 48 // Loads policy information from the backing file. Non-existing or erroneous | |
| 49 // cache files are ignored. | |
| 50 void LoadPolicyFromFile(); | |
| 51 | |
| 52 // Resets the policy information. Returns true if the new policy is different | |
| 53 // from the previously stored policy. | |
| 54 bool SetPolicy(const em::CloudPolicyResponse& policy); | |
| 55 | |
| 56 // Gets the policy information. Ownership of the return value is transferred | |
| 57 // to the caller. | |
|
gfeher
2011/02/02 08:42:45
If I understand correctly, there is no way to get
Jakob Kummerow
2011/02/03 14:36:52
Done.
| |
| 58 PolicyMapType* GetPolicy(); | |
| 59 | |
| 60 void SetUnmanaged(); | |
| 61 bool is_unmanaged() const { | |
| 62 return is_unmanaged_; | |
| 63 } | |
| 64 | |
| 65 // Returns the time as which the policy was last fetched. | |
| 66 base::Time last_policy_refresh_time() const { | |
| 67 return last_policy_refresh_time_; | |
| 68 } | |
| 69 | |
| 70 private: | |
| 71 friend class CloudPolicyCacheTest; | |
| 72 | |
| 73 // Decodes a CloudPolicyResponse into two (ConfigurationPolicyType -> Value*) | |
| 74 // maps and a timestamp. Also performs verification, returns NULL if any | |
| 75 // check fails. | |
| 76 static bool DecodePolicyResponse( | |
| 77 const em::CloudPolicyResponse& policy_response, | |
| 78 PolicyMapType* mandatory, | |
| 79 PolicyMapType* recommended, | |
| 80 base::Time* timestamp); | |
| 81 | |
| 82 // Returns true if |certificate_chain| is trusted and a |signature| created | |
| 83 // from it matches |data|. | |
| 84 static bool VerifySignature( | |
| 85 const std::string& signature, | |
| 86 const std::string& data, | |
| 87 const RepeatedPtrField<std::string>& certificate_chain); | |
| 88 | |
| 89 // Returns true if |a| equals |b|. | |
| 90 static bool Equals(const PolicyMapType* a, const PolicyMapType* b); | |
| 91 | |
| 92 // The file in which we store a cached version of the policy information. | |
| 93 const FilePath backing_file_path_; | |
| 94 | |
| 95 // Protects |policy_|. | |
|
gfeher
2011/02/02 08:42:45
Please update comment.
Jakob Kummerow
2011/02/03 14:36:52
Done.
| |
| 96 base::Lock lock_; | |
| 97 | |
| 98 // Policy key-value information. | |
| 99 scoped_ptr<PolicyMapType> mandatory_policy_; | |
| 100 scoped_ptr<PolicyMapType> recommended_policy_; | |
| 101 | |
| 102 // Tracks whether the store received a SetPolicy() call, which overrides any | |
| 103 // information loaded from the file. | |
| 104 bool fresh_policy_; | |
| 105 | |
| 106 bool is_unmanaged_; | |
| 107 | |
| 108 // The time at which the policy was last refreshed. | |
| 109 base::Time last_policy_refresh_time_; | |
| 110 }; | |
| 111 | |
| 112 } // namespace policy | |
| 113 | |
| 114 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_H_ | |
| OLD | NEW |