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

Side by Side Diff: chrome/browser/policy/user_policy_cache.cc

Issue 9111022: Removed ConfigurationPolicyType and extended PolicyMap. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 11 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/policy/user_policy_cache.h" 5 #include "chrome/browser/policy/user_policy_cache.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "chrome/browser/policy/enterprise_metrics.h" 14 #include "chrome/browser/policy/enterprise_metrics.h"
15 #include "chrome/browser/policy/policy_map.h" 15 #include "chrome/browser/policy/policy_map.h"
16 #include "chrome/browser/policy/proto/cloud_policy.pb.h" 16 #include "chrome/browser/policy/proto/cloud_policy.pb.h"
17 #include "chrome/browser/policy/proto/device_management_local.pb.h" 17 #include "chrome/browser/policy/proto/device_management_local.pb.h"
18 #include "chrome/browser/policy/proto/old_generic_format.pb.h" 18 #include "chrome/browser/policy/proto/old_generic_format.pb.h"
19 #include "policy/configuration_policy_type.h"
20 #include "policy/policy_constants.h" 19 #include "policy/policy_constants.h"
21 20
22 namespace em = enterprise_management; 21 namespace em = enterprise_management;
23 22
24 namespace policy { 23 namespace policy {
25 24
26 // Decodes a CloudPolicySettings object into two maps with mandatory and 25 // Decodes a CloudPolicySettings object into a PolicyMap. All the policies will
27 // recommended settings, respectively. The implementation is generated code 26 // be POLICY_SCOPE_USER. The PolicyLevel is decoded from the protobuf.
28 // in policy/cloud_policy_generated.cc. 27 // The implementation is generated code in policy/cloud_policy_generated.cc.
29 void DecodePolicy(const em::CloudPolicySettings& policy, 28 void DecodePolicy(const em::CloudPolicySettings& policy, PolicyMap* map);
30 PolicyMap* mandatory, PolicyMap* recommended);
31 29
32 UserPolicyCache::UserPolicyCache(const FilePath& backing_file_path, 30 UserPolicyCache::UserPolicyCache(const FilePath& backing_file_path,
33 bool wait_for_policy_fetch) 31 bool wait_for_policy_fetch)
34 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), 32 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
35 disk_cache_ready_(false), 33 disk_cache_ready_(false),
36 fetch_ready_(!wait_for_policy_fetch) { 34 fetch_ready_(!wait_for_policy_fetch) {
37 disk_cache_ = new UserPolicyDiskCache(weak_ptr_factory_.GetWeakPtr(), 35 disk_cache_ = new UserPolicyDiskCache(weak_ptr_factory_.GetWeakPtr(),
38 backing_file_path); 36 backing_file_path);
39 } 37 }
40 38
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 set_last_policy_refresh_time(timestamp); 97 set_last_policy_refresh_time(timestamp);
100 } 98 }
101 } 99 }
102 100
103 // Ready to feed policy up the chain! 101 // Ready to feed policy up the chain!
104 disk_cache_ready_ = true; 102 disk_cache_ready_ = true;
105 CheckIfReady(); 103 CheckIfReady();
106 } 104 }
107 105
108 bool UserPolicyCache::DecodePolicyData(const em::PolicyData& policy_data, 106 bool UserPolicyCache::DecodePolicyData(const em::PolicyData& policy_data,
109 PolicyMap* mandatory, 107 PolicyMap* policies) {
110 PolicyMap* recommended) {
111 // TODO(jkummerow): Verify policy_data.device_token(). Needs final 108 // TODO(jkummerow): Verify policy_data.device_token(). Needs final
112 // specification which token we're actually sending / expecting to get back. 109 // specification which token we're actually sending / expecting to get back.
113 em::CloudPolicySettings policy; 110 em::CloudPolicySettings policy;
114 if (!policy.ParseFromString(policy_data.policy_value())) { 111 if (!policy.ParseFromString(policy_data.policy_value())) {
115 LOG(WARNING) << "Failed to parse CloudPolicySettings protobuf."; 112 LOG(WARNING) << "Failed to parse CloudPolicySettings protobuf.";
116 return false; 113 return false;
117 } 114 }
118 DecodePolicy(policy, mandatory, recommended); 115 DecodePolicy(policy, policies);
119 MaybeDecodeOldstylePolicy(policy_data.policy_value(), mandatory, recommended); 116 MaybeDecodeOldstylePolicy(policy_data.policy_value(), policies);
120 return true; 117 return true;
121 } 118 }
122 119
123 void UserPolicyCache::CheckIfReady() { 120 void UserPolicyCache::CheckIfReady() {
124 if (!IsReady() && disk_cache_ready_ && fetch_ready_) 121 if (!IsReady() && disk_cache_ready_ && fetch_ready_)
125 SetReady(); 122 SetReady();
126 } 123 }
127 124
128 // Everything below is only needed for supporting old-style GenericNamedValue 125 // Everything below is only needed for supporting old-style GenericNamedValue
129 // based policy data and can be removed once this support is no longer needed. 126 // based policy data and can be removed once this support is no longer needed.
130 127
131 using google::protobuf::RepeatedField; 128 using google::protobuf::RepeatedField;
132 using google::protobuf::RepeatedPtrField; 129 using google::protobuf::RepeatedPtrField;
133 130
134 void UserPolicyCache::MaybeDecodeOldstylePolicy( 131 void UserPolicyCache::MaybeDecodeOldstylePolicy(
135 const std::string& policy_data, 132 const std::string& policy_data,
136 PolicyMap* mandatory, 133 PolicyMap* policies) {
137 PolicyMap* recommended) {
138 // Return immediately if we already have policy information in the maps. 134 // Return immediately if we already have policy information in the maps.
139 if (!mandatory->empty() || !recommended->empty()) 135 if (!policies->empty())
140 return; 136 return;
141 em::LegacyChromeSettingsProto policy; 137 em::LegacyChromeSettingsProto policy;
142 // Return if the input string doesn't match the protobuf definition. 138 // Return if the input string doesn't match the protobuf definition.
143 if (!policy.ParseFromString(policy_data)) 139 if (!policy.ParseFromString(policy_data))
144 return; 140 return;
145 // Return if there's no old-style policy to decode. 141 // Return if there's no old-style policy to decode.
146 if (policy.named_value_size() == 0) 142 if (policy.named_value_size() == 0)
147 return; 143 return;
148 144
149 // Inspect GenericNamedValues and decode them. 145 // Inspect GenericNamedValues and decode them.
150 DictionaryValue result; 146 DictionaryValue result;
151 RepeatedPtrField<em::GenericNamedValue>::const_iterator named_value; 147 RepeatedPtrField<em::GenericNamedValue>::const_iterator named_value;
152 for (named_value = policy.named_value().begin(); 148 for (named_value = policy.named_value().begin();
153 named_value != policy.named_value().end(); 149 named_value != policy.named_value().end();
154 ++named_value) { 150 ++named_value) {
155 if (named_value->has_value()) { 151 if (named_value->has_value()) {
156 Value* decoded_value = DecodeValue(named_value->value()); 152 Value* decoded_value = DecodeValue(named_value->value());
157 if (decoded_value) 153 if (decoded_value)
158 result.Set(named_value->name(), decoded_value); 154 result.Set(named_value->name(), decoded_value);
159 } 155 }
160 } 156 }
161 mandatory->LoadFrom(&result, GetChromePolicyDefinitionList()); 157 policies->LoadFrom(&result,
158 GetChromePolicyDefinitionList(),
159 POLICY_LEVEL_MANDATORY,
160 POLICY_SCOPE_USER);
162 } 161 }
163 162
164 Value* UserPolicyCache::DecodeIntegerValue( 163 Value* UserPolicyCache::DecodeIntegerValue(
165 google::protobuf::int64 value) const { 164 google::protobuf::int64 value) const {
166 if (value < std::numeric_limits<int>::min() || 165 if (value < std::numeric_limits<int>::min() ||
167 value > std::numeric_limits<int>::max()) { 166 value > std::numeric_limits<int>::max()) {
168 LOG(WARNING) << "Integer value " << value 167 LOG(WARNING) << "Integer value " << value
169 << " out of numeric limits, ignoring."; 168 << " out of numeric limits, ignoring.";
170 return NULL; 169 return NULL;
171 } 170 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 return list; 235 return list;
237 } 236 }
238 default: 237 default:
239 NOTREACHED() << "Unhandled value type"; 238 NOTREACHED() << "Unhandled value type";
240 } 239 }
241 240
242 return NULL; 241 return NULL;
243 } 242 }
244 243
245 } // namespace policy 244 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/user_policy_cache.h ('k') | chrome/browser/policy/user_policy_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698