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

Side by Side Diff: chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.cc

Issue 400623002: Be more picky in triggering enrollment recovery. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Julian's comment. Created 6 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
« no previous file with comments | « chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 "chrome/browser/chromeos/settings/owner_key_util.h" 15 #include "chrome/browser/chromeos/settings/owner_key_util.h"
16 #include "policy/proto/device_management_backend.pb.h" 16 #include "policy/proto/device_management_backend.pb.h"
17 17
18 namespace em = enterprise_management; 18 namespace em = enterprise_management;
19 19
20 namespace policy { 20 namespace policy {
21 21
22 DeviceCloudPolicyStoreChromeOS::DeviceCloudPolicyStoreChromeOS( 22 DeviceCloudPolicyStoreChromeOS::DeviceCloudPolicyStoreChromeOS(
23 chromeos::DeviceSettingsService* device_settings_service, 23 chromeos::DeviceSettingsService* device_settings_service,
24 EnterpriseInstallAttributes* install_attributes, 24 EnterpriseInstallAttributes* install_attributes,
25 scoped_refptr<base::SequencedTaskRunner> background_task_runner) 25 scoped_refptr<base::SequencedTaskRunner> background_task_runner)
26 : device_settings_service_(device_settings_service), 26 : device_settings_service_(device_settings_service),
27 install_attributes_(install_attributes), 27 install_attributes_(install_attributes),
28 background_task_runner_(background_task_runner), 28 background_task_runner_(background_task_runner),
29 first_update_(true), 29 enrollment_validation_done_(false),
30 weak_factory_(this) { 30 weak_factory_(this) {
31 device_settings_service_->AddObserver(this); 31 device_settings_service_->AddObserver(this);
32 } 32 }
33 33
34 DeviceCloudPolicyStoreChromeOS::~DeviceCloudPolicyStoreChromeOS() { 34 DeviceCloudPolicyStoreChromeOS::~DeviceCloudPolicyStoreChromeOS() {
35 device_settings_service_->RemoveObserver(this); 35 device_settings_service_->RemoveObserver(this);
36 } 36 }
37 37
38 void DeviceCloudPolicyStoreChromeOS::Store( 38 void DeviceCloudPolicyStoreChromeOS::Store(
39 const em::PolicyFetchResponse& policy) { 39 const em::PolicyFetchResponse& policy) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 UpdateFromService(); 131 UpdateFromService();
132 } 132 }
133 133
134 void DeviceCloudPolicyStoreChromeOS::UpdateFromService() { 134 void DeviceCloudPolicyStoreChromeOS::UpdateFromService() {
135 if (!install_attributes_->IsEnterpriseDevice()) { 135 if (!install_attributes_->IsEnterpriseDevice()) {
136 status_ = STATUS_BAD_STATE; 136 status_ = STATUS_BAD_STATE;
137 NotifyStoreError(); 137 NotifyStoreError();
138 return; 138 return;
139 } 139 }
140 140
141 // Fill UMA histogram once per session. Skip temp validation error because it 141 // Once per session, validate internal consistency of enrollment state (DM
142 // is not a definitive result (policy load will be retried). 142 // token must be present on enrolled devices) and in case of failure set flag
143 // to indicate that recovery is required.
143 const chromeos::DeviceSettingsService::Status status = 144 const chromeos::DeviceSettingsService::Status status =
144 device_settings_service_->status(); 145 device_settings_service_->status();
145 if (first_update_ && 146 switch (status) {
146 status != chromeos::DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR) { 147 case chromeos::DeviceSettingsService::STORE_SUCCESS:
147 first_update_ = false; 148 case chromeos::DeviceSettingsService::STORE_KEY_UNAVAILABLE:
148 const bool has_dm_token = 149 case chromeos::DeviceSettingsService::STORE_NO_POLICY:
149 status == chromeos::DeviceSettingsService::STORE_SUCCESS && 150 case chromeos::DeviceSettingsService::STORE_INVALID_POLICY:
150 device_settings_service_->policy_data() && 151 case chromeos::DeviceSettingsService::STORE_VALIDATION_ERROR: {
151 device_settings_service_->policy_data()->has_request_token(); 152 if (!enrollment_validation_done_) {
153 enrollment_validation_done_ = true;
154 const bool has_dm_token =
155 status == chromeos::DeviceSettingsService::STORE_SUCCESS &&
156 device_settings_service_->policy_data() &&
157 device_settings_service_->policy_data()->has_request_token();
152 158
153 // At the time LoginDisplayHostImpl decides whether enrollment flow is to be 159 // At the time LoginDisplayHostImpl decides whether enrollment flow is
154 // started, policy hasn't been read yet, so LoginDisplayHostImpl is not in a 160 // to be started, policy hasn't been read yet. To work around this,
155 // position to decide whether recovery is required. To work around this, 161 // once the need for recovery is detected upon policy load, a flag is
156 // upon policy load on machines requiring recovery, a flag is stored in 162 // stored in prefs which is accessed by LoginDisplayHostImpl early
157 // prefs which is accessed by LoginDisplayHostImpl early during (next) boot. 163 // during (next) boot.
158 if (!has_dm_token) { 164 if (!has_dm_token) {
159 LOG(ERROR) << "Policy read on enrolled device yields no DM token! " 165 LOG(ERROR) << "Device policy read on enrolled device yields "
160 << "Status: " << status << "."; 166 << "no DM token! Status: " << status << ".";
161 chromeos::StartupUtils::MarkEnrollmentRecoveryRequired(); 167 chromeos::StartupUtils::MarkEnrollmentRecoveryRequired();
168 }
169 UMA_HISTOGRAM_BOOLEAN("Enterprise.EnrolledPolicyHasDMToken",
170 has_dm_token);
171 }
172 break;
162 } 173 }
163 UMA_HISTOGRAM_BOOLEAN("Enterprise.EnrolledPolicyHasDMToken", has_dm_token); 174 case chromeos::DeviceSettingsService::STORE_POLICY_ERROR:
175 case chromeos::DeviceSettingsService::STORE_OPERATION_FAILED:
176 case chromeos::DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR:
177 // Do nothing for write errors or transient read errors.
178 break;
164 } 179 }
165 180
166 switch (device_settings_service_->status()) { 181 switch (status) {
167 case chromeos::DeviceSettingsService::STORE_SUCCESS: { 182 case chromeos::DeviceSettingsService::STORE_SUCCESS: {
168 status_ = STATUS_OK; 183 status_ = STATUS_OK;
169 policy_.reset(new em::PolicyData()); 184 policy_.reset(new em::PolicyData());
170 if (device_settings_service_->policy_data()) 185 if (device_settings_service_->policy_data())
171 policy_->MergeFrom(*device_settings_service_->policy_data()); 186 policy_->MergeFrom(*device_settings_service_->policy_data());
172 187
173 PolicyMap new_policy_map; 188 PolicyMap new_policy_map;
174 if (is_managed()) { 189 if (is_managed()) {
175 DecodeDevicePolicy(*device_settings_service_->device_settings(), 190 DecodeDevicePolicy(*device_settings_service_->device_settings(),
176 &new_policy_map, install_attributes_); 191 &new_policy_map, install_attributes_);
(...skipping 15 matching lines...) Expand all
192 case chromeos::DeviceSettingsService::STORE_VALIDATION_ERROR: 207 case chromeos::DeviceSettingsService::STORE_VALIDATION_ERROR:
193 case chromeos::DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR: 208 case chromeos::DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR:
194 status_ = STATUS_LOAD_ERROR; 209 status_ = STATUS_LOAD_ERROR;
195 break; 210 break;
196 } 211 }
197 212
198 NotifyStoreError(); 213 NotifyStoreError();
199 } 214 }
200 215
201 } // namespace policy 216 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698