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

Unified Diff: chrome/browser/chromeos/settings/device_oauth2_token_service.cc

Issue 2685123002: Make OAuth2TokenService and subclasses take delegate by unique_ptr (Closed)
Patch Set: Created 3 years, 10 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/settings/device_oauth2_token_service.cc
diff --git a/chrome/browser/chromeos/settings/device_oauth2_token_service.cc b/chrome/browser/chromeos/settings/device_oauth2_token_service.cc
index af29c630baa2fe5e1c7aafab6bb601fd8c1e2192..9f7dd0eeda3f3c77afcc6c8bef0b162d3e5a3e9b 100644
--- a/chrome/browser/chromeos/settings/device_oauth2_token_service.cc
+++ b/chrome/browser/chromeos/settings/device_oauth2_token_service.cc
@@ -45,14 +45,13 @@ void DeviceOAuth2TokenService::OnValidationCompleted(
}
DeviceOAuth2TokenService::DeviceOAuth2TokenService(
- DeviceOAuth2TokenServiceDelegate* delegate)
- : OAuth2TokenService(delegate),
- delegate_(static_cast<DeviceOAuth2TokenServiceDelegate*>(delegate)) {
- delegate_->SetValidationStatusDelegate(this);
+ std::unique_ptr<DeviceOAuth2TokenServiceDelegate> delegate)
+ : OAuth2TokenService(std::move(delegate)) {
+ GetDeviceDelegate()->SetValidationStatusDelegate(this);
}
DeviceOAuth2TokenService::~DeviceOAuth2TokenService() {
- delegate_->SetValidationStatusDelegate(nullptr);
+ GetDeviceDelegate()->SetValidationStatusDelegate(nullptr);
FlushPendingRequests(false, GoogleServiceAuthError::REQUEST_CANCELED);
}
@@ -65,11 +64,11 @@ void DeviceOAuth2TokenService::RegisterPrefs(PrefRegistrySimple* registry) {
void DeviceOAuth2TokenService::SetAndSaveRefreshToken(
const std::string& refresh_token,
const StatusCallback& result_callback) {
- delegate_->SetAndSaveRefreshToken(refresh_token, result_callback);
+ GetDeviceDelegate()->SetAndSaveRefreshToken(refresh_token, result_callback);
}
std::string DeviceOAuth2TokenService::GetRobotAccountId() const {
- return delegate_->GetRobotAccountId();
+ return GetDeviceDelegate()->GetRobotAccountId();
}
void DeviceOAuth2TokenService::FetchOAuth2Token(
@@ -79,17 +78,17 @@ void DeviceOAuth2TokenService::FetchOAuth2Token(
const std::string& client_id,
const std::string& client_secret,
const ScopeSet& scopes) {
- switch (delegate_->state_) {
+ switch (GetDeviceDelegate()->state_) {
case DeviceOAuth2TokenServiceDelegate::STATE_VALIDATION_PENDING:
// If this is the first request for a token, start validation.
- delegate_->StartValidation();
+ GetDeviceDelegate()->StartValidation();
// fall through.
case DeviceOAuth2TokenServiceDelegate::STATE_LOADING:
case DeviceOAuth2TokenServiceDelegate::STATE_VALIDATION_STARTED:
// Add a pending request that will be satisfied once validation completes.
pending_requests_.push_back(new PendingRequest(
request->AsWeakPtr(), client_id, client_secret, scopes));
- delegate_->RequestValidation();
+ GetDeviceDelegate()->RequestValidation();
return;
case DeviceOAuth2TokenServiceDelegate::STATE_NO_TOKEN:
FailRequest(request, GoogleServiceAuthError::USER_NOT_SIGNED_UP);
@@ -104,7 +103,7 @@ void DeviceOAuth2TokenService::FetchOAuth2Token(
return;
}
- NOTREACHED() << "Unexpected state " << delegate_->state_;
+ NOTREACHED() << "Unexpected state " << GetDeviceDelegate()->state_;
}
void DeviceOAuth2TokenService::FlushPendingRequests(
@@ -123,7 +122,7 @@ void DeviceOAuth2TokenService::FlushPendingRequests(
OAuth2TokenService::FetchOAuth2Token(
scoped_request->request.get(),
scoped_request->request->GetAccountId(),
- delegate_->GetRequestContext(), scoped_request->client_id,
+ GetDeviceDelegate()->GetRequestContext(), scoped_request->client_id,
scoped_request->client_secret, scoped_request->scopes);
} else {
FailRequest(scoped_request->request.get(), error);
@@ -140,4 +139,14 @@ void DeviceOAuth2TokenService::FailRequest(
auth_error, std::string(), base::Time()));
}
+DeviceOAuth2TokenServiceDelegate*
+DeviceOAuth2TokenService::GetDeviceDelegate() {
+ return static_cast<DeviceOAuth2TokenServiceDelegate*>(GetDelegate());
+}
+
+const DeviceOAuth2TokenServiceDelegate*
+DeviceOAuth2TokenService::GetDeviceDelegate() const {
+ return static_cast<const DeviceOAuth2TokenServiceDelegate*>(GetDelegate());
+}
+
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698