1// Copyright 2013 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 COMPONENTS_POLICY_CORE_COMMON_POLICY_BUNDLE_H_ 6#define COMPONENTS_POLICY_CORE_COMMON_POLICY_BUNDLE_H_ 7 8#include <map> 9#include <string> 10 11#include "base/basictypes.h" 12#include "components/policy/core/common/policy_map.h" 13#include "components/policy/core/common/policy_namespace.h" 14#include "components/policy/policy_export.h" 15 16namespace policy { 17 18// Maps policy namespaces to PolicyMaps. 19class POLICY_EXPORT PolicyBundle { 20 public: 21 typedef std::map<PolicyNamespace, PolicyMap*> MapType; 22 typedef MapType::iterator iterator; 23 typedef MapType::const_iterator const_iterator; 24 25 PolicyBundle(); 26 virtual ~PolicyBundle(); 27 28 // Returns the PolicyMap for namespace |ns|. 29 PolicyMap& Get(const PolicyNamespace& ns); 30 const PolicyMap& Get(const PolicyNamespace& ns) const; 31 32 // Swaps the internal representation of |this| with |other|. 33 void Swap(PolicyBundle* other); 34 35 // |this| becomes a copy of |other|. Any existing PolicyMaps are dropped. 36 void CopyFrom(const PolicyBundle& other); 37 38 // Merges the PolicyMaps of |this| with those of |other| for each namespace 39 // in common. Also adds copies of the (namespace, PolicyMap) pairs in |other| 40 // that don't have an entry in |this|. 41 // Each policy in each PolicyMap is replaced only if the policy from |other| 42 // has a higher priority. 43 // See PolicyMap::MergeFrom for details on merging individual PolicyMaps. 44 void MergeFrom(const PolicyBundle& other); 45 46 // Returns true if |other| has the same keys and value as |this|. 47 bool Equals(const PolicyBundle& other) const; 48 49 // Returns iterators to the beginning and end of the underlying container. 50 iterator begin() { return policy_bundle_.begin(); } 51 iterator end() { return policy_bundle_.end(); } 52 53 // These can be used to iterate over and read the PolicyMaps, but not to 54 // modify them. 55 const_iterator begin() const { return policy_bundle_.begin(); } 56 const_iterator end() const { return policy_bundle_.end(); } 57 58 // Erases all the existing pairs. 59 void Clear(); 60 61 private: 62 MapType policy_bundle_; 63 64 // An empty PolicyMap that is returned by const Get() for namespaces that 65 // do not exist in |policy_bundle_|. 66 const PolicyMap kEmpty_; 67 68 DISALLOW_COPY_AND_ASSIGN(PolicyBundle); 69}; 70 71} // namespace policy 72 73#endif // COMPONENTS_POLICY_CORE_COMMON_POLICY_BUNDLE_H_ 74