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

Unified Diff: chrome/browser/chromeos/policy/enrollment_handler_chromeos.cc

Issue 477243003: Revert of Minor cleanup of EnrollmentHandlerChromeOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/policy/enrollment_handler_chromeos.cc
diff --git a/chrome/browser/chromeos/policy/enrollment_handler_chromeos.cc b/chrome/browser/chromeos/policy/enrollment_handler_chromeos.cc
index a98d1310eec7be56d3979e730bee9ee64a8da940..a75e7b87d2ec485307d800d35bfb37f2597508a6 100644
--- a/chrome/browser/chromeos/policy/enrollment_handler_chromeos.cc
+++ b/chrome/browser/chromeos/policy/enrollment_handler_chromeos.cc
@@ -89,7 +89,7 @@
CHECK_EQ(STEP_PENDING, enrollment_step_);
enrollment_step_ = STEP_STATE_KEYS;
state_keys_broker_->RequestStateKeys(
- base::Bind(&EnrollmentHandlerChromeOS::HandleStateKeysResult,
+ base::Bind(&EnrollmentHandlerChromeOS::CheckStateKeys,
weak_ptr_factory_.GetWeakPtr()));
}
@@ -140,7 +140,7 @@
// from that username to validate the key below (http://crbug.com/343074).
validator->ValidateInitialKey(GetPolicyVerificationKey(), domain);
validator.release()->StartValidation(
- base::Bind(&EnrollmentHandlerChromeOS::HandlePolicyValidationResult,
+ base::Bind(&EnrollmentHandlerChromeOS::PolicyValidated,
weak_ptr_factory_.GetWeakPtr()));
}
@@ -162,7 +162,7 @@
client_->FetchPolicy();
} else {
LOG(FATAL) << "Registration state changed to " << client_->is_registered()
- << " in step " << enrollment_step_ << ".";
+ << " in step " << enrollment_step_;
}
}
@@ -184,10 +184,10 @@
DCHECK_EQ(store_, store);
if (enrollment_step_ == STEP_LOADING_STORE) {
- // If the |store_| wasn't initialized when StartEnrollment() was called,
- // then StartRegistration() bails silently. This gets registration rolling
- // again after the store finishes loading.
- StartRegistration();
+ // If the |store_| wasn't initialized when StartEnrollment() was
+ // called, then AttemptRegistration() bails silently. This gets
+ // registration rolling again after the store finishes loading.
+ AttemptRegistration();
} else if (enrollment_step_ == STEP_STORE_POLICY) {
ReportResult(EnrollmentStatus::ForStatus(EnrollmentStatus::STATUS_SUCCESS));
}
@@ -206,40 +206,37 @@
store_->validation_status()));
}
-void EnrollmentHandlerChromeOS::HandleStateKeysResult(
+void EnrollmentHandlerChromeOS::CheckStateKeys(
const std::vector<std::string>& state_keys, bool /* first_boot */) {
CHECK_EQ(STEP_STATE_KEYS, enrollment_step_);
// Make sure state keys are available if forced re-enrollment is on.
if (chromeos::AutoEnrollmentController::GetMode() ==
chromeos::AutoEnrollmentController::MODE_FORCED_RE_ENROLLMENT) {
+ if (state_keys.empty()) {
+ ReportResult(
+ EnrollmentStatus::ForStatus(EnrollmentStatus::STATUS_NO_STATE_KEYS));
+ return;
+ }
client_->SetStateKeysToUpload(state_keys);
current_state_key_ = state_keys_broker_->current_state_key();
- if (state_keys.empty() || current_state_key_.empty()) {
- ReportResult(
- EnrollmentStatus::ForStatus(EnrollmentStatus::STATUS_NO_STATE_KEYS));
- return;
- }
}
enrollment_step_ = STEP_LOADING_STORE;
- StartRegistration();
-}
-
-void EnrollmentHandlerChromeOS::StartRegistration() {
+ AttemptRegistration();
+}
+
+void EnrollmentHandlerChromeOS::AttemptRegistration() {
CHECK_EQ(STEP_LOADING_STORE, enrollment_step_);
if (store_->is_initialized()) {
enrollment_step_ = STEP_REGISTRATION;
client_->Register(em::DeviceRegisterRequest::DEVICE,
auth_token_, client_id_, is_auto_enrollment_,
requisition_, current_state_key_);
- } else {
- // Do nothing. StartRegistration() will be called again from OnStoreLoaded()
- // after the CloudPolicyStore has initialized.
- }
-}
-
-void EnrollmentHandlerChromeOS::HandlePolicyValidationResult(
+ }
+}
+
+void EnrollmentHandlerChromeOS::PolicyValidated(
DeviceCloudPolicyValidator* validator) {
CHECK_EQ(STEP_VALIDATION, enrollment_step_);
if (validator->success()) {
@@ -305,7 +302,7 @@
const std::string& access_token,
int expires_in_seconds) {
// We never use the code that should trigger this callback.
- LOG(FATAL) << "Unexpected callback invoked.";
+ LOG(FATAL) << "Unexpected callback invoked";
}
// GaiaOAuthClient::Delegate OAuth2 error when fetching refresh token request.
@@ -338,7 +335,7 @@
enrollment_step_ = STEP_STORE_TOKEN_AND_ID;
device_settings_service_->SetManagementSettings(
management_mode_, request_token_, device_id_,
- base::Bind(&EnrollmentHandlerChromeOS::HandleSetManagementSettingsDone,
+ base::Bind(&EnrollmentHandlerChromeOS::OnSetManagementSettingsDone,
weak_ptr_factory_.GetWeakPtr()));
} else {
install_attributes_->LockDevice(
@@ -348,7 +345,7 @@
}
}
-void EnrollmentHandlerChromeOS::HandleSetManagementSettingsDone() {
+void EnrollmentHandlerChromeOS::OnSetManagementSettingsDone() {
CHECK_EQ(STEP_STORE_TOKEN_AND_ID, enrollment_step_);
if (device_settings_service_->status() !=
chromeos::DeviceSettingsService::STORE_SUCCESS) {
@@ -357,7 +354,7 @@
return;
}
- StartStoreRobotAuth();
+ StoreRobotAuth();
}
void EnrollmentHandlerChromeOS::HandleLockDeviceResult(
@@ -365,8 +362,8 @@
CHECK_EQ(STEP_LOCK_DEVICE, enrollment_step_);
switch (lock_result) {
case EnterpriseInstallAttributes::LOCK_SUCCESS:
- StartStoreRobotAuth();
- break;
+ StoreRobotAuth();
+ return;
case EnterpriseInstallAttributes::LOCK_NOT_READY:
// We wait up to |kLockRetryTimeoutMs| milliseconds and if it hasn't
// succeeded by then show an error to the user and stop the enrollment.
@@ -384,30 +381,34 @@
ReportResult(EnrollmentStatus::ForStatus(
EnrollmentStatus::STATUS_LOCK_TIMEOUT));
}
- break;
+ return;
case EnterpriseInstallAttributes::LOCK_BACKEND_ERROR:
ReportResult(EnrollmentStatus::ForStatus(
EnrollmentStatus::STATUS_LOCK_ERROR));
- break;
+ return;
case EnterpriseInstallAttributes::LOCK_WRONG_USER:
LOG(ERROR) << "Enrollment cannot proceed because the InstallAttrs "
<< "has been locked already!";
ReportResult(EnrollmentStatus::ForStatus(
EnrollmentStatus::STATUS_LOCK_WRONG_USER));
- break;
- }
-}
-
-void EnrollmentHandlerChromeOS::StartStoreRobotAuth() {
+ return;
+ }
+
+ NOTREACHED() << "Invalid lock result " << lock_result;
+ ReportResult(EnrollmentStatus::ForStatus(
+ EnrollmentStatus::STATUS_LOCK_ERROR));
+}
+
+void EnrollmentHandlerChromeOS::StoreRobotAuth() {
// Get the token service so we can store our robot refresh token.
enrollment_step_ = STEP_STORE_ROBOT_AUTH;
chromeos::DeviceOAuth2TokenServiceFactory::Get()->SetAndSaveRefreshToken(
refresh_token_,
- base::Bind(&EnrollmentHandlerChromeOS::HandleStoreRobotAuthTokenResult,
+ base::Bind(&EnrollmentHandlerChromeOS::HandleRobotAuthTokenStored,
weak_ptr_factory_.GetWeakPtr()));
}
-void EnrollmentHandlerChromeOS::HandleStoreRobotAuthTokenResult(bool result) {
+void EnrollmentHandlerChromeOS::HandleRobotAuthTokenStored(bool result) {
CHECK_EQ(STEP_STORE_ROBOT_AUTH, enrollment_step_);
if (!result) {
@@ -441,9 +442,9 @@
if (status.status() != EnrollmentStatus::STATUS_SUCCESS) {
LOG(WARNING) << "Enrollment failed: " << status.status()
- << ", client: " << status.client_status()
- << ", validation: " << status.validation_status()
- << ", store: " << status.store_status();
+ << " " << status.client_status()
+ << " " << status.validation_status()
+ << " " << status.store_status();
}
if (!callback.is_null())

Powered by Google App Engine
This is Rietveld 408576698