| OLD | NEW |
| 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 SetExtensionsDomainsReady(); |
| 20 #endif | 20 #endif |
| 21 } | 21 } |
| 22 | 22 |
| 23 SchemaRegistry::~SchemaRegistry() { | 23 SchemaRegistry::~SchemaRegistry() { |
| 24 for (auto& observer : internal_observers_) | 24 for (auto& observer : internal_observers_) |
| 25 observer.OnSchemaRegistryShuttingDown(this); | 25 observer.OnSchemaRegistryShuttingDown(this); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void SchemaRegistry::RegisterComponent(const PolicyNamespace& ns, | 28 void SchemaRegistry::RegisterComponent(const PolicyNamespace& ns, |
| 29 const Schema& schema) { | 29 const Schema& schema) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 void SchemaRegistry::SetReady(PolicyDomain domain) { | 69 void SchemaRegistry::SetReady(PolicyDomain domain) { |
| 70 if (domains_ready_[domain]) | 70 if (domains_ready_[domain]) |
| 71 return; | 71 return; |
| 72 domains_ready_[domain] = true; | 72 domains_ready_[domain] = true; |
| 73 if (IsReady()) { | 73 if (IsReady()) { |
| 74 for (auto& observer : observers_) | 74 for (auto& observer : observers_) |
| 75 observer.OnSchemaRegistryReady(); | 75 observer.OnSchemaRegistryReady(); |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 | 78 |
| 79 void SchemaRegistry::SetAllDomainsReady() { |
| 80 for (int i = 0; i < POLICY_DOMAIN_SIZE; ++i) |
| 81 SetReady(static_cast<PolicyDomain>(i)); |
| 82 } |
| 83 |
| 84 void SchemaRegistry::SetExtensionsDomainsReady() { |
| 85 SetReady(POLICY_DOMAIN_EXTENSIONS); |
| 86 SetReady(POLICY_DOMAIN_SIGNIN_EXTENSIONS); |
| 87 } |
| 88 |
| 79 void SchemaRegistry::AddObserver(Observer* observer) { | 89 void SchemaRegistry::AddObserver(Observer* observer) { |
| 80 observers_.AddObserver(observer); | 90 observers_.AddObserver(observer); |
| 81 } | 91 } |
| 82 | 92 |
| 83 void SchemaRegistry::RemoveObserver(Observer* observer) { | 93 void SchemaRegistry::RemoveObserver(Observer* observer) { |
| 84 observers_.RemoveObserver(observer); | 94 observers_.RemoveObserver(observer); |
| 85 } | 95 } |
| 86 | 96 |
| 87 void SchemaRegistry::AddInternalObserver(InternalObserver* observer) { | 97 void SchemaRegistry::AddInternalObserver(InternalObserver* observer) { |
| 88 internal_observers_.AddObserver(observer); | 98 internal_observers_.AddObserver(observer); |
| 89 } | 99 } |
| 90 | 100 |
| 91 void SchemaRegistry::RemoveInternalObserver(InternalObserver* observer) { | 101 void SchemaRegistry::RemoveInternalObserver(InternalObserver* observer) { |
| 92 internal_observers_.RemoveObserver(observer); | 102 internal_observers_.RemoveObserver(observer); |
| 93 } | 103 } |
| 94 | 104 |
| 95 void SchemaRegistry::Notify(bool has_new_schemas) { | 105 void SchemaRegistry::Notify(bool has_new_schemas) { |
| 96 for (auto& observer : observers_) | 106 for (auto& observer : observers_) |
| 97 observer.OnSchemaRegistryUpdated(has_new_schemas); | 107 observer.OnSchemaRegistryUpdated(has_new_schemas); |
| 98 } | 108 } |
| 99 | 109 |
| 100 CombinedSchemaRegistry::CombinedSchemaRegistry() | 110 CombinedSchemaRegistry::CombinedSchemaRegistry() |
| 101 : own_schema_map_(new SchemaMap) { | 111 : own_schema_map_(new SchemaMap) { |
| 102 // The combined registry is always ready, since it can always start tracking | 112 // The combined registry is always ready, since it can always start tracking |
| 103 // another registry that is not ready yet and going from "ready" to "not | 113 // another registry that is not ready yet and going from "ready" to "not |
| 104 // ready" is not allowed. | 114 // ready" is not allowed. |
| 105 for (int i = 0; i < POLICY_DOMAIN_SIZE; ++i) | 115 SetAllDomainsReady(); |
| 106 SetReady(static_cast<PolicyDomain>(i)); | |
| 107 } | 116 } |
| 108 | 117 |
| 109 CombinedSchemaRegistry::~CombinedSchemaRegistry() {} | 118 CombinedSchemaRegistry::~CombinedSchemaRegistry() {} |
| 110 | 119 |
| 111 void CombinedSchemaRegistry::Track(SchemaRegistry* registry) { | 120 void CombinedSchemaRegistry::Track(SchemaRegistry* registry) { |
| 112 registries_.insert(registry); | 121 registries_.insert(registry); |
| 113 registry->AddObserver(this); | 122 registry->AddObserver(this); |
| 114 registry->AddInternalObserver(this); | 123 registry->AddInternalObserver(this); |
| 115 // Recombine the maps only if the |registry| has any components other than | 124 // Recombine the maps only if the |registry| has any components other than |
| 116 // POLICY_DOMAIN_CHROME. | 125 // POLICY_DOMAIN_CHROME. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 void ForwardingSchemaRegistry::OnSchemaRegistryShuttingDown( | 233 void ForwardingSchemaRegistry::OnSchemaRegistryShuttingDown( |
| 225 SchemaRegistry* registry) { | 234 SchemaRegistry* registry) { |
| 226 DCHECK_EQ(wrapped_, registry); | 235 DCHECK_EQ(wrapped_, registry); |
| 227 wrapped_->RemoveObserver(this); | 236 wrapped_->RemoveObserver(this); |
| 228 wrapped_->RemoveInternalObserver(this); | 237 wrapped_->RemoveInternalObserver(this); |
| 229 wrapped_ = NULL; | 238 wrapped_ = NULL; |
| 230 // Keep serving the same |schema_map_|. | 239 // Keep serving the same |schema_map_|. |
| 231 } | 240 } |
| 232 | 241 |
| 233 } // namespace policy | 242 } // namespace policy |
| OLD | NEW |