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

Side by Side Diff: chrome/browser/policy/cloud_policy_provider.h

Issue 6979011: Move user cloud policy to BrowserProcess. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments by mnissler. Added unittest. Created 9 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_H_
7 #pragma once
8
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/scoped_vector.h"
11 #include "base/observer_list.h"
12 #include "chrome/browser/policy/cloud_policy_cache_base.h"
13 #include "chrome/browser/policy/configuration_policy_provider.h"
14 #include "chrome/browser/policy/policy_map.h"
15
16 namespace policy {
17
18 // A thin wrapper around CloudPolicyCacheBase. Proxies the notifications and
19 // delegates the actions to the underlying |cache_|. Also exposes the PolicyMap
20 // of |cache_|.
21 // The |cache_| is kept as a weak reference and can be exchanged at any point
22 // destroying the CloudPolicyProvider instance.
Mattias Nissler (ping if slow) 2011/05/31 14:14:19 destroying is not exactly exchanging the |cache_|
sfeuz 2011/06/03 08:30:35 I meant to write "[...] at any point WITHOUT destr
23 class CloudPolicyProvider : public ConfigurationPolicyProvider,
24 public CloudPolicyCacheBase::Observer {
25 public:
26 CloudPolicyProvider(const PolicyDefinitionList* policy_list,
27 CloudPolicyCacheBase::PolicyLevel level);
28 virtual ~CloudPolicyProvider();
29
30 // ConfigurationPolicyProvider implementation.
31 virtual bool Provide(ConfigurationPolicyStoreInterface* store) OVERRIDE;
32 virtual bool IsInitializationComplete() const OVERRIDE;
33 virtual void AddObserver(ConfigurationPolicyProvider::Observer* observer)
34 OVERRIDE;
35 virtual void RemoveObserver(ConfigurationPolicyProvider::Observer* observer)
36 OVERRIDE;
37
38 // CloudPolicyCacheBase::Observer implementation.
39 virtual void OnCacheUpdate() OVERRIDE;
40 virtual void OnCacheGoingAway() OVERRIDE;
41
42 // Exposes |policy_map| of the underlying |cache_|.
43 PolicyMap* policy_map();
Mattias Nissler (ping if slow) 2011/05/31 14:14:19 It feels wrong that you both expose the policy map
Joao da Silva 2011/05/31 14:50:23 Should this be const?
sfeuz 2011/06/03 08:30:35 Done. As we discussed offline.
44
45 // Sets another backend.
46 void set_cache(CloudPolicyCacheBase* cache);
47
48 private:
49 // The underlying policy cache. Can be NULL if currently none is present.
50 CloudPolicyCacheBase* cache_;
51 // Policy level this provider will handle.
52 CloudPolicyCacheBase::PolicyLevel level_;
53
54 // Provider observers that are registered with this provider.
55 ObserverList<ConfigurationPolicyProvider::Observer, true> observer_list_;
56
57 DISALLOW_COPY_AND_ASSIGN(CloudPolicyProvider);
58 };
59
60 // Combines multiple CloudPolicyProviders and applies them in the given order.
61 class CombiningCloudPolicyProvider : public ConfigurationPolicyProvider {
62 public:
63 explicit CombiningCloudPolicyProvider(
64 const PolicyDefinitionList* policy_list);
65 virtual ~CombiningCloudPolicyProvider();
66
67 // ConfigurationPolicyProvider implementation.
68 // Applies policy by applying the policies of the underlying
69 // CloudPolicyProviders in |cloud_policy_providers_| in the
70 // order they appear there. Early elements in |cloud_policy_providers_| take
71 // precedence. Handles special case for Proxy policy by marking all
72 // Proxy-related policies as applied as soon as one of them is applied.
73 // Returns true if we could apply at least one policy.
Mattias Nissler (ping if slow) 2011/05/31 14:14:19 That seems wrong. It's totally OK for no policy to
sfeuz 2011/06/03 08:30:35 I agree. Just returning true is probably the right
74 bool Provide(ConfigurationPolicyStoreInterface* store) OVERRIDE;
Mattias Nissler (ping if slow) 2011/05/31 14:14:19 virtual
sfeuz 2011/06/03 08:30:35 Done.
75
76 // Returns true if at least one CloudPolicyProvider in
77 // |cloud_policy_providers_| is initialized.
78 bool IsInitializationComplete() const OVERRIDE;
Mattias Nissler (ping if slow) 2011/05/31 14:14:19 virtual
Joao da Silva 2011/05/31 14:50:23 I'm not sure this is the correct behavior, instead
sfeuz 2011/06/03 08:30:35 Done.
sfeuz 2011/06/03 08:30:35 I now believe the correct behaviour is to always r
79 void AddObserver(ConfigurationPolicyProvider::Observer* observer) OVERRIDE;
Mattias Nissler (ping if slow) 2011/05/31 14:14:19 virtual
sfeuz 2011/06/03 08:30:35 Done.
80 void RemoveObserver(ConfigurationPolicyProvider::Observer* observer) OVERRIDE;
Mattias Nissler (ping if slow) 2011/05/31 14:14:19 virtual
sfeuz 2011/06/03 08:30:35 Done.
81
82 // Callbacks for CloudPolicyProviderWithObserver.
83 void OnUpdatePolicy(CloudPolicyProvider* cloud_policy_provider);
84 void OnProviderGoingAway(CloudPolicyProvider* cloud_policy_provider);
85
86 // Adds a new CloudPolicyProvider to the end of |cloud_policy_providers_|.
87 // Does not take ownership of |cloud_policy_provider|.
88 void AddCloudPolicyProvider(CloudPolicyProvider* cloud_policy_provider);
89
90 private:
91 // Wrapper around a CloudPolicyProvider to include the source in the
92 // callbacks. We need that to figure out which element in
93 // |cloud_policy_providers_| to remove if a CloudPolicyProvider calls
94 // OnProviderGoingAway.
Mattias Nissler (ping if slow) 2011/05/31 14:14:19 It seems like a adding an appropriate parameter to
sfeuz 2011/06/03 08:30:35 Added the parameter to the cache observer interfac
95 class CloudPolicyProviderWithObserver :
96 public ConfigurationPolicyProvider::Observer {
97 public:
98 CloudPolicyProviderWithObserver(
99 CombiningCloudPolicyProvider* combining_cloud_policy_provider,
100 CloudPolicyProvider* cloud_policy_provider) :
101 combining_cloud_policy_provider_(combining_cloud_policy_provider),
102 cloud_policy_provider_(cloud_policy_provider) {
103 DCHECK(combining_cloud_policy_provider_ && cloud_policy_provider_);
104 cloud_policy_provider_->AddObserver(this);
105 }
106 ~CloudPolicyProviderWithObserver() {
107 if (cloud_policy_provider_) {
108 cloud_policy_provider_->RemoveObserver(this);
109 cloud_policy_provider_ = NULL;
110 }
111 }
112 virtual void OnUpdatePolicy() {
113 combining_cloud_policy_provider_->OnUpdatePolicy(
114 cloud_policy_provider_);
115 }
116 virtual void OnProviderGoingAway() {
117 combining_cloud_policy_provider_->OnProviderGoingAway(
118 cloud_policy_provider_);
119 // Normally our dtor is called on removal from |cloud_policy_providers_|,
120 // but just in case we are still active remove us as Observer.
121 if (cloud_policy_provider_) {
122 cloud_policy_provider_->RemoveObserver(this);
123 cloud_policy_provider_ = NULL;
124 }
125 }
126 CloudPolicyProvider* cloud_policy_provider() const {
127 return cloud_policy_provider_;
128 }
129
130 private:
131 CombiningCloudPolicyProvider* combining_cloud_policy_provider_;
132 CloudPolicyProvider* cloud_policy_provider_;
133
134 DISALLOW_COPY_AND_ASSIGN(CloudPolicyProviderWithObserver);
135 };
136
137 // CloudPolicyProviders which are combined by this instance of
138 // CombiningCoudPolicyProvider. Order dependant.
Mattias Nissler (ping if slow) 2011/05/31 14:14:19 "Order dependant" conveys to me: There is somethin
sfeuz 2011/06/03 08:30:35 Was explained in Provide.
139 typedef ScopedVector<CloudPolicyProviderWithObserver> ListType;
140 ListType cloud_policy_providers_;
141
142 // Provider observers that are registered with this provider.
143 ObserverList<ConfigurationPolicyProvider::Observer, true> observer_list_;
144
145 DISALLOW_COPY_AND_ASSIGN(CombiningCloudPolicyProvider);
146 };
147
148 } // namespace policy
149
150 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698