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. 4 5 #include "chrome/browser/chromeos/policy/proxy_policy_provider.h" 6 7 namespace policy { 8 9 ProxyPolicyProvider::ProxyPolicyProvider() : delegate_(NULL) {} 10 11 ProxyPolicyProvider::~ProxyPolicyProvider() { 12 DCHECK(!delegate_); 13 } 14 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())); 24 } 25 } 26 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; 34 } 35 ConfigurationPolicyProvider::Shutdown(); 36 } 37 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()); 48 } 49 } 50 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()); 57 } 58 59 } // namespace policy 60