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

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

Issue 7147015: Move user cloud policy to BrowserProcess (was 6979011) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix unit_test include breakage Created 9 years, 5 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/policy/cloud_policy_cache_base.h" 5 #include "chrome/browser/policy/cloud_policy_cache_base.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/policy/configuration_policy_pref_store.h"
12 #include "chrome/browser/policy/policy_notifier.h" 11 #include "chrome/browser/policy/policy_notifier.h"
13 12
14 namespace policy { 13 namespace policy {
15 14
16 // A thin ConfigurationPolicyProvider implementation sitting on top of
17 // CloudPolicyCacheBase for hooking up with ConfigurationPolicyPrefStore.
18 class CloudPolicyCacheBase::CloudPolicyProvider
19 : public ConfigurationPolicyProvider {
20 public:
21 CloudPolicyProvider(const PolicyDefinitionList* policy_list,
22 CloudPolicyCacheBase* cache,
23 CloudPolicyCacheBase::PolicyLevel level)
24 : ConfigurationPolicyProvider(policy_list),
25 cache_(cache),
26 level_(level) {}
27 virtual ~CloudPolicyProvider() {}
28
29 virtual bool Provide(ConfigurationPolicyStoreInterface* store) {
30 if (level_ == POLICY_LEVEL_MANDATORY)
31 ApplyPolicyMap(&cache_->mandatory_policy_, store);
32 else if (level_ == POLICY_LEVEL_RECOMMENDED)
33 ApplyPolicyMap(&cache_->recommended_policy_, store);
34 return true;
35 }
36
37 virtual bool IsInitializationComplete() const {
38 return cache_->initialization_complete_;
39 }
40
41 virtual void AddObserver(ConfigurationPolicyProvider::Observer* observer) {
42 cache_->observer_list_.AddObserver(observer);
43 }
44 virtual void RemoveObserver(ConfigurationPolicyProvider::Observer* observer) {
45 cache_->observer_list_.RemoveObserver(observer);
46 }
47
48 private:
49 // The underlying policy cache.
50 CloudPolicyCacheBase* cache_;
51 // Policy level this provider will handle.
52 CloudPolicyCacheBase::PolicyLevel level_;
53
54 DISALLOW_COPY_AND_ASSIGN(CloudPolicyProvider);
55 };
56
57 CloudPolicyCacheBase::CloudPolicyCacheBase() 15 CloudPolicyCacheBase::CloudPolicyCacheBase()
58 : notifier_(NULL), 16 : notifier_(NULL),
59 initialization_complete_(false), 17 initialization_complete_(false),
60 is_unmanaged_(false) { 18 is_unmanaged_(false) {
61 public_key_version_.valid = false; 19 public_key_version_.valid = false;
62 managed_policy_provider_.reset(
63 new CloudPolicyProvider(
64 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
65 this,
66 POLICY_LEVEL_MANDATORY));
67 recommended_policy_provider_.reset(
68 new CloudPolicyProvider(
69 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
70 this,
71 POLICY_LEVEL_RECOMMENDED));
72 } 20 }
73 21
74 CloudPolicyCacheBase::~CloudPolicyCacheBase() { 22 CloudPolicyCacheBase::~CloudPolicyCacheBase() {
75 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer, 23 FOR_EACH_OBSERVER(Observer, observer_list_, OnCacheGoingAway(this));
76 observer_list_, OnProviderGoingAway()); 24 }
25
26 void CloudPolicyCacheBase::AddObserver(Observer* observer) {
27 observer_list_.AddObserver(observer);
28 }
29
30 void CloudPolicyCacheBase::RemoveObserver(Observer* observer) {
31 observer_list_.RemoveObserver(observer);
32 }
33
34 const PolicyMap* CloudPolicyCacheBase::policy(PolicyLevel level) {
35 switch (level) {
36 case POLICY_LEVEL_MANDATORY:
37 return &mandatory_policy_;
38 case POLICY_LEVEL_RECOMMENDED:
39 return &recommended_policy_;
40 }
41 NOTREACHED();
42 return NULL;
77 } 43 }
78 44
79 bool CloudPolicyCacheBase::GetPublicKeyVersion(int* version) { 45 bool CloudPolicyCacheBase::GetPublicKeyVersion(int* version) {
80 if (public_key_version_.valid) 46 if (public_key_version_.valid)
81 *version = public_key_version_.version; 47 *version = public_key_version_.version;
82 48
83 return public_key_version_.valid; 49 return public_key_version_.valid;
84 } 50 }
85 51
86 bool CloudPolicyCacheBase::SetPolicyInternal( 52 bool CloudPolicyCacheBase::SetPolicyInternal(
(...skipping 25 matching lines...) Expand all
112 public_key_version_.valid = temp_public_key_version.valid; 78 public_key_version_.valid = temp_public_key_version.valid;
113 79
114 const bool new_policy_differs = 80 const bool new_policy_differs =
115 !mandatory_policy_.Equals(mandatory_policy) || 81 !mandatory_policy_.Equals(mandatory_policy) ||
116 !recommended_policy_.Equals(recommended_policy); 82 !recommended_policy_.Equals(recommended_policy);
117 mandatory_policy_.Swap(&mandatory_policy); 83 mandatory_policy_.Swap(&mandatory_policy);
118 recommended_policy_.Swap(&recommended_policy); 84 recommended_policy_.Swap(&recommended_policy);
119 initialization_complete_ = true; 85 initialization_complete_ = true;
120 86
121 if (new_policy_differs || initialization_was_not_complete) { 87 if (new_policy_differs || initialization_was_not_complete) {
122 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer, 88 FOR_EACH_OBSERVER(Observer, observer_list_, OnCacheUpdate(this));
123 observer_list_, OnUpdatePolicy());
124 } 89 }
125 InformNotifier(CloudPolicySubsystem::SUCCESS, 90 InformNotifier(CloudPolicySubsystem::SUCCESS,
126 CloudPolicySubsystem::NO_DETAILS); 91 CloudPolicySubsystem::NO_DETAILS);
127 return true; 92 return true;
128 } 93 }
129 94
130 void CloudPolicyCacheBase::SetUnmanagedInternal(const base::Time& timestamp) { 95 void CloudPolicyCacheBase::SetUnmanagedInternal(const base::Time& timestamp) {
131 is_unmanaged_ = true; 96 is_unmanaged_ = true;
132 initialization_complete_ = true; 97 initialization_complete_ = true;
133 public_key_version_.valid = false; 98 public_key_version_.valid = false;
134 mandatory_policy_.Clear(); 99 mandatory_policy_.Clear();
135 recommended_policy_.Clear(); 100 recommended_policy_.Clear();
136 last_policy_refresh_time_ = timestamp; 101 last_policy_refresh_time_ = timestamp;
137 102
138 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer, 103 FOR_EACH_OBSERVER(Observer, observer_list_, OnCacheUpdate(this));
139 observer_list_, OnUpdatePolicy());
140 }
141
142 ConfigurationPolicyProvider* CloudPolicyCacheBase::GetManagedPolicyProvider() {
143 DCHECK(CalledOnValidThread());
144 return managed_policy_provider_.get();
145 }
146
147 ConfigurationPolicyProvider*
148 CloudPolicyCacheBase::GetRecommendedPolicyProvider() {
149 DCHECK(CalledOnValidThread());
150 return recommended_policy_provider_.get();
151 } 104 }
152 105
153 bool CloudPolicyCacheBase::DecodePolicyResponse( 106 bool CloudPolicyCacheBase::DecodePolicyResponse(
154 const em::PolicyFetchResponse& policy_response, 107 const em::PolicyFetchResponse& policy_response,
155 PolicyMap* mandatory, 108 PolicyMap* mandatory,
156 PolicyMap* recommended, 109 PolicyMap* recommended,
157 base::Time* timestamp, 110 base::Time* timestamp,
158 PublicKeyVersion* public_key_version) { 111 PublicKeyVersion* public_key_version) {
159 std::string data = policy_response.policy_data(); 112 std::string data = policy_response.policy_data();
160 em::PolicyData policy_data; 113 em::PolicyData policy_data;
(...skipping 17 matching lines...) Expand all
178 void CloudPolicyCacheBase::InformNotifier( 131 void CloudPolicyCacheBase::InformNotifier(
179 CloudPolicySubsystem::PolicySubsystemState state, 132 CloudPolicySubsystem::PolicySubsystemState state,
180 CloudPolicySubsystem::ErrorDetails error_details) { 133 CloudPolicySubsystem::ErrorDetails error_details) {
181 // TODO(jkummerow): To obsolete this NULL-check, make all uses of 134 // TODO(jkummerow): To obsolete this NULL-check, make all uses of
182 // UserPolicyCache explicitly set a notifier using |set_policy_notifier()|. 135 // UserPolicyCache explicitly set a notifier using |set_policy_notifier()|.
183 if (notifier_) 136 if (notifier_)
184 notifier_->Inform(state, error_details, PolicyNotifier::POLICY_CACHE); 137 notifier_->Inform(state, error_details, PolicyNotifier::POLICY_CACHE);
185 } 138 }
186 139
187 } // namespace policy 140 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud_policy_cache_base.h ('k') | chrome/browser/policy/cloud_policy_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698