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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_POLICY_POLICY_BUNDLE_H_
6 #define CHROME_BROWSER_POLICY_POLICY_BUNDLE_H_
11 #include "base/basictypes.h"
12 #include "chrome/browser/policy/policy_map.h"
13 #include "components/policy/core/common/policy_namespace.h"
17 // Maps policy namespaces to PolicyMaps.
20 typedef std::map<PolicyNamespace, PolicyMap*> MapType;
21 typedef MapType::iterator iterator;
22 typedef MapType::const_iterator const_iterator;
25 virtual ~PolicyBundle();
27 // Returns the PolicyMap for namespace |ns|.
28 PolicyMap& Get(const PolicyNamespace& ns);
29 const PolicyMap& Get(const PolicyNamespace& ns) const;
31 // Swaps the internal representation of |this| with |other|.
32 void Swap(PolicyBundle* other);
34 // |this| becomes a copy of |other|. Any existing PolicyMaps are dropped.
35 void CopyFrom(const PolicyBundle& other);
37 // Merges the PolicyMaps of |this| with those of |other| for each namespace
38 // in common. Also adds copies of the (namespace, PolicyMap) pairs in |other|
39 // that don't have an entry in |this|.
40 // Each policy in each PolicyMap is replaced only if the policy from |other|
41 // has a higher priority.
42 // See PolicyMap::MergeFrom for details on merging individual PolicyMaps.
43 void MergeFrom(const PolicyBundle& other);
45 // Returns true if |other| has the same keys and value as |this|.
46 bool Equals(const PolicyBundle& other) const;
48 // Returns iterators to the beginning and end of the underlying container.
49 iterator begin() { return policy_bundle_.begin(); }
50 iterator end() { return policy_bundle_.end(); }
52 // These can be used to iterate over and read the PolicyMaps, but not to
54 const_iterator begin() const { return policy_bundle_.begin(); }
55 const_iterator end() const { return policy_bundle_.end(); }
57 // Erases all the existing pairs.
61 MapType policy_bundle_;
63 // An empty PolicyMap that is returned by const Get() for namespaces that
64 // do not exist in |policy_bundle_|.
65 const PolicyMap kEmpty_;
67 DISALLOW_COPY_AND_ASSIGN(PolicyBundle);
72 #endif // CHROME_BROWSER_POLICY_POLICY_BUNDLE_H_