• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/macros.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 
17 namespace policy {
18 
19 class PolicyBundle;
20 
21 // Maps component id (e.g. extension id) to schema.
22 typedef std::map<std::string, Schema> ComponentMap;
23 typedef std::map<PolicyDomain, ComponentMap> DomainMap;
24 
25 // Contains a mapping of policy namespaces (domain + component ID) to its
26 // corresponding Schema.
27 // This class is thread-safe.
28 class POLICY_EXPORT SchemaMap : public base::RefCountedThreadSafe<SchemaMap> {
29  public:
30   SchemaMap();
31   // Takes ownership of |map| (its contents will be swapped).
32   // TODO(emaxx): Change to use move semantics.
33   explicit SchemaMap(DomainMap& map);
34 
35   const DomainMap& GetDomains() const;
36 
37   const ComponentMap* GetComponents(PolicyDomain domain) const;
38 
39   const Schema* GetSchema(const PolicyNamespace& ns) const;
40 
41   // Removes all the policies in |bundle| that don't match the known schemas.
42   // Unknown components are also dropped.
43   void FilterBundle(PolicyBundle* bundle) const;
44 
45   // Returns true if this map contains at least one component of a domain other
46   // than POLICY_DOMAIN_CHROME.
47   bool HasComponents() const;
48 
49   void GetChanges(const scoped_refptr<SchemaMap>& older,
50                   PolicyNamespaceList* removed,
51                   PolicyNamespaceList* added) const;
52 
53  private:
54   friend class base::RefCountedThreadSafe<SchemaMap>;
55 
56   void GetNamespacesNotInOther(const SchemaMap* other,
57                                PolicyNamespaceList* list) const;
58 
59   ~SchemaMap();
60 
61   DomainMap map_;
62 
63   DISALLOW_COPY_AND_ASSIGN(SchemaMap);
64 };
65 
66 }  // namespace policy
67 
68 #endif  // COMPONENTS_POLICY_CORE_COMMON_SCHEMA_MAP_H_
69