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_SCHEMA_MAP_H_ 6#define COMPONENTS_POLICY_CORE_COMMON_SCHEMA_MAP_H_ 7 8#include <map> 9#include <string> 10 11#include "base/basictypes.h" 12#include "base/memory/ref_counted.h" 13#include "components/policy/core/common/policy_namespace.h" 14#include "components/policy/core/common/schema.h" 15#include "components/policy/policy_export.h" 16 17namespace policy { 18 19class PolicyBundle; 20 21typedef std::map<std::string, Schema> ComponentMap; 22typedef std::map<PolicyDomain, ComponentMap> DomainMap; 23 24// Contains a mapping of policy namespaces (domain + component ID) to its 25// corresponding Schema. 26class POLICY_EXPORT SchemaMap : public base::RefCountedThreadSafe<SchemaMap> { 27 public: 28 SchemaMap(); 29 // Takes ownership of |map| (its contents will be swapped). 30 explicit SchemaMap(DomainMap& map); 31 32 const DomainMap& GetDomains() const; 33 34 const ComponentMap* GetComponents(PolicyDomain domain) const; 35 36 const Schema* GetSchema(const PolicyNamespace& ns) const; 37 38 // Removes all the policies in |bundle| that don't match the known schemas. 39 // Unknown components are also dropped. 40 void FilterBundle(PolicyBundle* bundle) const; 41 42 // Returns true if this map contains at least one component of a domain other 43 // than POLICY_DOMAIN_CHROME. 44 bool HasComponents() const; 45 46 void GetChanges(const scoped_refptr<SchemaMap>& older, 47 PolicyNamespaceList* removed, 48 PolicyNamespaceList* added) const; 49 50 private: 51 friend class base::RefCountedThreadSafe<SchemaMap>; 52 53 void GetNamespacesNotInOther(const SchemaMap* other, 54 PolicyNamespaceList* list) const; 55 56 ~SchemaMap(); 57 58 DomainMap map_; 59 60 DISALLOW_COPY_AND_ASSIGN(SchemaMap); 61}; 62 63} // namespace policy 64 65#endif // COMPONENTS_POLICY_CORE_COMMON_SCHEMA_MAP_H_ 66