OLD | NEW |
---|---|
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/chromeos/policy/device_cloud_policy_store_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
11 #include "chrome/browser/chromeos/login/startup_utils.h" | 11 #include "chrome/browser/chromeos/login/startup_utils.h" |
12 #include "chrome/browser/chromeos/policy/device_policy_decoder_chromeos.h" | 12 #include "chrome/browser/chromeos/policy/device_policy_decoder_chromeos.h" |
13 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 13 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
14 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 14 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
15 #include "components/ownership/owner_key_util.h" | 15 #include "components/ownership/owner_key_util.h" |
16 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | |
16 #include "policy/proto/device_management_backend.pb.h" | 17 #include "policy/proto/device_management_backend.pb.h" |
17 | 18 |
18 namespace em = enterprise_management; | 19 namespace em = enterprise_management; |
19 | 20 |
20 namespace policy { | 21 namespace policy { |
21 | 22 |
22 DeviceCloudPolicyStoreChromeOS::DeviceCloudPolicyStoreChromeOS( | 23 DeviceCloudPolicyStoreChromeOS::DeviceCloudPolicyStoreChromeOS( |
23 chromeos::DeviceSettingsService* device_settings_service, | 24 chromeos::DeviceSettingsService* device_settings_service, |
24 EnterpriseInstallAttributes* install_attributes, | 25 EnterpriseInstallAttributes* install_attributes, |
25 scoped_refptr<base::SequencedTaskRunner> background_task_runner) | 26 scoped_refptr<base::SequencedTaskRunner> background_task_runner) |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 validator->policy().Pass(), | 130 validator->policy().Pass(), |
130 base::Bind(&DeviceCloudPolicyStoreChromeOS::OnPolicyStored, | 131 base::Bind(&DeviceCloudPolicyStoreChromeOS::OnPolicyStored, |
131 weak_factory_.GetWeakPtr())); | 132 weak_factory_.GetWeakPtr())); |
132 } | 133 } |
133 | 134 |
134 void DeviceCloudPolicyStoreChromeOS::OnPolicyStored() { | 135 void DeviceCloudPolicyStoreChromeOS::OnPolicyStored() { |
135 UpdateFromService(); | 136 UpdateFromService(); |
136 } | 137 } |
137 | 138 |
138 void DeviceCloudPolicyStoreChromeOS::UpdateFromService() { | 139 void DeviceCloudPolicyStoreChromeOS::UpdateFromService() { |
139 if (!install_attributes_->IsEnterpriseDevice()) { | 140 const em::PolicyData* policy_data = device_settings_service_->policy_data(); |
141 const chromeos::DeviceSettingsService::Status status = | |
142 device_settings_service_->status(); | |
143 | |
144 const bool is_enterprise_managed = install_attributes_->IsEnterpriseDevice(); | |
145 bool is_or_was_consumer_managed = false; | |
146 if (policy_data) { | |
147 const ManagementMode management_mode = GetManagementMode(*policy_data); | |
148 if (management_mode == MANAGEMENT_MODE_CONSUMER_MANAGED || | |
149 (management_mode == MANAGEMENT_MODE_LOCAL_OWNER && | |
150 policy() && | |
151 GetManagementMode(*policy()) == MANAGEMENT_MODE_CONSUMER_MANAGED)) { | |
152 // The device is consumer-managed, or was consumer-managed and is now | |
153 // unmanaged. | |
154 is_or_was_consumer_managed = true; | |
155 } | |
156 } | |
157 | |
158 if (!is_enterprise_managed && !is_or_was_consumer_managed) { | |
140 status_ = STATUS_BAD_STATE; | 159 status_ = STATUS_BAD_STATE; |
141 NotifyStoreError(); | 160 NotifyStoreError(); |
142 return; | 161 return; |
143 } | 162 } |
144 | 163 |
145 // Once per session, validate internal consistency of enrollment state (DM | 164 // For enterprise devices, Once per session, validate internal consistency of |
Mattias Nissler (ping if slow)
2014/12/05 14:02:34
nit: once (lowercase)
davidyu
2014/12/05 14:08:41
Done.
| |
146 // token must be present on enrolled devices) and in case of failure set flag | 165 // enrollment state (DM token must be present on enrolled devices) and in case |
147 // to indicate that recovery is required. | 166 // of failure set flag to indicate that recovery is required. |
148 const chromeos::DeviceSettingsService::Status status = | 167 if (is_enterprise_managed) { |
149 device_settings_service_->status(); | 168 switch (status) { |
150 switch (status) { | 169 case chromeos::DeviceSettingsService::STORE_SUCCESS: |
151 case chromeos::DeviceSettingsService::STORE_SUCCESS: | 170 case chromeos::DeviceSettingsService::STORE_KEY_UNAVAILABLE: |
152 case chromeos::DeviceSettingsService::STORE_KEY_UNAVAILABLE: | 171 case chromeos::DeviceSettingsService::STORE_NO_POLICY: |
153 case chromeos::DeviceSettingsService::STORE_NO_POLICY: | 172 case chromeos::DeviceSettingsService::STORE_INVALID_POLICY: |
154 case chromeos::DeviceSettingsService::STORE_INVALID_POLICY: | 173 case chromeos::DeviceSettingsService::STORE_VALIDATION_ERROR: { |
155 case chromeos::DeviceSettingsService::STORE_VALIDATION_ERROR: { | 174 if (!enrollment_validation_done_) { |
156 if (!enrollment_validation_done_) { | 175 enrollment_validation_done_ = true; |
157 enrollment_validation_done_ = true; | 176 const bool has_dm_token = |
158 const bool has_dm_token = | 177 status == chromeos::DeviceSettingsService::STORE_SUCCESS && |
159 status == chromeos::DeviceSettingsService::STORE_SUCCESS && | 178 policy_data && |
160 device_settings_service_->policy_data() && | 179 policy_data->has_request_token(); |
161 device_settings_service_->policy_data()->has_request_token(); | |
162 | 180 |
163 // At the time LoginDisplayHostImpl decides whether enrollment flow is | 181 // At the time LoginDisplayHostImpl decides whether enrollment flow is |
164 // to be started, policy hasn't been read yet. To work around this, | 182 // to be started, policy hasn't been read yet. To work around this, |
165 // once the need for recovery is detected upon policy load, a flag is | 183 // once the need for recovery is detected upon policy load, a flag is |
166 // stored in prefs which is accessed by LoginDisplayHostImpl early | 184 // stored in prefs which is accessed by LoginDisplayHostImpl early |
167 // during (next) boot. | 185 // during (next) boot. |
168 if (!has_dm_token) { | 186 if (!has_dm_token) { |
169 LOG(ERROR) << "Device policy read on enrolled device yields " | 187 LOG(ERROR) << "Device policy read on enrolled device yields " |
170 << "no DM token! Status: " << status << "."; | 188 << "no DM token! Status: " << status << "."; |
171 chromeos::StartupUtils::MarkEnrollmentRecoveryRequired(); | 189 chromeos::StartupUtils::MarkEnrollmentRecoveryRequired(); |
190 } | |
191 UMA_HISTOGRAM_BOOLEAN("Enterprise.EnrolledPolicyHasDMToken", | |
192 has_dm_token); | |
172 } | 193 } |
173 UMA_HISTOGRAM_BOOLEAN("Enterprise.EnrolledPolicyHasDMToken", | 194 break; |
174 has_dm_token); | |
175 } | 195 } |
176 break; | 196 case chromeos::DeviceSettingsService::STORE_POLICY_ERROR: |
197 case chromeos::DeviceSettingsService::STORE_OPERATION_FAILED: | |
198 case chromeos::DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR: | |
199 // Do nothing for write errors or transient read errors. | |
200 break; | |
177 } | 201 } |
178 case chromeos::DeviceSettingsService::STORE_POLICY_ERROR: | |
179 case chromeos::DeviceSettingsService::STORE_OPERATION_FAILED: | |
180 case chromeos::DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR: | |
181 // Do nothing for write errors or transient read errors. | |
182 break; | |
183 } | 202 } |
184 | 203 |
185 switch (status) { | 204 switch (status) { |
186 case chromeos::DeviceSettingsService::STORE_SUCCESS: { | 205 case chromeos::DeviceSettingsService::STORE_SUCCESS: { |
187 status_ = STATUS_OK; | 206 status_ = STATUS_OK; |
188 policy_.reset(new em::PolicyData()); | 207 policy_.reset(new em::PolicyData()); |
189 if (device_settings_service_->policy_data()) | 208 if (policy_data) |
190 policy_->MergeFrom(*device_settings_service_->policy_data()); | 209 policy_->MergeFrom(*policy_data); |
191 | 210 |
192 PolicyMap new_policy_map; | 211 PolicyMap new_policy_map; |
193 if (is_managed()) { | 212 if (is_enterprise_managed && is_managed()) { |
194 DecodeDevicePolicy(*device_settings_service_->device_settings(), | 213 DecodeDevicePolicy(*device_settings_service_->device_settings(), |
195 &new_policy_map, install_attributes_); | 214 &new_policy_map, install_attributes_); |
196 } | 215 } |
197 policy_map_.Swap(&new_policy_map); | 216 policy_map_.Swap(&new_policy_map); |
198 | 217 |
199 NotifyStoreLoaded(); | 218 NotifyStoreLoaded(); |
200 return; | 219 return; |
201 } | 220 } |
202 case chromeos::DeviceSettingsService::STORE_KEY_UNAVAILABLE: | 221 case chromeos::DeviceSettingsService::STORE_KEY_UNAVAILABLE: |
203 status_ = STATUS_BAD_STATE; | 222 status_ = STATUS_BAD_STATE; |
204 break; | 223 break; |
205 case chromeos::DeviceSettingsService::STORE_POLICY_ERROR: | 224 case chromeos::DeviceSettingsService::STORE_POLICY_ERROR: |
206 case chromeos::DeviceSettingsService::STORE_OPERATION_FAILED: | 225 case chromeos::DeviceSettingsService::STORE_OPERATION_FAILED: |
207 status_ = STATUS_STORE_ERROR; | 226 status_ = STATUS_STORE_ERROR; |
208 break; | 227 break; |
209 case chromeos::DeviceSettingsService::STORE_NO_POLICY: | 228 case chromeos::DeviceSettingsService::STORE_NO_POLICY: |
210 case chromeos::DeviceSettingsService::STORE_INVALID_POLICY: | 229 case chromeos::DeviceSettingsService::STORE_INVALID_POLICY: |
211 case chromeos::DeviceSettingsService::STORE_VALIDATION_ERROR: | 230 case chromeos::DeviceSettingsService::STORE_VALIDATION_ERROR: |
212 case chromeos::DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR: | 231 case chromeos::DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR: |
213 status_ = STATUS_LOAD_ERROR; | 232 status_ = STATUS_LOAD_ERROR; |
214 break; | 233 break; |
215 } | 234 } |
216 | 235 |
217 NotifyStoreError(); | 236 NotifyStoreError(); |
218 } | 237 } |
219 | 238 |
220 } // namespace policy | 239 } // namespace policy |
OLD | NEW |