1 // Copyright 2014 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.
5 #include "components/policy/core/common/proxy_policy_provider.h"
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "components/policy/core/common/policy_bundle.h"
13 ProxyPolicyProvider::ProxyPolicyProvider() : delegate_(NULL
) {}
15 ProxyPolicyProvider::~ProxyPolicyProvider() {
19 void ProxyPolicyProvider::SetDelegate(ConfigurationPolicyProvider
* delegate
) {
21 delegate_
->RemoveObserver(this);
24 delegate_
->AddObserver(this);
25 OnUpdatePolicy(delegate_
);
27 UpdatePolicy(scoped_ptr
<PolicyBundle
>(new PolicyBundle()));
31 void ProxyPolicyProvider::Shutdown() {
32 // Note: the delegate is not owned by the proxy provider, so this call is not
33 // forwarded. The same applies for the Init() call.
34 // Just drop the delegate without propagating updates here.
36 delegate_
->RemoveObserver(this);
39 ConfigurationPolicyProvider::Shutdown();
42 void ProxyPolicyProvider::RefreshPolicies() {
44 delegate_
->RefreshPolicies();
46 // Subtle: if a RefreshPolicies() call comes after Shutdown() then the
47 // current bundle should be served instead. This also does the right thing
48 // if SetDelegate() was never called before.
49 scoped_ptr
<PolicyBundle
> bundle(new PolicyBundle());
50 bundle
->CopyFrom(policies());
51 UpdatePolicy(bundle
.Pass());
55 void ProxyPolicyProvider::OnUpdatePolicy(
56 ConfigurationPolicyProvider
* provider
) {
57 DCHECK_EQ(delegate_
, provider
);
58 scoped_ptr
<PolicyBundle
> bundle(new PolicyBundle());
59 bundle
->CopyFrom(delegate_
->policies());
60 UpdatePolicy(bundle
.Pass());