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

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

Issue 9111022: Removed ConfigurationPolicyType and extended PolicyMap. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 11 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 26 matching lines...) Expand all
37 observer_list_.AddObserver(observer); 37 observer_list_.AddObserver(observer);
38 } 38 }
39 39
40 void CloudPolicyCacheBase::RemoveObserver(Observer* observer) { 40 void CloudPolicyCacheBase::RemoveObserver(Observer* observer) {
41 observer_list_.RemoveObserver(observer); 41 observer_list_.RemoveObserver(observer);
42 } 42 }
43 43
44 void CloudPolicyCacheBase::Reset() { 44 void CloudPolicyCacheBase::Reset() {
45 last_policy_refresh_time_ = base::Time(); 45 last_policy_refresh_time_ = base::Time();
46 is_unmanaged_ = false; 46 is_unmanaged_ = false;
47 mandatory_policy_.Clear(); 47 policies_.Clear();
48 recommended_policy_.Clear();
49 public_key_version_.version = 0; 48 public_key_version_.version = 0;
50 public_key_version_.valid = false; 49 public_key_version_.valid = false;
51 InformNotifier(CloudPolicySubsystem::UNENROLLED, 50 InformNotifier(CloudPolicySubsystem::UNENROLLED,
52 CloudPolicySubsystem::NO_DETAILS); 51 CloudPolicySubsystem::NO_DETAILS);
53 } 52 }
54 53
55 bool CloudPolicyCacheBase::IsReady() { 54 bool CloudPolicyCacheBase::IsReady() {
56 return initialization_complete_; 55 return initialization_complete_;
57 } 56 }
58 57
59 const PolicyMap* CloudPolicyCacheBase::policy(PolicyLevel level) {
60 switch (level) {
61 case POLICY_LEVEL_MANDATORY:
62 return &mandatory_policy_;
63 case POLICY_LEVEL_RECOMMENDED:
64 return &recommended_policy_;
65 }
66 NOTREACHED();
67 return NULL;
68 }
69
70 bool CloudPolicyCacheBase::GetPublicKeyVersion(int* version) { 58 bool CloudPolicyCacheBase::GetPublicKeyVersion(int* version) {
71 if (public_key_version_.valid) 59 if (public_key_version_.valid)
72 *version = public_key_version_.version; 60 *version = public_key_version_.version;
73 61
74 return public_key_version_.valid; 62 return public_key_version_.valid;
75 } 63 }
76 64
77 bool CloudPolicyCacheBase::SetPolicyInternal( 65 bool CloudPolicyCacheBase::SetPolicyInternal(
78 const em::PolicyFetchResponse& policy, 66 const em::PolicyFetchResponse& policy,
79 base::Time* timestamp, 67 base::Time* timestamp,
80 bool check_for_timestamp_validity) { 68 bool check_for_timestamp_validity) {
81 DCHECK(CalledOnValidThread()); 69 DCHECK(CalledOnValidThread());
82 is_unmanaged_ = false; 70 is_unmanaged_ = false;
83 PolicyMap mandatory_policy; 71 PolicyMap policies;
84 PolicyMap recommended_policy;
85 base::Time temp_timestamp; 72 base::Time temp_timestamp;
86 PublicKeyVersion temp_public_key_version; 73 PublicKeyVersion temp_public_key_version;
87 bool ok = DecodePolicyResponse(policy, &mandatory_policy, &recommended_policy, 74 bool ok = DecodePolicyResponse(policy, &policies,
88 &temp_timestamp, &temp_public_key_version); 75 &temp_timestamp, &temp_public_key_version);
89 if (!ok) { 76 if (!ok) {
90 LOG(WARNING) << "Decoding policy data failed."; 77 LOG(WARNING) << "Decoding policy data failed.";
91 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchInvalidPolicy, 78 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchInvalidPolicy,
92 kMetricPolicySize); 79 kMetricPolicySize);
93 return false; 80 return false;
94 } 81 }
95 if (timestamp) { 82 if (timestamp) {
96 *timestamp = temp_timestamp; 83 *timestamp = temp_timestamp;
97 } 84 }
98 if (check_for_timestamp_validity && 85 if (check_for_timestamp_validity &&
99 temp_timestamp > base::Time::NowFromSystemTime()) { 86 temp_timestamp > base::Time::NowFromSystemTime()) {
100 LOG(WARNING) << "Rejected policy data, file is from the future."; 87 LOG(WARNING) << "Rejected policy data, file is from the future.";
101 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, 88 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy,
102 kMetricPolicyFetchTimestampInFuture, 89 kMetricPolicyFetchTimestampInFuture,
103 kMetricPolicySize); 90 kMetricPolicySize);
104 return false; 91 return false;
105 } 92 }
106 public_key_version_.version = temp_public_key_version.version; 93 public_key_version_.version = temp_public_key_version.version;
107 public_key_version_.valid = temp_public_key_version.valid; 94 public_key_version_.valid = temp_public_key_version.valid;
108 95
109 const bool new_policy_differs = 96 if (policies_.Equals(policies)) {
110 !mandatory_policy_.Equals(mandatory_policy) ||
111 !recommended_policy_.Equals(recommended_policy);
112 mandatory_policy_.Swap(&mandatory_policy);
113 recommended_policy_.Swap(&recommended_policy);
114
115 if (!new_policy_differs) {
116 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchNotModified, 97 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchNotModified,
117 kMetricPolicySize); 98 kMetricPolicySize);
118 } 99 }
119 100
101 policies_.Swap(&policies);
102
120 InformNotifier(CloudPolicySubsystem::SUCCESS, 103 InformNotifier(CloudPolicySubsystem::SUCCESS,
121 CloudPolicySubsystem::NO_DETAILS); 104 CloudPolicySubsystem::NO_DETAILS);
122 return true; 105 return true;
123 } 106 }
124 107
125 void CloudPolicyCacheBase::SetUnmanagedInternal(const base::Time& timestamp) { 108 void CloudPolicyCacheBase::SetUnmanagedInternal(const base::Time& timestamp) {
126 is_unmanaged_ = true; 109 is_unmanaged_ = true;
127 public_key_version_.valid = false; 110 public_key_version_.valid = false;
128 mandatory_policy_.Clear(); 111 policies_.Clear();
129 recommended_policy_.Clear();
130 last_policy_refresh_time_ = timestamp; 112 last_policy_refresh_time_ = timestamp;
131 } 113 }
132 114
133 void CloudPolicyCacheBase::SetReady() { 115 void CloudPolicyCacheBase::SetReady() {
134 initialization_complete_ = true; 116 initialization_complete_ = true;
135 NotifyObservers(); 117 NotifyObservers();
136 } 118 }
137 119
138 bool CloudPolicyCacheBase::DecodePolicyResponse( 120 bool CloudPolicyCacheBase::DecodePolicyResponse(
139 const em::PolicyFetchResponse& policy_response, 121 const em::PolicyFetchResponse& policy_response,
140 PolicyMap* mandatory, 122 PolicyMap* policies,
141 PolicyMap* recommended,
142 base::Time* timestamp, 123 base::Time* timestamp,
143 PublicKeyVersion* public_key_version) { 124 PublicKeyVersion* public_key_version) {
144 std::string data = policy_response.policy_data(); 125 std::string data = policy_response.policy_data();
145 em::PolicyData policy_data; 126 em::PolicyData policy_data;
146 if (!policy_data.ParseFromString(data)) { 127 if (!policy_data.ParseFromString(data)) {
147 LOG(WARNING) << "Failed to parse PolicyData protobuf."; 128 LOG(WARNING) << "Failed to parse PolicyData protobuf.";
148 return false; 129 return false;
149 } 130 }
150 if (timestamp) { 131 if (timestamp) {
151 *timestamp = base::Time::UnixEpoch() + 132 *timestamp = base::Time::UnixEpoch() +
152 base::TimeDelta::FromMilliseconds(policy_data.timestamp()); 133 base::TimeDelta::FromMilliseconds(policy_data.timestamp());
153 } 134 }
154 if (public_key_version) { 135 if (public_key_version) {
155 public_key_version->valid = policy_data.has_public_key_version(); 136 public_key_version->valid = policy_data.has_public_key_version();
156 if (public_key_version->valid) 137 if (public_key_version->valid)
157 public_key_version->version = policy_data.public_key_version(); 138 public_key_version->version = policy_data.public_key_version();
158 } 139 }
159 machine_id_missing_ = policy_data.valid_serial_number_missing(); 140 machine_id_missing_ = policy_data.valid_serial_number_missing();
160 141
161 return DecodePolicyData(policy_data, mandatory, recommended); 142 return DecodePolicyData(policy_data, policies);
162 } 143 }
163 144
164 void CloudPolicyCacheBase::NotifyObservers() { 145 void CloudPolicyCacheBase::NotifyObservers() {
165 if (IsReady()) 146 if (IsReady())
166 FOR_EACH_OBSERVER(Observer, observer_list_, OnCacheUpdate(this)); 147 FOR_EACH_OBSERVER(Observer, observer_list_, OnCacheUpdate(this));
167 } 148 }
168 149
169 void CloudPolicyCacheBase::InformNotifier( 150 void CloudPolicyCacheBase::InformNotifier(
170 CloudPolicySubsystem::PolicySubsystemState state, 151 CloudPolicySubsystem::PolicySubsystemState state,
171 CloudPolicySubsystem::ErrorDetails error_details) { 152 CloudPolicySubsystem::ErrorDetails error_details) {
172 // TODO(jkummerow): To obsolete this NULL-check, make all uses of 153 // TODO(jkummerow): To obsolete this NULL-check, make all uses of
173 // UserPolicyCache explicitly set a notifier using |set_policy_notifier()|. 154 // UserPolicyCache explicitly set a notifier using |set_policy_notifier()|.
174 if (notifier_) 155 if (notifier_)
175 notifier_->Inform(state, error_details, PolicyNotifier::POLICY_CACHE); 156 notifier_->Inform(state, error_details, PolicyNotifier::POLICY_CACHE);
176 } 157 }
177 158
178 } // namespace policy 159 } // 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