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

Side by Side Diff: components/policy/core/common/cloud/component_cloud_policy_store.cc

Issue 2830033003: Use {To/From}JavaTime for policy timestamps (Closed)
Patch Set: Rebase Created 3 years, 8 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "components/policy/core/common/cloud/component_cloud_policy_store.h" 5 #include "components/policy/core/common/cloud/component_cloud_policy_store.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 65 }
66 66
67 const DomainConstants* GetDomainConstantsForType(const std::string& type) { 67 const DomainConstants* GetDomainConstantsForType(const std::string& type) {
68 for (const DomainConstants& constants : kDomains) { 68 for (const DomainConstants& constants : kDomains) {
69 if (constants.policy_type == type) 69 if (constants.policy_type == type)
70 return &constants; 70 return &constants;
71 } 71 }
72 return nullptr; 72 return nullptr;
73 } 73 }
74 74
75 base::Time GetTimeFromPolicyTimestamp(int64_t timestamp) {
76 return base::Time::UnixEpoch() + base::TimeDelta::FromMilliseconds(timestamp);
77 }
78
79 } // namespace 75 } // namespace
80 76
81 ComponentCloudPolicyStore::Delegate::~Delegate() {} 77 ComponentCloudPolicyStore::Delegate::~Delegate() {}
82 78
83 ComponentCloudPolicyStore::ComponentCloudPolicyStore(Delegate* delegate, 79 ComponentCloudPolicyStore::ComponentCloudPolicyStore(Delegate* delegate,
84 ResourceCache* cache) 80 ResourceCache* cache)
85 : delegate_(delegate), cache_(cache) { 81 : delegate_(delegate), cache_(cache) {
86 // Allow the store to be created on a different thread than the thread that 82 // Allow the store to be created on a different thread than the thread that
87 // will end up using it. 83 // will end up using it.
88 DetachFromThread(); 84 DetachFromThread();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 160
165 // The protobuf looks good; load the policy data. 161 // The protobuf looks good; load the policy data.
166 std::string data; 162 std::string data;
167 PolicyMap policy; 163 PolicyMap policy;
168 if (cache_->Load(constants.data_cache_key, id, &data) && 164 if (cache_->Load(constants.data_cache_key, id, &data) &&
169 ValidateData(data, payload.secure_hash(), &policy)) { 165 ValidateData(data, payload.secure_hash(), &policy)) {
170 // The data is also good; expose the policies. 166 // The data is also good; expose the policies.
171 policy_bundle_.Get(ns).Swap(&policy); 167 policy_bundle_.Get(ns).Swap(&policy);
172 cached_hashes_[ns] = payload.secure_hash(); 168 cached_hashes_[ns] = payload.secure_hash();
173 stored_policy_times_[ns] = 169 stored_policy_times_[ns] =
174 GetTimeFromPolicyTimestamp(policy_data.timestamp()); 170 base::Time::FromJavaTime(policy_data.timestamp());
175 } else { 171 } else {
176 // The data for this proto couldn't be loaded or is corrupted. 172 // The data for this proto couldn't be loaded or is corrupted.
177 Delete(ns); 173 Delete(ns);
178 } 174 }
179 } 175 }
180 } 176 }
181 } 177 }
182 178
183 bool ComponentCloudPolicyStore::Store( 179 bool ComponentCloudPolicyStore::Store(
184 const PolicyNamespace& ns, 180 const PolicyNamespace& ns,
185 const std::string& serialized_policy, 181 const std::string& serialized_policy,
186 std::unique_ptr<em::PolicyData> policy_data, 182 std::unique_ptr<em::PolicyData> policy_data,
187 const std::string& secure_hash, 183 const std::string& secure_hash,
188 const std::string& data) { 184 const std::string& data) {
189 DCHECK(CalledOnValidThread()); 185 DCHECK(CalledOnValidThread());
190 const DomainConstants* constants = GetDomainConstants(ns.domain); 186 const DomainConstants* constants = GetDomainConstants(ns.domain);
191 PolicyMap policy; 187 PolicyMap policy;
192 // |serialized_policy| has already been validated; validate the data now. 188 // |serialized_policy| has already been validated; validate the data now.
193 if (!constants) 189 if (!constants)
194 return false; 190 return false;
195 if (!ValidateData(data, secure_hash, &policy)) 191 if (!ValidateData(data, secure_hash, &policy))
196 return false; 192 return false;
197 193
198 // Flush the proto and the data to the cache. 194 // Flush the proto and the data to the cache.
199 cache_->Store(constants->proto_cache_key, ns.component_id, serialized_policy); 195 cache_->Store(constants->proto_cache_key, ns.component_id, serialized_policy);
200 cache_->Store(constants->data_cache_key, ns.component_id, data); 196 cache_->Store(constants->data_cache_key, ns.component_id, data);
201 // And expose the policy. 197 // And expose the policy.
202 policy_bundle_.Get(ns).Swap(&policy); 198 policy_bundle_.Get(ns).Swap(&policy);
203 cached_hashes_[ns] = secure_hash; 199 cached_hashes_[ns] = secure_hash;
204 stored_policy_times_[ns] = 200 stored_policy_times_[ns] = base::Time::FromJavaTime(policy_data->timestamp());
205 GetTimeFromPolicyTimestamp(policy_data->timestamp());
206 delegate_->OnComponentCloudPolicyStoreUpdated(); 201 delegate_->OnComponentCloudPolicyStoreUpdated();
207 return true; 202 return true;
208 } 203 }
209 204
210 void ComponentCloudPolicyStore::Delete(const PolicyNamespace& ns) { 205 void ComponentCloudPolicyStore::Delete(const PolicyNamespace& ns) {
211 DCHECK(CalledOnValidThread()); 206 DCHECK(CalledOnValidThread());
212 const DomainConstants* constants = GetDomainConstants(ns.domain); 207 const DomainConstants* constants = GetDomainConstants(ns.domain);
213 if (!constants) 208 if (!constants)
214 return; 209 return;
215 210
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 // this must support a configurable scope; assuming POLICY_SCOPE_USER is 397 // this must support a configurable scope; assuming POLICY_SCOPE_USER is
403 // fine for now. 398 // fine for now.
404 policy->Set(it.key(), level, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, 399 policy->Set(it.key(), level, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
405 std::move(value), nullptr); 400 std::move(value), nullptr);
406 } 401 }
407 402
408 return true; 403 return true;
409 } 404 }
410 405
411 } // namespace policy 406 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698