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

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

Powered by Google App Engine
This is Rietveld 408576698