| OLD | NEW |
| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 180 |
| 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( |
| 192 const std::set<std::string>& keep) { | 191 PolicyDomain domain, |
| 192 const ResourceCache::SubkeyFilter& filter) { |
| 193 DCHECK(CalledOnValidThread()); | 193 DCHECK(CalledOnValidThread()); |
| 194 const DomainConstants* constants = GetDomainConstants(domain); | 194 const DomainConstants* constants = GetDomainConstants(domain); |
| 195 if (!constants) | 195 if (!constants) |
| 196 return; | 196 return; |
| 197 | 197 |
| 198 cache_->PurgeOtherSubkeys(constants->proto_cache_key, keep); | 198 cache_->FilterSubkeys(constants->proto_cache_key, filter); |
| 199 cache_->PurgeOtherSubkeys(constants->data_cache_key, keep); | 199 cache_->FilterSubkeys(constants->data_cache_key, filter); |
| 200 | 200 |
| 201 // Stop serving policies for purged namespaces. | 201 // Stop serving policies for purged namespaces. |
| 202 bool purged_current_policies = false; | 202 bool purged_current_policies = false; |
| 203 for (PolicyBundle::const_iterator it = policy_bundle_.begin(); | 203 for (PolicyBundle::const_iterator it = policy_bundle_.begin(); |
| 204 it != policy_bundle_.end(); ++it) { | 204 it != policy_bundle_.end(); ++it) { |
| 205 if (it->first.domain == domain && | 205 if (it->first.domain == domain && |
| 206 keep.find(it->first.component_id) == keep.end() && | 206 filter.Run(it->first.component_id) && |
| 207 !policy_bundle_.Get(it->first).empty()) { | 207 !policy_bundle_.Get(it->first).empty()) { |
| 208 policy_bundle_.Get(it->first).Clear(); | 208 policy_bundle_.Get(it->first).Clear(); |
| 209 purged_current_policies = true; | 209 purged_current_policies = true; |
| 210 } | 210 } |
| 211 } | 211 } |
| 212 | 212 |
| 213 // Purge cached hashes, so that those namespaces can be fetched again if the | 213 // Purge cached hashes, so that those namespaces can be fetched again if the |
| 214 // policy state changes. | 214 // policy state changes. |
| 215 std::map<PolicyNamespace, std::string>::iterator it = cached_hashes_.begin(); | 215 std::map<PolicyNamespace, std::string>::iterator it = cached_hashes_.begin(); |
| 216 while (it != cached_hashes_.end()) { | 216 while (it != cached_hashes_.end()) { |
| 217 if (it->first.domain == domain && | 217 if (it->first.domain == domain && filter.Run(it->first.component_id)) { |
| 218 keep.find(it->first.component_id) == keep.end()) { | |
| 219 std::map<PolicyNamespace, std::string>::iterator prev = it; | 218 std::map<PolicyNamespace, std::string>::iterator prev = it; |
| 220 ++it; | 219 ++it; |
| 221 cached_hashes_.erase(prev); | 220 cached_hashes_.erase(prev); |
| 222 } else { | 221 } else { |
| 223 ++it; | 222 ++it; |
| 224 } | 223 } |
| 225 } | 224 } |
| 226 | 225 |
| 227 if (purged_current_policies) | 226 if (purged_current_policies) |
| 228 delegate_->OnComponentCloudPolicyStoreUpdated(); | 227 delegate_->OnComponentCloudPolicyStoreUpdated(); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 // If policy for components is ever used for device-level settings then | 335 // If policy for components is ever used for device-level settings then |
| 337 // this must support a configurable scope; assuming POLICY_SCOPE_USER is | 336 // this must support a configurable scope; assuming POLICY_SCOPE_USER is |
| 338 // fine for now. | 337 // fine for now. |
| 339 policy->Set(it.key(), level, POLICY_SCOPE_USER, value.release(), NULL); | 338 policy->Set(it.key(), level, POLICY_SCOPE_USER, value.release(), NULL); |
| 340 } | 339 } |
| 341 | 340 |
| 342 return true; | 341 return true; |
| 343 } | 342 } |
| 344 | 343 |
| 345 } // namespace policy | 344 } // namespace policy |
| OLD | NEW |