Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / proxy_policy_provider.cc
blob30c879c4b2d7b105a21b9ccc2961217bce8d7952
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"
7 namespace policy {
9 ProxyPolicyProvider::ProxyPolicyProvider() : delegate_(NULL) {}
11 ProxyPolicyProvider::~ProxyPolicyProvider() {
12 DCHECK(!delegate_);
15 void ProxyPolicyProvider::SetDelegate(ConfigurationPolicyProvider* delegate) {
16 if (delegate_)
17 delegate_->RemoveObserver(this);
18 delegate_ = delegate;
19 if (delegate_) {
20 delegate_->AddObserver(this);
21 OnUpdatePolicy(delegate_);
22 } else {
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.
31 if (delegate_) {
32 delegate_->RemoveObserver(this);
33 delegate_ = NULL;
35 ConfigurationPolicyProvider::Shutdown();
38 void ProxyPolicyProvider::RefreshPolicies() {
39 if (delegate_) {
40 delegate_->RefreshPolicies();
41 } else {
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());
59 } // namespace policy