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

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

Issue 34523003: settings: Make DeviceOAuth2TokenServiceFactory::Get() async (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 7 years, 2 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 182b46a76d5d72869441f1b46e81bb88f537a64a..8900f93ecb39f09c89623320cee4b1614b61c157 100644
--- a/chrome/browser/chromeos/policy/enrollment_handler_chromeos.cc
+++ b/chrome/browser/chromeos/policy/enrollment_handler_chromeos.cc
@@ -53,7 +53,8 @@ EnrollmentHandlerChromeOS::EnrollmentHandlerChromeOS(
device_mode_(DEVICE_MODE_NOT_SET),
enrollment_step_(STEP_PENDING),
lockbox_init_duration_(0),
- weak_factory_(this) {
+ lock_weak_factory_(this),
+ token_weak_factory_(this) {
CHECK(!client_->is_registered());
CHECK_EQ(DM_STATUS_SUCCESS, client_->status());
store_->AddObserver(this);
@@ -110,7 +111,7 @@ void EnrollmentHandlerChromeOS::OnPolicyFetched(CloudPolicyClient* client) {
validator->ValidateInitialKey();
validator.release()->StartValidation(
base::Bind(&EnrollmentHandlerChromeOS::PolicyValidated,
- weak_factory_.GetWeakPtr()));
+ lock_weak_factory_.GetWeakPtr()));
}
void EnrollmentHandlerChromeOS::OnRegistrationStateChanged(
@@ -161,18 +162,21 @@ void EnrollmentHandlerChromeOS::OnStoreLoaded(CloudPolicyStore* store) {
// registration rolling again after the store finishes loading.
AttemptRegistration();
} else if (enrollment_step_ == STEP_STORE_POLICY) {
- // Store the robot API auth refresh token.
- // Currently optional, so always return success.
- chromeos::DeviceOAuth2TokenService* token_service =
- chromeos::DeviceOAuth2TokenServiceFactory::Get();
- if (token_service && !robot_refresh_token_.empty()) {
- token_service->SetAndSaveRefreshToken(robot_refresh_token_);
-
- }
- ReportResult(EnrollmentStatus::ForStatus(EnrollmentStatus::STATUS_SUCCESS));
+ chromeos::DeviceOAuth2TokenServiceFactory::Get(
+ base::Bind(&EnrollmentHandlerChromeOS::DidGetTokenService,
+ token_weak_factory_.GetWeakPtr()));
}
}
+void EnrollmentHandlerChromeOS::DidGetTokenService(
+ chromeos::DeviceOAuth2TokenService* token_service) {
+ // Store the robot API auth refresh token.
+ // Currently optional, so always return success.
+ if (token_service && !robot_refresh_token_.empty())
+ token_service->SetAndSaveRefreshToken(robot_refresh_token_);
+ ReportResult(EnrollmentStatus::ForStatus(EnrollmentStatus::STATUS_SUCCESS));
+}
+
void EnrollmentHandlerChromeOS::OnStoreError(CloudPolicyStore* store) {
DCHECK_EQ(store_, store);
ReportResult(EnrollmentStatus::ForStoreError(store_->status(),
@@ -271,12 +275,12 @@ void EnrollmentHandlerChromeOS::StartLockDevice(
const std::string& device_id) {
CHECK_EQ(STEP_LOCK_DEVICE, enrollment_step_);
// Since this method is also called directly.
- weak_factory_.InvalidateWeakPtrs();
+ lock_weak_factory_.InvalidateWeakPtrs();
install_attributes_->LockDevice(
user, device_mode, device_id,
base::Bind(&EnrollmentHandlerChromeOS::HandleLockDeviceResult,
- weak_factory_.GetWeakPtr(),
+ lock_weak_factory_.GetWeakPtr(),
user,
device_mode,
device_id));
@@ -303,7 +307,7 @@ void EnrollmentHandlerChromeOS::HandleLockDeviceResult(
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&EnrollmentHandlerChromeOS::StartLockDevice,
- weak_factory_.GetWeakPtr(),
+ lock_weak_factory_.GetWeakPtr(),
user, device_mode, device_id),
base::TimeDelta::FromMilliseconds(kLockRetryIntervalMs));
lockbox_init_duration_ += kLockRetryIntervalMs;
@@ -333,7 +337,7 @@ void EnrollmentHandlerChromeOS::Stop() {
if (client_.get())
client_->RemoveObserver(this);
enrollment_step_ = STEP_FINISHED;
- weak_factory_.InvalidateWeakPtrs();
+ lock_weak_factory_.InvalidateWeakPtrs();
completion_callback_.Reset();
}

Powered by Google App Engine
This is Rietveld 408576698