Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: chrome/browser/policy/cloud_policy_cache.h

Issue 6523058: New policy protobuf protocol. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 // Keeps the authoritative copy of cloud policy information as read from the
31 // persistence file or determined by the policy backend. The cache doesn't talk
32 // to the service directly, but receives updated policy information through
33 // SetPolicy() calls, which is then persisted and decoded into the internal
34 // Value representation chrome uses.
35 class CloudPolicyCache {
36 public:
37 typedef ConfigurationPolicyProvider::PolicyMapType PolicyMapType;
38
39 explicit CloudPolicyCache(const FilePath& backing_file_path);
40 ~CloudPolicyCache();
41
42 // Loads policy information from the backing file. Non-existing or erroneous
43 // cache files are ignored.
44 void LoadPolicyFromFile();
45
46 // Resets the policy information. Returns true if the new policy is different
47 // from the previously stored policy.
48 bool SetPolicy(const em::CloudPolicyResponse& policy);
49 bool SetDevicePolicy(const em::DevicePolicyResponse& policy);
50
51 // Gets the policy information. Ownership of the return value is transferred
52 // to the caller.
53 DictionaryValue* GetDevicePolicy();
54 const PolicyMapType* GetMandatoryPolicy() const;
55 const PolicyMapType* GetRecommendedPolicy() const;
56
57 void SetUnmanaged();
58 bool is_unmanaged() const {
59 return is_unmanaged_;
60 }
61
62 // Returns the time at which the policy was last fetched.
63 base::Time last_policy_refresh_time() const {
64 return last_policy_refresh_time_;
65 }
66
67 // Returns true if this cache holds (old-style) device policy that should be
68 // given preference over (new-style) mandatory/recommended policy.
69 bool has_device_policy() const {
70 return has_device_policy_;
71 }
72
73 private:
74 friend class CloudPolicyCacheTest;
75 friend class DeviceManagementPolicyCacheDecodeTest;
76
77 // Decodes a CloudPolicyResponse into two (ConfigurationPolicyType -> Value*)
78 // maps and a timestamp. Also performs verification, returns NULL if any
79 // check fails.
80 static bool DecodePolicyResponse(
81 const em::CloudPolicyResponse& policy_response,
82 PolicyMapType* mandatory,
83 PolicyMapType* recommended,
84 base::Time* timestamp);
85
86 // Returns true if |certificate_chain| is trusted and a |signature| created
87 // from it matches |data|.
88 static bool VerifySignature(
89 const std::string& signature,
90 const std::string& data,
91 const RepeatedPtrField<std::string>& certificate_chain);
92
93 // Returns true if |a| equals |b|.
94 static bool Equals(const PolicyMapType& a, const PolicyMapType& b);
95 // Helper function for the above.
96 static bool MapEntryEquals(const PolicyMapType::value_type& a,
97 const PolicyMapType::value_type& b);
98
99 // Decodes an int64 value. Checks whether the passed value fits the numeric
100 // limits of the value representation. Returns a value (ownership is
101 // transferred to the caller) on success, NULL on failure.
102 static Value* DecodeIntegerValue(google::protobuf::int64 value);
103
104 // Decode a GenericValue message to the Value representation used internally.
105 // Returns NULL if |value| is invalid (i.e. contains no actual value).
106 static Value* DecodeValue(const em::GenericValue& value);
107
108 // Decodes a policy message and returns it in Value representation. Ownership
109 // of the returned dictionary is transferred to the caller.
110 static DictionaryValue* DecodeDevicePolicy(
111 const em::DevicePolicyResponse& response);
112
113 // The file in which we store a cached version of the policy information.
114 const FilePath backing_file_path_;
115
116 // Protects both |mandatory_policy_| and |recommended_policy_| as well as
117 // |device_policy_|.
118 base::Lock lock_;
119
120 // Policy key-value information.
121 PolicyMapType mandatory_policy_;
122 PolicyMapType recommended_policy_;
123 scoped_ptr<DictionaryValue> device_policy_;
124
125 // Tracks whether the store received a SetPolicy() call, which overrides any
126 // information loaded from the file.
127 bool fresh_policy_;
128
129 bool is_unmanaged_;
130
131 // Tracks whether the cache currently stores |device_policy_| that should be
132 // given preference over |mandatory_policy_| and |recommended_policy_|.
133 bool has_device_policy_;
134
135 // The time at which the policy was last refreshed.
136 base::Time last_policy_refresh_time_;
137 };
138
139 } // namespace policy
140
141 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_H_
OLDNEW
« no previous file with comments | « chrome/browser/policy/asynchronous_policy_provider.cc ('k') | chrome/browser/policy/cloud_policy_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698