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

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

Issue 2771803003: Don't start FRE from the login screen (Closed)
Patch Set: Improve comments Created 3 years, 8 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
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/auto_enrollment_client.h" 5 #include "chrome/browser/chromeos/policy/auto_enrollment_client.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/guid.h" 10 #include "base/guid.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 return std::string(); 71 return std::string();
72 case em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_REQUESTED: 72 case em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_REQUESTED:
73 return kDeviceStateRestoreModeReEnrollmentRequested; 73 return kDeviceStateRestoreModeReEnrollmentRequested;
74 case em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_ENFORCED: 74 case em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_ENFORCED:
75 return kDeviceStateRestoreModeReEnrollmentEnforced; 75 return kDeviceStateRestoreModeReEnrollmentEnforced;
76 case em::DeviceStateRetrievalResponse::RESTORE_MODE_DISABLED: 76 case em::DeviceStateRetrievalResponse::RESTORE_MODE_DISABLED:
77 return kDeviceStateRestoreModeDisabled; 77 return kDeviceStateRestoreModeDisabled;
78 } 78 }
79 79
80 // Return is required to avoid compiler warning. 80 // Return is required to avoid compiler warning.
81 NOTREACHED() << "Bad restore mode " << restore_mode; 81 NOTREACHED() << "Bad restore_mode=" << restore_mode;
82 return std::string(); 82 return std::string();
83 } 83 }
84 84
85 } // namespace 85 } // namespace
86 86
87 AutoEnrollmentClient::AutoEnrollmentClient( 87 AutoEnrollmentClient::AutoEnrollmentClient(
88 const ProgressCallback& callback, 88 const ProgressCallback& callback,
89 DeviceManagementService* service, 89 DeviceManagementService* service,
90 PrefService* local_state, 90 PrefService* local_state,
91 scoped_refptr<net::URLRequestContextGetter> system_request_context, 91 scoped_refptr<net::URLRequestContextGetter> system_request_context,
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 has_server_state_ = has_server_state; 183 has_server_state_ = has_server_state;
184 return true; 184 return true;
185 } 185 }
186 186
187 bool AutoEnrollmentClient::RetryStep() { 187 bool AutoEnrollmentClient::RetryStep() {
188 // If there is a pending request job, let it finish. 188 // If there is a pending request job, let it finish.
189 if (request_job_) 189 if (request_job_)
190 return true; 190 return true;
191 191
192 if (GetCachedDecision()) { 192 if (GetCachedDecision()) {
193 VLOG(1) << "Cached: has_state=" << has_server_state_;
193 // The bucket download check has completed already. If it came back 194 // The bucket download check has completed already. If it came back
194 // positive, then device state should be (re-)downloaded. 195 // positive, then device state should be (re-)downloaded.
195 if (has_server_state_) { 196 if (has_server_state_) {
196 if (!device_state_available_) { 197 if (!device_state_available_) {
197 SendDeviceStateRequest(); 198 SendDeviceStateRequest();
198 return true; 199 return true;
199 } 200 }
200 } 201 }
201 } else { 202 } else {
202 // Start bucket download. 203 // Start bucket download.
(...skipping 12 matching lines...) Expand all
215 progress_callback_.Run(state_); 216 progress_callback_.Run(state_);
216 } 217 }
217 } 218 }
218 219
219 void AutoEnrollmentClient::NextStep() { 220 void AutoEnrollmentClient::NextStep() {
220 if (RetryStep()) 221 if (RetryStep())
221 return; 222 return;
222 223
223 // Protocol finished successfully, report result. 224 // Protocol finished successfully, report result.
224 const RestoreMode restore_mode = GetRestoreMode(); 225 const RestoreMode restore_mode = GetRestoreMode();
225 if (restore_mode == RESTORE_MODE_REENROLLMENT_REQUESTED || 226 switch (restore_mode) {
226 restore_mode == RESTORE_MODE_REENROLLMENT_ENFORCED) { 227 case RESTORE_MODE_NONE:
227 ReportProgress(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT); 228 case RESTORE_MODE_DISABLED:
228 } else { 229 ReportProgress(AUTO_ENROLLMENT_STATE_NO_ENROLLMENT);
229 ReportProgress(AUTO_ENROLLMENT_STATE_NO_ENROLLMENT); 230 break;
231 case RESTORE_MODE_REENROLLMENT_REQUESTED:
232 case RESTORE_MODE_REENROLLMENT_ENFORCED:
233 ReportProgress(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT);
234 break;
230 } 235 }
231 } 236 }
232 237
233 void AutoEnrollmentClient::SendBucketDownloadRequest() { 238 void AutoEnrollmentClient::SendBucketDownloadRequest() {
234 // Only power-of-2 moduli are supported for now. These are computed by taking 239 // Only power-of-2 moduli are supported for now. These are computed by taking
235 // the lower |current_power_| bits of the hash. 240 // the lower |current_power_| bits of the hash.
236 uint64_t remainder = 0; 241 uint64_t remainder = 0;
237 for (int i = 0; 8 * i < current_power_; ++i) { 242 for (int i = 0; 8 * i < current_power_; ++i) {
238 uint64_t byte = server_backed_state_key_hash_[31 - i] & 0xff; 243 uint64_t byte = server_backed_state_key_hash_[31 - i] & 0xff;
239 remainder = remainder | (byte << (8 * i)); 244 remainder = remainder | (byte << (8 * i));
240 } 245 }
241 remainder = remainder & ((UINT64_C(1) << current_power_) - 1); 246 remainder = remainder & ((UINT64_C(1) << current_power_) - 1);
242 247
243 ReportProgress(AUTO_ENROLLMENT_STATE_PENDING); 248 ReportProgress(AUTO_ENROLLMENT_STATE_PENDING);
244 249
250 VLOG(1) << "Request bucket #" << remainder;
245 request_job_.reset( 251 request_job_.reset(
246 device_management_service_->CreateJob( 252 device_management_service_->CreateJob(
247 DeviceManagementRequestJob::TYPE_AUTO_ENROLLMENT, 253 DeviceManagementRequestJob::TYPE_AUTO_ENROLLMENT,
248 request_context_.get())); 254 request_context_.get()));
249 request_job_->SetClientID(device_id_); 255 request_job_->SetClientID(device_id_);
250 em::DeviceAutoEnrollmentRequest* request = 256 em::DeviceAutoEnrollmentRequest* request =
251 request_job_->GetRequest()->mutable_auto_enrollment_request(); 257 request_job_->GetRequest()->mutable_auto_enrollment_request();
252 request->set_remainder(remainder); 258 request->set_remainder(remainder);
253 request->set_modulus(INT64_C(1) << current_power_); 259 request->set_modulus(INT64_C(1) << current_power_);
254 request_job_->Start( 260 request_job_->Start(
255 base::Bind(&AutoEnrollmentClient::HandleRequestCompletion, 261 base::Bind(&AutoEnrollmentClient::HandleRequestCompletion,
256 base::Unretained(this), 262 base::Unretained(this),
257 &AutoEnrollmentClient::OnBucketDownloadRequestCompletion)); 263 &AutoEnrollmentClient::OnBucketDownloadRequestCompletion));
258 } 264 }
259 265
260 void AutoEnrollmentClient::SendDeviceStateRequest() { 266 void AutoEnrollmentClient::SendDeviceStateRequest() {
261 ReportProgress(AUTO_ENROLLMENT_STATE_PENDING); 267 ReportProgress(AUTO_ENROLLMENT_STATE_PENDING);
262 268
269 VLOG(1) << "State request for key: " << server_backed_state_key_;
263 request_job_.reset( 270 request_job_.reset(
264 device_management_service_->CreateJob( 271 device_management_service_->CreateJob(
265 DeviceManagementRequestJob::TYPE_DEVICE_STATE_RETRIEVAL, 272 DeviceManagementRequestJob::TYPE_DEVICE_STATE_RETRIEVAL,
266 request_context_.get())); 273 request_context_.get()));
267 request_job_->SetClientID(device_id_); 274 request_job_->SetClientID(device_id_);
268 em::DeviceStateRetrievalRequest* request = 275 em::DeviceStateRetrievalRequest* request =
269 request_job_->GetRequest()->mutable_device_state_retrieval_request(); 276 request_job_->GetRequest()->mutable_device_state_retrieval_request();
270 request->set_server_backed_state_key(server_backed_state_key_); 277 request->set_server_backed_state_key(server_backed_state_key_);
271 request_job_->Start( 278 request_job_->Start(
272 base::Bind(&AutoEnrollmentClient::HandleRequestCompletion, 279 base::Bind(&AutoEnrollmentClient::HandleRequestCompletion,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 return true; 353 return true;
347 } 354 }
348 } else { 355 } else {
349 // Server should have sent down a list of hashes to try. 356 // Server should have sent down a list of hashes to try.
350 has_server_state_ = IsIdHashInProtobuf(enrollment_response.hash()); 357 has_server_state_ = IsIdHashInProtobuf(enrollment_response.hash());
351 // Cache the current decision in local_state, so that it is reused in case 358 // Cache the current decision in local_state, so that it is reused in case
352 // the device reboots before enrolling. 359 // the device reboots before enrolling.
353 local_state_->SetBoolean(prefs::kShouldAutoEnroll, has_server_state_); 360 local_state_->SetBoolean(prefs::kShouldAutoEnroll, has_server_state_);
354 local_state_->SetInteger(prefs::kAutoEnrollmentPowerLimit, power_limit_); 361 local_state_->SetInteger(prefs::kAutoEnrollmentPowerLimit, power_limit_);
355 local_state_->CommitPendingWrite(); 362 local_state_->CommitPendingWrite();
356 VLOG(1) << "Auto enrollment check complete, has_server_state_ = " 363 VLOG(1) << "Received has_state=" << has_server_state_;
357 << has_server_state_;
358 progress = true; 364 progress = true;
359 } 365 }
360 366
361 // Bucket download done, update UMA. 367 // Bucket download done, update UMA.
362 UpdateBucketDownloadTimingHistograms(); 368 UpdateBucketDownloadTimingHistograms();
363 return progress; 369 return progress;
364 } 370 }
365 371
366 bool AutoEnrollmentClient::OnDeviceStateRequestCompletion( 372 bool AutoEnrollmentClient::OnDeviceStateRequestCompletion(
367 DeviceManagementStatus status, 373 DeviceManagementStatus status,
(...skipping 16 matching lines...) Expand all
384 ConvertRestoreMode(state_response.restore_mode()); 390 ConvertRestoreMode(state_response.restore_mode());
385 UpdateDict(dict.Get(), kDeviceStateRestoreMode, !restore_mode.empty(), 391 UpdateDict(dict.Get(), kDeviceStateRestoreMode, !restore_mode.empty(),
386 base::MakeUnique<base::Value>(restore_mode)); 392 base::MakeUnique<base::Value>(restore_mode));
387 393
388 UpdateDict(dict.Get(), kDeviceStateDisabledMessage, 394 UpdateDict(dict.Get(), kDeviceStateDisabledMessage,
389 state_response.has_disabled_state(), 395 state_response.has_disabled_state(),
390 base::MakeUnique<base::Value>( 396 base::MakeUnique<base::Value>(
391 state_response.disabled_state().message())); 397 state_response.disabled_state().message()));
392 398
393 // Logging as "WARNING" to make sure it's preserved in the logs. 399 // Logging as "WARNING" to make sure it's preserved in the logs.
394 LOG(WARNING) << "Restore mode: " << restore_mode; 400 LOG(WARNING) << "Received restore_mode=" << state_response.restore_mode();
395 } 401 }
396 local_state_->CommitPendingWrite(); 402 local_state_->CommitPendingWrite();
397 device_state_available_ = true; 403 device_state_available_ = true;
398 progress = true; 404 progress = true;
399 } 405 }
400 406
401 return progress; 407 return progress;
402 } 408 }
403 409
404 bool AutoEnrollmentClient::IsIdHashInProtobuf( 410 bool AutoEnrollmentClient::IsIdHashInProtobuf(
(...skipping 21 matching lines...) Expand all
426 base::TimeDelta delta = kZero; 432 base::TimeDelta delta = kZero;
427 if (!time_extra_start_.is_null()) 433 if (!time_extra_start_.is_null())
428 delta = now - time_extra_start_; 434 delta = now - time_extra_start_;
429 // This samples |kZero| when there was no need for extra time, so that we can 435 // This samples |kZero| when there was no need for extra time, so that we can
430 // measure the ratio of users that succeeded without needing a delay to the 436 // measure the ratio of users that succeeded without needing a delay to the
431 // total users going through OOBE. 437 // total users going through OOBE.
432 UMA_HISTOGRAM_CUSTOM_TIMES(kUMAExtraTime, delta, kMin, kMax, kBuckets); 438 UMA_HISTOGRAM_CUSTOM_TIMES(kUMAExtraTime, delta, kMin, kMax, kBuckets);
433 } 439 }
434 440
435 } // namespace policy 441 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698