summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/policy/proxy_policy_provider.cc
blob: 30c879c4b2d7b105a21b9ccc2961217bce8d7952 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// 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/chromeos/policy/proxy_policy_provider.h"

namespace policy {

ProxyPolicyProvider::ProxyPolicyProvider() : delegate_(NULL) {}

ProxyPolicyProvider::~ProxyPolicyProvider() {
  DCHECK(!delegate_);
}

void ProxyPolicyProvider::SetDelegate(ConfigurationPolicyProvider* delegate) {
  if (delegate_)
    delegate_->RemoveObserver(this);
  delegate_ = delegate;
  if (delegate_) {
    delegate_->AddObserver(this);
    OnUpdatePolicy(delegate_);
  } else {
    UpdatePolicy(scoped_ptr<PolicyBundle>(new PolicyBundle()));
  }
}

void ProxyPolicyProvider::Shutdown() {
  // Note: the delegate is not owned by the proxy provider, so this call is not
  // forwarded. The same applies for the Init() call.
  // Just drop the delegate without propagating updates here.
  if (delegate_) {
    delegate_->RemoveObserver(this);
    delegate_ = NULL;
  }
  ConfigurationPolicyProvider::Shutdown();
}

void ProxyPolicyProvider::RefreshPolicies() {
  if (delegate_) {
    delegate_->RefreshPolicies();
  } else {
    // Subtle: if a RefreshPolicies() call comes after Shutdown() then the
    // current bundle should be served instead. This also does the right thing
    // if SetDelegate() was never called before.
    scoped_ptr<PolicyBundle> bundle(new PolicyBundle());
    bundle->CopyFrom(policies());
    UpdatePolicy(bundle.Pass());
  }
}

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

}  // namespace policy