Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: components/policy/core/common/proxy_policy_provider.cc

Issue 1304843004: Add source column to chrome://policy showing the origins of policies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/policy/core/common/proxy_policy_provider.h" 5 #include "components/policy/core/common/proxy_policy_provider.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "components/policy/core/common/policy_bundle.h" 9 #include "components/policy/core/common/policy_bundle.h"
10 10
11 namespace policy { 11 namespace policy {
12 12
13 ProxyPolicyProvider::ProxyPolicyProvider() : delegate_(NULL) {} 13 ProxyPolicyProvider::ProxyPolicyProvider() : delegate_(NULL) {}
14 14
15 ProxyPolicyProvider::~ProxyPolicyProvider() { 15 ProxyPolicyProvider::~ProxyPolicyProvider() {
16 DCHECK(!delegate_); 16 DCHECK(!delegate_);
17 } 17 }
18 18
19 void ProxyPolicyProvider::SetDelegate(ConfigurationPolicyProvider* delegate) { 19 void ProxyPolicyProvider::SetDelegate(ConfigurationPolicyProvider* delegate) {
20 if (delegate_) 20 if (delegate_)
21 delegate_->RemoveObserver(this); 21 delegate_->RemoveObserver(this);
22 delegate_ = delegate; 22 delegate_ = delegate;
23 if (delegate_) { 23 if (delegate_) {
24 source_ = delegate_->source();
24 delegate_->AddObserver(this); 25 delegate_->AddObserver(this);
25 OnUpdatePolicy(delegate_); 26 OnUpdatePolicy(delegate_);
26 } else { 27 } else {
27 UpdatePolicy(scoped_ptr<PolicyBundle>(new PolicyBundle())); 28 UpdatePolicy(scoped_ptr<PolicyBundle>(new PolicyBundle()));
28 } 29 }
29 } 30 }
30 31
31 void ProxyPolicyProvider::Shutdown() { 32 void ProxyPolicyProvider::Shutdown() {
32 // Note: the delegate is not owned by the proxy provider, so this call is not 33 // 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 // forwarded. The same applies for the Init() call.
34 // Just drop the delegate without propagating updates here. 35 // Just drop the delegate without propagating updates here.
35 if (delegate_) { 36 if (delegate_) {
36 delegate_->RemoveObserver(this); 37 delegate_->RemoveObserver(this);
37 delegate_ = NULL; 38 delegate_ = NULL;
39 source_ = POLICY_SOURCE_UNKNOWN;
bartfab (slow) 2015/09/14 14:42:27 Nit 1: #include "components/policy/core/common/pol
fhorschig 2015/09/16 13:52:05 Done.
38 } 40 }
39 ConfigurationPolicyProvider::Shutdown(); 41 ConfigurationPolicyProvider::Shutdown();
40 } 42 }
41 43
42 void ProxyPolicyProvider::RefreshPolicies() { 44 void ProxyPolicyProvider::RefreshPolicies() {
43 if (delegate_) { 45 if (delegate_) {
44 delegate_->RefreshPolicies(); 46 delegate_->RefreshPolicies();
45 } else { 47 } else {
46 // Subtle: if a RefreshPolicies() call comes after Shutdown() then the 48 // Subtle: if a RefreshPolicies() call comes after Shutdown() then the
47 // current bundle should be served instead. This also does the right thing 49 // current bundle should be served instead. This also does the right thing
48 // if SetDelegate() was never called before. 50 // if SetDelegate() was never called before.
49 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); 51 scoped_ptr<PolicyBundle> bundle(new PolicyBundle());
50 bundle->CopyFrom(policies()); 52 bundle->CopyFrom(policies());
51 UpdatePolicy(bundle.Pass()); 53 UpdatePolicy(bundle.Pass());
52 } 54 }
53 } 55 }
54 56
55 void ProxyPolicyProvider::OnUpdatePolicy( 57 void ProxyPolicyProvider::OnUpdatePolicy(
56 ConfigurationPolicyProvider* provider) { 58 ConfigurationPolicyProvider* provider) {
57 DCHECK_EQ(delegate_, provider); 59 DCHECK_EQ(delegate_, provider);
58 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); 60 scoped_ptr<PolicyBundle> bundle(new PolicyBundle());
59 bundle->CopyFrom(delegate_->policies()); 61 bundle->CopyFrom(delegate_->policies());
60 UpdatePolicy(bundle.Pass()); 62 UpdatePolicy(bundle.Pass());
61 } 63 }
62 64
63 } // namespace policy 65 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698