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

Side by Side Diff: components/policy/core/common/schema_registry.cc

Issue 2422083002: Remove usage of FOR_EACH_OBSERVER macro in components/policy (Closed)
Patch Set: Created 4 years, 2 months 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
« no previous file with comments | « components/policy/core/common/remote_commands/remote_commands_queue.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 #include "components/policy/core/common/schema_registry.h" 5 #include "components/policy/core/common/schema_registry.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace policy { 9 namespace policy {
10 10
11 SchemaRegistry::Observer::~Observer() {} 11 SchemaRegistry::Observer::~Observer() {}
12 12
13 SchemaRegistry::InternalObserver::~InternalObserver() {} 13 SchemaRegistry::InternalObserver::~InternalObserver() {}
14 14
15 SchemaRegistry::SchemaRegistry() : schema_map_(new SchemaMap) { 15 SchemaRegistry::SchemaRegistry() : schema_map_(new SchemaMap) {
16 for (int i = 0; i < POLICY_DOMAIN_SIZE; ++i) 16 for (int i = 0; i < POLICY_DOMAIN_SIZE; ++i)
17 domains_ready_[i] = false; 17 domains_ready_[i] = false;
18 #if !defined(ENABLE_EXTENSIONS) 18 #if !defined(ENABLE_EXTENSIONS)
19 domains_ready_[POLICY_DOMAIN_EXTENSIONS] = true; 19 domains_ready_[POLICY_DOMAIN_EXTENSIONS] = true;
20 #endif 20 #endif
21 } 21 }
22 22
23 SchemaRegistry::~SchemaRegistry() { 23 SchemaRegistry::~SchemaRegistry() {
24 FOR_EACH_OBSERVER(InternalObserver, 24 for (auto& observer : internal_observers_)
25 internal_observers_, 25 observer.OnSchemaRegistryShuttingDown(this);
26 OnSchemaRegistryShuttingDown(this));
27 } 26 }
28 27
29 void SchemaRegistry::RegisterComponent(const PolicyNamespace& ns, 28 void SchemaRegistry::RegisterComponent(const PolicyNamespace& ns,
30 const Schema& schema) { 29 const Schema& schema) {
31 ComponentMap map; 30 ComponentMap map;
32 map[ns.component_id] = schema; 31 map[ns.component_id] = schema;
33 RegisterComponents(ns.domain, map); 32 RegisterComponents(ns.domain, map);
34 } 33 }
35 34
36 void SchemaRegistry::RegisterComponents(PolicyDomain domain, 35 void SchemaRegistry::RegisterComponents(PolicyDomain domain,
(...skipping 27 matching lines...) Expand all
64 if (!domains_ready_[i]) 63 if (!domains_ready_[i])
65 return false; 64 return false;
66 } 65 }
67 return true; 66 return true;
68 } 67 }
69 68
70 void SchemaRegistry::SetReady(PolicyDomain domain) { 69 void SchemaRegistry::SetReady(PolicyDomain domain) {
71 if (domains_ready_[domain]) 70 if (domains_ready_[domain])
72 return; 71 return;
73 domains_ready_[domain] = true; 72 domains_ready_[domain] = true;
74 if (IsReady()) 73 if (IsReady()) {
75 FOR_EACH_OBSERVER(Observer, observers_, OnSchemaRegistryReady()); 74 for (auto& observer : observers_)
75 observer.OnSchemaRegistryReady();
76 }
76 } 77 }
77 78
78 void SchemaRegistry::AddObserver(Observer* observer) { 79 void SchemaRegistry::AddObserver(Observer* observer) {
79 observers_.AddObserver(observer); 80 observers_.AddObserver(observer);
80 } 81 }
81 82
82 void SchemaRegistry::RemoveObserver(Observer* observer) { 83 void SchemaRegistry::RemoveObserver(Observer* observer) {
83 observers_.RemoveObserver(observer); 84 observers_.RemoveObserver(observer);
84 } 85 }
85 86
86 void SchemaRegistry::AddInternalObserver(InternalObserver* observer) { 87 void SchemaRegistry::AddInternalObserver(InternalObserver* observer) {
87 internal_observers_.AddObserver(observer); 88 internal_observers_.AddObserver(observer);
88 } 89 }
89 90
90 void SchemaRegistry::RemoveInternalObserver(InternalObserver* observer) { 91 void SchemaRegistry::RemoveInternalObserver(InternalObserver* observer) {
91 internal_observers_.RemoveObserver(observer); 92 internal_observers_.RemoveObserver(observer);
92 } 93 }
93 94
94 void SchemaRegistry::Notify(bool has_new_schemas) { 95 void SchemaRegistry::Notify(bool has_new_schemas) {
95 FOR_EACH_OBSERVER( 96 for (auto& observer : observers_)
96 Observer, observers_, OnSchemaRegistryUpdated(has_new_schemas)); 97 observer.OnSchemaRegistryUpdated(has_new_schemas);
97 } 98 }
98 99
99 CombinedSchemaRegistry::CombinedSchemaRegistry() 100 CombinedSchemaRegistry::CombinedSchemaRegistry()
100 : own_schema_map_(new SchemaMap) { 101 : own_schema_map_(new SchemaMap) {
101 // The combined registry is always ready, since it can always start tracking 102 // The combined registry is always ready, since it can always start tracking
102 // another registry that is not ready yet and going from "ready" to "not 103 // another registry that is not ready yet and going from "ready" to "not
103 // ready" is not allowed. 104 // ready" is not allowed.
104 for (int i = 0; i < POLICY_DOMAIN_SIZE; ++i) 105 for (int i = 0; i < POLICY_DOMAIN_SIZE; ++i)
105 SetReady(static_cast<PolicyDomain>(i)); 106 SetReady(static_cast<PolicyDomain>(i));
106 } 107 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 void ForwardingSchemaRegistry::OnSchemaRegistryShuttingDown( 224 void ForwardingSchemaRegistry::OnSchemaRegistryShuttingDown(
224 SchemaRegistry* registry) { 225 SchemaRegistry* registry) {
225 DCHECK_EQ(wrapped_, registry); 226 DCHECK_EQ(wrapped_, registry);
226 wrapped_->RemoveObserver(this); 227 wrapped_->RemoveObserver(this);
227 wrapped_->RemoveInternalObserver(this); 228 wrapped_->RemoveInternalObserver(this);
228 wrapped_ = NULL; 229 wrapped_ = NULL;
229 // Keep serving the same |schema_map_|. 230 // Keep serving the same |schema_map_|.
230 } 231 }
231 232
232 } // namespace policy 233 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy/core/common/remote_commands/remote_commands_queue.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698