summaryrefslogtreecommitdiffstats
path: root/chrome/browser/policy/proxy_policy_provider.cc
blob: d1db4c1d31eada99370f773bd9808b4ae44309ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/policy/proxy_policy_provider.h"

namespace policy {

ProxyPolicyProvider::ProxyPolicyProvider() {}

ProxyPolicyProvider::~ProxyPolicyProvider() {}

void ProxyPolicyProvider::SetDelegate(ConfigurationPolicyProvider* delegate) {
  if (delegate) {
    registrar_.reset(new ConfigurationPolicyObserverRegistrar());
    registrar_->Init(delegate, this);
    OnUpdatePolicy(delegate);
  } else {
    registrar_.reset();
    UpdatePolicy(scoped_ptr<PolicyBundle>(new PolicyBundle()));
  }
}

void ProxyPolicyProvider::RefreshPolicies() {
  if (registrar_.get())
    registrar_->provider()->RefreshPolicies();
  else
    UpdatePolicy(scoped_ptr<PolicyBundle>(new PolicyBundle()));
}

void ProxyPolicyProvider::OnUpdatePolicy(
    ConfigurationPolicyProvider* provider) {
  DCHECK_EQ(registrar_->provider(), provider);
  scoped_ptr<PolicyBundle> bundle(new PolicyBundle());
  bundle->CopyFrom(registrar_->provider()->policies());
  UpdatePolicy(bundle.Pass());
}

void ProxyPolicyProvider::OnProviderGoingAway(
    ConfigurationPolicyProvider* provider) {
  registrar_.reset();
  UpdatePolicy(scoped_ptr<PolicyBundle>(new PolicyBundle()));
}

}  // namespace policy