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

Side by Side Diff: chrome/browser/policy/forwarding_policy_provider.cc

Issue 60823003: Introduced a ForwardingPolicyProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, fixes Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 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/policy/forwarding_policy_provider.h"
6
7 #include "chrome/browser/policy/schema_map.h"
8
9 namespace policy {
10
11 ForwardingPolicyProvider::ForwardingPolicyProvider(
12 ConfigurationPolicyProvider* delegate)
13 : delegate_(delegate), state_(WAITING_FOR_REGISTRY_READY) {
14 delegate_->AddObserver(this);
15 // Serve the initial |delegate_| policies.
16 OnUpdatePolicy(delegate_);
17 }
18
19 ForwardingPolicyProvider::~ForwardingPolicyProvider() {
20 delegate_->RemoveObserver(this);
21 }
22
23 void ForwardingPolicyProvider::Init(SchemaRegistry* registry) {
24 ConfigurationPolicyProvider::Init(registry);
25 if (registry->IsReady())
bartfab (slow) 2013/11/11 14:40:08 Nit: #include "chrome/browser/policy/schema_regist
Joao da Silva 2013/11/12 15:26:33 Done.
26 OnSchemaRegistryReady();
27 }
28
29 bool ForwardingPolicyProvider::IsInitializationComplete(PolicyDomain domain)
30 const {
31 if (domain == POLICY_DOMAIN_CHROME)
32 return delegate_->IsInitializationComplete(domain);
33 // This provider keeps its own state for all the other domains.
34 return state_ == READY;
35 }
36
37 void ForwardingPolicyProvider::RefreshPolicies() {
38 delegate_->RefreshPolicies();
39 }
40
41 void ForwardingPolicyProvider::OnSchemaRegistryReady() {
42 DCHECK_EQ(WAITING_FOR_REGISTRY_READY, state_);
43 // This provider's registry is ready, meaning that it has all the initial
44 // components schemas; the delegate's registry should also see them now,
45 // since it's tracking the former.
46 // Asking the delegate to RefreshPolicies now means that the next
47 // OnUpdatePolicy from the delegate will have the initial policy for
48 // components.
49 if (!schema_map()->HasComponents()) {
50 // If there are no component registered for this provider then there's no
51 // need to reload.
52 state_ = READY;
53 OnUpdatePolicy(delegate_);
54 return;
55 }
56
57 state_ = WAITING_FOR_REFRESH;
58 RefreshPolicies();
59 }
60
61 void ForwardingPolicyProvider::OnSchemaRegistryUpdated(bool has_new_schemas) {
62 if (!has_new_schemas || state_ != READY)
63 return;
64 RefreshPolicies();
65 }
66
67 void ForwardingPolicyProvider::OnUpdatePolicy(
68 ConfigurationPolicyProvider* provider) {
69 DCHECK_EQ(delegate_, provider);
70
71 if (state_ == WAITING_FOR_REFRESH)
72 state_ = READY;
73
74 scoped_ptr<PolicyBundle> bundle(new PolicyBundle());
75 if (state_ == READY) {
76 bundle->CopyFrom(delegate_->policies());
77 schema_map()->FilterBundle(bundle.get());
78 } else {
79 // Always forward the Chrome policy, even if the components are not ready
80 // yet.
81 PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, "");
bartfab (slow) 2013/11/11 14:40:08 Nit: const - or simply construct it inline.
Joao da Silva 2013/11/12 15:26:33 Done.
82 bundle->Get(chrome_ns).CopyFrom(delegate_->policies().Get(chrome_ns));
83 }
84
85 UpdatePolicy(bundle.Pass());
86 }
87
88 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698