1 // Copyright (c) 2012 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 "chrome/browser/chromeos/policy/proxy_policy_provider.h"
9 ProxyPolicyProvider::ProxyPolicyProvider() : delegate_(NULL
) {}
11 ProxyPolicyProvider::~ProxyPolicyProvider() {
15 void ProxyPolicyProvider::SetDelegate(ConfigurationPolicyProvider
* delegate
) {
17 delegate_
->RemoveObserver(this);
20 delegate_
->AddObserver(this);
21 OnUpdatePolicy(delegate_
);
23 UpdatePolicy(scoped_ptr
<PolicyBundle
>(new PolicyBundle()));
27 void ProxyPolicyProvider::Shutdown() {
28 // Note: the delegate is not owned by the proxy provider, so this call is not
29 // forwarded. The same applies for the Init() call.
30 // Just drop the delegate without propagating updates here.
32 delegate_
->RemoveObserver(this);
35 ConfigurationPolicyProvider::Shutdown();
38 void ProxyPolicyProvider::RefreshPolicies() {
40 delegate_
->RefreshPolicies();
42 // Subtle: if a RefreshPolicies() call comes after Shutdown() then the
43 // current bundle should be served instead. This also does the right thing
44 // if SetDelegate() was never called before.
45 scoped_ptr
<PolicyBundle
> bundle(new PolicyBundle());
46 bundle
->CopyFrom(policies());
47 UpdatePolicy(bundle
.Pass());
51 void ProxyPolicyProvider::OnUpdatePolicy(
52 ConfigurationPolicyProvider
* provider
) {
53 DCHECK_EQ(delegate_
, provider
);
54 scoped_ptr
<PolicyBundle
> bundle(new PolicyBundle());
55 bundle
->CopyFrom(delegate_
->policies());
56 UpdatePolicy(bundle
.Pass());