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