Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: chrome/browser/policy/schema_registry.h

Issue 78453005: Move PolicySchema and PolicySchemaRegistry to components/policy/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: export nested class on win Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/policy/schema_map_unittest.cc ('k') | chrome/browser/policy/schema_registry.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 CHROME_BROWSER_POLICY_SCHEMA_REGISTRY_H_
6 #define CHROME_BROWSER_POLICY_SCHEMA_REGISTRY_H_
7
8 #include <set>
9
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/observer_list.h"
14 #include "base/threading/non_thread_safe.h"
15 #include "chrome/browser/policy/schema_map.h"
16 #include "components/policy/core/common/policy_namespace.h"
17 #include "components/policy/core/common/schema.h"
18
19 namespace policy {
20
21 class SchemaMap;
22
23 // Holds the main reference to the current SchemaMap, and allows a list of
24 // observers to get notified whenever it is updated.
25 // This object is not thread safe and must be used from the owner's thread,
26 // usually UI.
27 class SchemaRegistry : public base::NonThreadSafe {
28 public:
29 class Observer {
30 public:
31 // Invoked whenever schemas are registered or unregistered.
32 // |has_new_schemas| is true if a new component has been registered since
33 // the last update; this allows observers to ignore updates when
34 // components are unregistered but still get a handle to the current map
35 // (e.g. for periodic reloads).
36 virtual void OnSchemaRegistryUpdated(bool has_new_schemas) = 0;
37
38 // Invoked when all policy domains become ready.
39 virtual void OnSchemaRegistryReady() = 0;
40
41 protected:
42 virtual ~Observer();
43 };
44
45 SchemaRegistry();
46 virtual ~SchemaRegistry();
47
48 const scoped_refptr<SchemaMap>& schema_map() const { return schema_map_; }
49
50 // Register a single component.
51 void RegisterComponent(const PolicyNamespace& ns,
52 const Schema& schema);
53
54 // Register a list of components for a given domain.
55 virtual void RegisterComponents(PolicyDomain domain,
56 const ComponentMap& components);
57
58 virtual void UnregisterComponent(const PolicyNamespace& ns);
59
60 // Returns true if all domains have registered the initial components.
61 bool IsReady() const;
62
63 // This indicates that the initial components for |domain| have all been
64 // registered. It must be invoked at least once for each policy domain;
65 // subsequent calls for the same domain are ignored.
66 void SetReady(PolicyDomain domain);
67
68 void AddObserver(Observer* observer);
69 void RemoveObserver(Observer* observer);
70
71 bool HasObservers() const;
72
73 protected:
74 void Notify(bool has_new_schemas);
75
76 scoped_refptr<SchemaMap> schema_map_;
77
78 private:
79 ObserverList<Observer, true> observers_;
80 bool domains_ready_[POLICY_DOMAIN_SIZE];
81
82 DISALLOW_COPY_AND_ASSIGN(SchemaRegistry);
83 };
84
85 // A registry that combines the maps of other registries.
86 class CombinedSchemaRegistry : public SchemaRegistry,
87 public SchemaRegistry::Observer {
88 public:
89 CombinedSchemaRegistry();
90 virtual ~CombinedSchemaRegistry();
91
92 void Track(SchemaRegistry* registry);
93 void Untrack(SchemaRegistry* registry);
94
95 virtual void RegisterComponents(PolicyDomain domain,
96 const ComponentMap& components) OVERRIDE;
97
98 virtual void UnregisterComponent(const PolicyNamespace& ns) OVERRIDE;
99
100 virtual void OnSchemaRegistryUpdated(bool has_new_schemas) OVERRIDE;
101
102 virtual void OnSchemaRegistryReady() OVERRIDE;
103
104 private:
105 void Combine(bool has_new_schemas);
106
107 std::set<SchemaRegistry*> registries_;
108 scoped_refptr<SchemaMap> own_schema_map_;
109
110 DISALLOW_COPY_AND_ASSIGN(CombinedSchemaRegistry);
111 };
112
113 } // namespace policy
114
115 #endif // CHROME_BROWSER_POLICY_SCHEMA_REGISTRY_H_
OLDNEW
« no previous file with comments | « chrome/browser/policy/schema_map_unittest.cc ('k') | chrome/browser/policy/schema_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698