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#include "components/policy/core/common/configuration_policy_provider.h"
6
7#include "base/callback.h"
8#include "components/policy/core/common/external_data_fetcher.h"
9#include "components/policy/core/common/policy_map.h"
10
11namespace policy {
12
13ConfigurationPolicyProvider::Observer::~Observer() {}
14
15ConfigurationPolicyProvider::ConfigurationPolicyProvider()
16    : did_shutdown_(false),
17      schema_registry_(NULL) {}
18
19ConfigurationPolicyProvider::~ConfigurationPolicyProvider() {
20  DCHECK(did_shutdown_);
21}
22
23void ConfigurationPolicyProvider::Init(SchemaRegistry* registry) {
24  schema_registry_ = registry;
25  schema_registry_->AddObserver(this);
26}
27
28void ConfigurationPolicyProvider::Shutdown() {
29  did_shutdown_ = true;
30  if (schema_registry_) {
31    // Unit tests don't initialize the BrowserPolicyConnector but call
32    // shutdown; handle that.
33    schema_registry_->RemoveObserver(this);
34    schema_registry_ = NULL;
35  }
36}
37
38bool ConfigurationPolicyProvider::IsInitializationComplete(
39    PolicyDomain domain) const {
40  return true;
41}
42
43void ConfigurationPolicyProvider::UpdatePolicy(
44    scoped_ptr<PolicyBundle> bundle) {
45  if (bundle.get())
46    policy_bundle_.Swap(bundle.get());
47  else
48    policy_bundle_.Clear();
49  FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
50                    observer_list_,
51                    OnUpdatePolicy(this));
52}
53
54SchemaRegistry* ConfigurationPolicyProvider::schema_registry() const {
55  return schema_registry_;
56}
57
58const scoped_refptr<SchemaMap>&
59ConfigurationPolicyProvider::schema_map() const {
60  return schema_registry_->schema_map();
61}
62
63void ConfigurationPolicyProvider::AddObserver(Observer* observer) {
64  observer_list_.AddObserver(observer);
65}
66
67void ConfigurationPolicyProvider::RemoveObserver(Observer* observer) {
68  observer_list_.RemoveObserver(observer);
69}
70
71void ConfigurationPolicyProvider::OnSchemaRegistryUpdated(
72    bool has_new_schemas) {}
73
74void ConfigurationPolicyProvider::OnSchemaRegistryReady() {}
75
76}  // namespace policy
77