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/policy/device_policy_decoder_chromeos.h" | 12 #include "chrome/browser/chromeos/policy/device_policy_decoder_chromeos.h" |
12 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 13 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
13 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 14 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
14 #include "chrome/browser/chromeos/settings/owner_key_util.h" | 15 #include "chrome/browser/chromeos/settings/owner_key_util.h" |
15 #include "policy/proto/device_management_backend.pb.h" | 16 #include "policy/proto/device_management_backend.pb.h" |
16 | 17 |
17 namespace em = enterprise_management; | 18 namespace em = enterprise_management; |
18 | 19 |
19 namespace policy { | 20 namespace policy { |
20 | 21 |
21 DeviceCloudPolicyStoreChromeOS::DeviceCloudPolicyStoreChromeOS( | 22 DeviceCloudPolicyStoreChromeOS::DeviceCloudPolicyStoreChromeOS( |
22 chromeos::DeviceSettingsService* device_settings_service, | 23 chromeos::DeviceSettingsService* device_settings_service, |
23 EnterpriseInstallAttributes* install_attributes, | 24 EnterpriseInstallAttributes* install_attributes, |
24 scoped_refptr<base::SequencedTaskRunner> background_task_runner) | 25 scoped_refptr<base::SequencedTaskRunner> background_task_runner) |
25 : device_settings_service_(device_settings_service), | 26 : device_settings_service_(device_settings_service), |
26 install_attributes_(install_attributes), | 27 install_attributes_(install_attributes), |
27 background_task_runner_(background_task_runner), | 28 background_task_runner_(background_task_runner), |
28 uma_done_(false), | 29 first_update_(true), |
29 weak_factory_(this) { | 30 weak_factory_(this) { |
30 device_settings_service_->AddObserver(this); | 31 device_settings_service_->AddObserver(this); |
31 } | 32 } |
32 | 33 |
33 DeviceCloudPolicyStoreChromeOS::~DeviceCloudPolicyStoreChromeOS() { | 34 DeviceCloudPolicyStoreChromeOS::~DeviceCloudPolicyStoreChromeOS() { |
34 device_settings_service_->RemoveObserver(this); | 35 device_settings_service_->RemoveObserver(this); |
35 } | 36 } |
36 | 37 |
37 void DeviceCloudPolicyStoreChromeOS::Store( | 38 void DeviceCloudPolicyStoreChromeOS::Store( |
38 const em::PolicyFetchResponse& policy) { | 39 const em::PolicyFetchResponse& policy) { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 if (!install_attributes_->IsEnterpriseDevice()) { | 135 if (!install_attributes_->IsEnterpriseDevice()) { |
135 status_ = STATUS_BAD_STATE; | 136 status_ = STATUS_BAD_STATE; |
136 NotifyStoreError(); | 137 NotifyStoreError(); |
137 return; | 138 return; |
138 } | 139 } |
139 | 140 |
140 // Fill UMA histogram once per session. Skip temp validation error because it | 141 // Fill UMA histogram once per session. Skip temp validation error because it |
141 // is not a definitive result (policy load will be retried). | 142 // is not a definitive result (policy load will be retried). |
142 const chromeos::DeviceSettingsService::Status status = | 143 const chromeos::DeviceSettingsService::Status status = |
143 device_settings_service_->status(); | 144 device_settings_service_->status(); |
144 if (!uma_done_ && | 145 if (first_update_ && |
145 status != chromeos::DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR) { | 146 status != chromeos::DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR) { |
146 uma_done_ = true; | 147 first_update_ = false; |
147 const bool has_dm_token = | 148 const bool has_dm_token = |
148 status == chromeos::DeviceSettingsService::STORE_SUCCESS && | 149 status == chromeos::DeviceSettingsService::STORE_SUCCESS && |
149 device_settings_service_->policy_data() && | 150 device_settings_service_->policy_data() && |
150 device_settings_service_->policy_data()->has_request_token(); | 151 device_settings_service_->policy_data()->has_request_token(); |
| 152 |
| 153 // At the time LoginDisplayHostImpl decides whether enrollment flow is to be |
| 154 // started, policy hasn't been read yet, so LoginDisplayHostImpl is not in a |
| 155 // position to decide whether recovery is required. To work around this, |
| 156 // upon policy load on machines requiring recovery, a flag is stored in |
| 157 // prefs which is accessed by LoginDisplayHostImpl early during (next) boot. |
| 158 if (!has_dm_token) { |
| 159 LOG(ERROR) << "Policy read on enrolled device yields no DM token! " |
| 160 << "Status: " << status << "."; |
| 161 chromeos::StartupUtils::MarkEnrollmentRecoveryRequired(); |
| 162 } |
151 UMA_HISTOGRAM_BOOLEAN("Enterprise.EnrolledPolicyHasDMToken", has_dm_token); | 163 UMA_HISTOGRAM_BOOLEAN("Enterprise.EnrolledPolicyHasDMToken", has_dm_token); |
152 LOG_IF(ERROR, !has_dm_token) | |
153 << "Policy read on enrolled device yields no DM token! " | |
154 << "Status: " << status << "."; | |
155 } | 164 } |
156 | 165 |
157 switch (device_settings_service_->status()) { | 166 switch (device_settings_service_->status()) { |
158 case chromeos::DeviceSettingsService::STORE_SUCCESS: { | 167 case chromeos::DeviceSettingsService::STORE_SUCCESS: { |
159 status_ = STATUS_OK; | 168 status_ = STATUS_OK; |
160 policy_.reset(new em::PolicyData()); | 169 policy_.reset(new em::PolicyData()); |
161 if (device_settings_service_->policy_data()) | 170 if (device_settings_service_->policy_data()) |
162 policy_->MergeFrom(*device_settings_service_->policy_data()); | 171 policy_->MergeFrom(*device_settings_service_->policy_data()); |
163 | 172 |
164 PolicyMap new_policy_map; | 173 PolicyMap new_policy_map; |
(...skipping 18 matching lines...) Expand all Loading... |
183 case chromeos::DeviceSettingsService::STORE_VALIDATION_ERROR: | 192 case chromeos::DeviceSettingsService::STORE_VALIDATION_ERROR: |
184 case chromeos::DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR: | 193 case chromeos::DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR: |
185 status_ = STATUS_LOAD_ERROR; | 194 status_ = STATUS_LOAD_ERROR; |
186 break; | 195 break; |
187 } | 196 } |
188 | 197 |
189 NotifyStoreError(); | 198 NotifyStoreError(); |
190 } | 199 } |
191 | 200 |
192 } // namespace policy | 201 } // namespace policy |
OLD | NEW |