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() { |
140 const em::PolicyData* policy_data = device_settings_service_->policy_data(); | |
141 if (policy_data) { | |
142 const ManagementMode management_mode = GetManagementMode(*policy_data); | |
143 if (management_mode == MANAGEMENT_MODE_CONSUMER_MANAGED || | |
144 (management_mode == MANAGEMENT_MODE_LOCAL_OWNER && | |
145 policy() && | |
146 GetManagementMode(*policy()) == MANAGEMENT_MODE_CONSUMER_MANAGED)) { | |
147 // For consumer-managed devices, or devices that were consumer-managed | |
148 // and are now unmanaged, we clear the policy data and set the status to | |
149 // success. The management mode is propagated so that the store knows if | |
150 // it is consumer-managed. | |
151 policy_.reset(new em::PolicyData()); | |
Mattias Nissler (ping if slow)
2014/12/05 12:28:37
Why can't you just copy device_settings_service_->
| |
152 policy_->set_management_mode(policy_data->management_mode()); | |
153 PolicyMap new_policy_map; | |
154 policy_map_.Swap(&new_policy_map); | |
Mattias Nissler (ping if slow)
2014/12/05 12:28:37
Instead of swapping in an empty map, you could jus
| |
155 status_ = STATUS_OK; | |
156 NotifyStoreLoaded(); | |
157 return; | |
158 } | |
159 } | |
160 | |
139 if (!install_attributes_->IsEnterpriseDevice()) { | 161 if (!install_attributes_->IsEnterpriseDevice()) { |
140 status_ = STATUS_BAD_STATE; | 162 status_ = STATUS_BAD_STATE; |
141 NotifyStoreError(); | 163 NotifyStoreError(); |
142 return; | 164 return; |
143 } | 165 } |
144 | 166 |
145 // Once per session, validate internal consistency of enrollment state (DM | 167 // Once per session, validate internal consistency of enrollment state (DM |
146 // token must be present on enrolled devices) and in case of failure set flag | 168 // token must be present on enrolled devices) and in case of failure set flag |
147 // to indicate that recovery is required. | 169 // to indicate that recovery is required. |
148 const chromeos::DeviceSettingsService::Status status = | 170 const chromeos::DeviceSettingsService::Status status = |
149 device_settings_service_->status(); | 171 device_settings_service_->status(); |
150 switch (status) { | 172 switch (status) { |
151 case chromeos::DeviceSettingsService::STORE_SUCCESS: | 173 case chromeos::DeviceSettingsService::STORE_SUCCESS: |
152 case chromeos::DeviceSettingsService::STORE_KEY_UNAVAILABLE: | 174 case chromeos::DeviceSettingsService::STORE_KEY_UNAVAILABLE: |
153 case chromeos::DeviceSettingsService::STORE_NO_POLICY: | 175 case chromeos::DeviceSettingsService::STORE_NO_POLICY: |
154 case chromeos::DeviceSettingsService::STORE_INVALID_POLICY: | 176 case chromeos::DeviceSettingsService::STORE_INVALID_POLICY: |
155 case chromeos::DeviceSettingsService::STORE_VALIDATION_ERROR: { | 177 case chromeos::DeviceSettingsService::STORE_VALIDATION_ERROR: { |
156 if (!enrollment_validation_done_) { | 178 if (!enrollment_validation_done_) { |
157 enrollment_validation_done_ = true; | 179 enrollment_validation_done_ = true; |
158 const bool has_dm_token = | 180 const bool has_dm_token = |
159 status == chromeos::DeviceSettingsService::STORE_SUCCESS && | 181 status == chromeos::DeviceSettingsService::STORE_SUCCESS && |
160 device_settings_service_->policy_data() && | 182 policy_data && |
161 device_settings_service_->policy_data()->has_request_token(); | 183 policy_data->has_request_token(); |
162 | 184 |
163 // At the time LoginDisplayHostImpl decides whether enrollment flow is | 185 // At the time LoginDisplayHostImpl decides whether enrollment flow is |
164 // to be started, policy hasn't been read yet. To work around this, | 186 // 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 | 187 // once the need for recovery is detected upon policy load, a flag is |
166 // stored in prefs which is accessed by LoginDisplayHostImpl early | 188 // stored in prefs which is accessed by LoginDisplayHostImpl early |
167 // during (next) boot. | 189 // during (next) boot. |
168 if (!has_dm_token) { | 190 if (!has_dm_token) { |
169 LOG(ERROR) << "Device policy read on enrolled device yields " | 191 LOG(ERROR) << "Device policy read on enrolled device yields " |
170 << "no DM token! Status: " << status << "."; | 192 << "no DM token! Status: " << status << "."; |
171 chromeos::StartupUtils::MarkEnrollmentRecoveryRequired(); | 193 chromeos::StartupUtils::MarkEnrollmentRecoveryRequired(); |
172 } | 194 } |
173 UMA_HISTOGRAM_BOOLEAN("Enterprise.EnrolledPolicyHasDMToken", | 195 UMA_HISTOGRAM_BOOLEAN("Enterprise.EnrolledPolicyHasDMToken", |
174 has_dm_token); | 196 has_dm_token); |
175 } | 197 } |
176 break; | 198 break; |
177 } | 199 } |
178 case chromeos::DeviceSettingsService::STORE_POLICY_ERROR: | 200 case chromeos::DeviceSettingsService::STORE_POLICY_ERROR: |
179 case chromeos::DeviceSettingsService::STORE_OPERATION_FAILED: | 201 case chromeos::DeviceSettingsService::STORE_OPERATION_FAILED: |
180 case chromeos::DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR: | 202 case chromeos::DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR: |
181 // Do nothing for write errors or transient read errors. | 203 // Do nothing for write errors or transient read errors. |
182 break; | 204 break; |
183 } | 205 } |
184 | 206 |
185 switch (status) { | 207 switch (status) { |
186 case chromeos::DeviceSettingsService::STORE_SUCCESS: { | 208 case chromeos::DeviceSettingsService::STORE_SUCCESS: { |
187 status_ = STATUS_OK; | 209 status_ = STATUS_OK; |
188 policy_.reset(new em::PolicyData()); | 210 policy_.reset(new em::PolicyData()); |
189 if (device_settings_service_->policy_data()) | 211 if (policy_data) |
190 policy_->MergeFrom(*device_settings_service_->policy_data()); | 212 policy_->MergeFrom(*policy_data); |
191 | 213 |
192 PolicyMap new_policy_map; | 214 PolicyMap new_policy_map; |
193 if (is_managed()) { | 215 if (is_managed()) { |
194 DecodeDevicePolicy(*device_settings_service_->device_settings(), | 216 DecodeDevicePolicy(*device_settings_service_->device_settings(), |
195 &new_policy_map, install_attributes_); | 217 &new_policy_map, install_attributes_); |
196 } | 218 } |
197 policy_map_.Swap(&new_policy_map); | 219 policy_map_.Swap(&new_policy_map); |
198 | 220 |
199 NotifyStoreLoaded(); | 221 NotifyStoreLoaded(); |
200 return; | 222 return; |
(...skipping 10 matching lines...) Expand all Loading... | |
211 case chromeos::DeviceSettingsService::STORE_VALIDATION_ERROR: | 233 case chromeos::DeviceSettingsService::STORE_VALIDATION_ERROR: |
212 case chromeos::DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR: | 234 case chromeos::DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR: |
213 status_ = STATUS_LOAD_ERROR; | 235 status_ = STATUS_LOAD_ERROR; |
214 break; | 236 break; |
215 } | 237 } |
216 | 238 |
217 NotifyStoreError(); | 239 NotifyStoreError(); |
218 } | 240 } |
219 | 241 |
220 } // namespace policy | 242 } // namespace policy |
OLD | NEW |