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

Side by Side Diff: chrome/browser/policy/cloud/component_cloud_policy_store.cc

Issue 56623005: Policy providers all get a SchemaRegistry to work with. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@chrome-policy-schema-9-purge-with-callback
Patch Set: Fixed mac tests Created 7 years, 1 month 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 "chrome/browser/policy/cloud/component_cloud_policy_store.h" 5 #include "chrome/browser/policy/cloud/component_cloud_policy_store.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/sha1.h" 10 #include "base/sha1.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" 13 #include "chrome/browser/policy/cloud/cloud_policy_constants.h"
14 #include "chrome/browser/policy/cloud/cloud_policy_validator.h" 14 #include "chrome/browser/policy/cloud/cloud_policy_validator.h"
15 #include "chrome/browser/policy/cloud/resource_cache.h"
16 #include "chrome/browser/policy/external_data_fetcher.h" 15 #include "chrome/browser/policy/external_data_fetcher.h"
17 #include "chrome/browser/policy/policy_map.h" 16 #include "chrome/browser/policy/policy_map.h"
18 #include "chrome/browser/policy/proto/cloud/chrome_extension_policy.pb.h" 17 #include "chrome/browser/policy/proto/cloud/chrome_extension_policy.pb.h"
19 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" 18 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h"
20 #include "url/gurl.h" 19 #include "url/gurl.h"
21 20
22 namespace em = enterprise_management; 21 namespace em = enterprise_management;
23 22
24 namespace policy { 23 namespace policy {
25 24
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 cache_->Delete(constants->proto_cache_key, ns.component_id); 181 cache_->Delete(constants->proto_cache_key, ns.component_id);
183 cache_->Delete(constants->data_cache_key, ns.component_id); 182 cache_->Delete(constants->data_cache_key, ns.component_id);
184 183
185 if (!policy_bundle_.Get(ns).empty()) { 184 if (!policy_bundle_.Get(ns).empty()) {
186 policy_bundle_.Get(ns).Clear(); 185 policy_bundle_.Get(ns).Clear();
187 delegate_->OnComponentCloudPolicyStoreUpdated(); 186 delegate_->OnComponentCloudPolicyStoreUpdated();
188 } 187 }
189 } 188 }
190 189
191 void ComponentCloudPolicyStore::Purge(PolicyDomain domain, 190 void ComponentCloudPolicyStore::Purge(PolicyDomain domain,
192 const std::set<std::string>& keep) { 191 const ResourceCache::KeyTest& test) {
193 DCHECK(CalledOnValidThread()); 192 DCHECK(CalledOnValidThread());
194 const DomainConstants* constants = GetDomainConstants(domain); 193 const DomainConstants* constants = GetDomainConstants(domain);
195 if (!constants) 194 if (!constants)
196 return; 195 return;
197 196
198 cache_->PurgeOtherSubkeys(constants->proto_cache_key, keep); 197 cache_->PurgeSubkeys(constants->proto_cache_key, test);
199 cache_->PurgeOtherSubkeys(constants->data_cache_key, keep); 198 cache_->PurgeSubkeys(constants->data_cache_key, test);
200 199
201 // Stop serving policies for purged namespaces. 200 // Stop serving policies for purged namespaces.
202 bool purged_current_policies = false; 201 bool purged_current_policies = false;
203 for (PolicyBundle::const_iterator it = policy_bundle_.begin(); 202 for (PolicyBundle::const_iterator it = policy_bundle_.begin();
204 it != policy_bundle_.end(); ++it) { 203 it != policy_bundle_.end(); ++it) {
205 if (it->first.domain == domain && 204 if (it->first.domain == domain &&
206 keep.find(it->first.component_id) == keep.end() && 205 test.Run(it->first.component_id) &&
207 !policy_bundle_.Get(it->first).empty()) { 206 !policy_bundle_.Get(it->first).empty()) {
208 policy_bundle_.Get(it->first).Clear(); 207 policy_bundle_.Get(it->first).Clear();
209 purged_current_policies = true; 208 purged_current_policies = true;
210 } 209 }
211 } 210 }
212 211
213 // Purge cached hashes, so that those namespaces can be fetched again if the 212 // Purge cached hashes, so that those namespaces can be fetched again if the
214 // policy state changes. 213 // policy state changes.
215 std::map<PolicyNamespace, std::string>::iterator it = cached_hashes_.begin(); 214 std::map<PolicyNamespace, std::string>::iterator it = cached_hashes_.begin();
216 while (it != cached_hashes_.end()) { 215 while (it != cached_hashes_.end()) {
217 if (it->first.domain == domain && 216 if (it->first.domain == domain && test.Run(it->first.component_id)) {
218 keep.find(it->first.component_id) == keep.end()) {
219 std::map<PolicyNamespace, std::string>::iterator prev = it; 217 std::map<PolicyNamespace, std::string>::iterator prev = it;
220 ++it; 218 ++it;
221 cached_hashes_.erase(prev); 219 cached_hashes_.erase(prev);
222 } else { 220 } else {
223 ++it; 221 ++it;
224 } 222 }
225 } 223 }
226 224
227 if (purged_current_policies) 225 if (purged_current_policies)
228 delegate_->OnComponentCloudPolicyStoreUpdated(); 226 delegate_->OnComponentCloudPolicyStoreUpdated();
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 // If policy for components is ever used for device-level settings then 334 // If policy for components is ever used for device-level settings then
337 // this must support a configurable scope; assuming POLICY_SCOPE_USER is 335 // this must support a configurable scope; assuming POLICY_SCOPE_USER is
338 // fine for now. 336 // fine for now.
339 policy->Set(it.key(), level, POLICY_SCOPE_USER, value.release(), NULL); 337 policy->Set(it.key(), level, POLICY_SCOPE_USER, value.release(), NULL);
340 } 338 }
341 339
342 return true; 340 return true;
343 } 341 }
344 342
345 } // namespace policy 343 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698