Commit 8bd35f1f authored by Anand K. Mistry's avatar Anand K. Mistry Committed by Commit Bot

Convert google_apis::AuthStatusCallback to OnceCallback

Bug: 1007788
Change-Id: I52a2b0a15d8962f312f41a9fb1e227c911d5f410
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1997425Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarRyo Hashimoto <hashimoto@chromium.org>
Commit-Queue: Anand Mistry <amistry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#731808}
parent 9cc1fae0
...@@ -1050,7 +1050,7 @@ void FileManagerPrivateInternalGetDownloadUrlFunction::OnGotDownloadUrl( ...@@ -1050,7 +1050,7 @@ void FileManagerPrivateInternalGetDownloadUrlFunction::OnGotDownloadUrl(
->GetURLLoaderFactoryForBrowserProcess(); ->GetURLLoaderFactoryForBrowserProcess();
auth_service_ = std::make_unique<google_apis::AuthService>( auth_service_ = std::make_unique<google_apis::AuthService>(
identity_manager, account_id, url_loader_factory, scopes); identity_manager, account_id, url_loader_factory, scopes);
auth_service_->StartAuthentication(base::Bind( auth_service_->StartAuthentication(base::BindOnce(
&FileManagerPrivateInternalGetDownloadUrlFunction::OnTokenFetched, this)); &FileManagerPrivateInternalGetDownloadUrlFunction::OnTokenFetched, this));
} }
......
...@@ -381,10 +381,10 @@ FileManagerPrivateRequestWebStoreAccessTokenFunction::Run() { ...@@ -381,10 +381,10 @@ FileManagerPrivateRequestWebStoreAccessTokenFunction::Run() {
g_browser_process->system_network_context_manager() g_browser_process->system_network_context_manager()
->GetSharedURLLoaderFactory(), ->GetSharedURLLoaderFactory(),
scopes); scopes);
auth_service_->StartAuthentication(base::Bind( auth_service_->StartAuthentication(
&FileManagerPrivateRequestWebStoreAccessTokenFunction:: base::BindOnce(&FileManagerPrivateRequestWebStoreAccessTokenFunction::
OnAccessTokenFetched, OnAccessTokenFetched,
this)); this));
return RespondLater(); return RespondLater();
} }
......
...@@ -287,7 +287,7 @@ bool DriveServiceOnWorker::HasAccessToken() const { ...@@ -287,7 +287,7 @@ bool DriveServiceOnWorker::HasAccessToken() const {
} }
void DriveServiceOnWorker::RequestAccessToken( void DriveServiceOnWorker::RequestAccessToken(
const google_apis::AuthStatusCallback& callback) { google_apis::AuthStatusCallback callback) {
NOTREACHED(); NOTREACHED();
} }
......
...@@ -112,8 +112,7 @@ class DriveServiceOnWorker : public drive::DriveServiceInterface { ...@@ -112,8 +112,7 @@ class DriveServiceOnWorker : public drive::DriveServiceInterface {
void RemoveObserver(drive::DriveServiceObserver* observer) override; void RemoveObserver(drive::DriveServiceObserver* observer) override;
bool CanSendRequest() const override; bool CanSendRequest() const override;
bool HasAccessToken() const override; bool HasAccessToken() const override;
void RequestAccessToken( void RequestAccessToken(google_apis::AuthStatusCallback callback) override;
const google_apis::AuthStatusCallback& callback) override;
void ClearAccessToken() override; void ClearAccessToken() override;
void ClearRefreshToken() override; void ClearRefreshToken() override;
google_apis::CancelCallback GetAllTeamDriveList( google_apis::CancelCallback GetAllTeamDriveList(
......
...@@ -793,18 +793,18 @@ bool DriveAPIService::HasAccessToken() const { ...@@ -793,18 +793,18 @@ bool DriveAPIService::HasAccessToken() const {
return sender_->auth_service()->HasAccessToken(); return sender_->auth_service()->HasAccessToken();
} }
void DriveAPIService::RequestAccessToken(const AuthStatusCallback& callback) { void DriveAPIService::RequestAccessToken(AuthStatusCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!callback.is_null()); DCHECK(callback);
const std::string access_token = sender_->auth_service()->access_token(); const std::string access_token = sender_->auth_service()->access_token();
if (!access_token.empty()) { if (!access_token.empty()) {
callback.Run(google_apis::HTTP_NOT_MODIFIED, access_token); std::move(callback).Run(google_apis::HTTP_NOT_MODIFIED, access_token);
return; return;
} }
// Retrieve the new auth token. // Retrieve the new auth token.
sender_->auth_service()->StartAuthentication(callback); sender_->auth_service()->StartAuthentication(std::move(callback));
} }
bool DriveAPIService::HasRefreshToken() const { bool DriveAPIService::HasRefreshToken() const {
......
...@@ -124,8 +124,7 @@ class DriveAPIService : public DriveServiceInterface, ...@@ -124,8 +124,7 @@ class DriveAPIService : public DriveServiceInterface,
void RemoveObserver(DriveServiceObserver* observer) override; void RemoveObserver(DriveServiceObserver* observer) override;
bool CanSendRequest() const override; bool CanSendRequest() const override;
bool HasAccessToken() const override; bool HasAccessToken() const override;
void RequestAccessToken( void RequestAccessToken(google_apis::AuthStatusCallback callback) override;
const google_apis::AuthStatusCallback& callback) override;
bool HasRefreshToken() const override; bool HasRefreshToken() const override;
void ClearAccessToken() override; void ClearAccessToken() override;
void ClearRefreshToken() override; void ClearRefreshToken() override;
......
...@@ -22,16 +22,15 @@ const char kTestUserAgent[] = "test-user-agent"; ...@@ -22,16 +22,15 @@ const char kTestUserAgent[] = "test-user-agent";
class TestAuthService : public google_apis::DummyAuthService { class TestAuthService : public google_apis::DummyAuthService {
public: public:
void StartAuthentication( void StartAuthentication(google_apis::AuthStatusCallback callback) override {
const google_apis::AuthStatusCallback& callback) override { callback_ = std::move(callback);
callback_ = callback;
} }
bool HasAccessToken() const override { return false; } bool HasAccessToken() const override { return false; }
void SendHttpError() { void SendHttpError() {
ASSERT_FALSE(callback_.is_null()); ASSERT_FALSE(callback_.is_null());
callback_.Run(google_apis::HTTP_UNAUTHORIZED, ""); std::move(callback_).Run(google_apis::HTTP_UNAUTHORIZED, "");
} }
private: private:
......
...@@ -181,8 +181,7 @@ class DriveServiceInterface : public DriveServiceBatchOperationsInterface { ...@@ -181,8 +181,7 @@ class DriveServiceInterface : public DriveServiceBatchOperationsInterface {
virtual bool HasAccessToken() const = 0; virtual bool HasAccessToken() const = 0;
// Gets the cached OAuth2 access token or if empty, then fetches a new one. // Gets the cached OAuth2 access token or if empty, then fetches a new one.
virtual void RequestAccessToken( virtual void RequestAccessToken(google_apis::AuthStatusCallback callback) = 0;
const google_apis::AuthStatusCallback& callback) = 0;
// True if OAuth2 refresh token is present. // True if OAuth2 refresh token is present.
virtual bool HasRefreshToken() const = 0; virtual bool HasRefreshToken() const = 0;
......
...@@ -38,8 +38,8 @@ bool DummyDriveService::CanSendRequest() const { return true; } ...@@ -38,8 +38,8 @@ bool DummyDriveService::CanSendRequest() const { return true; }
bool DummyDriveService::HasAccessToken() const { return true; } bool DummyDriveService::HasAccessToken() const { return true; }
void DummyDriveService::RequestAccessToken(const AuthStatusCallback& callback) { void DummyDriveService::RequestAccessToken(AuthStatusCallback callback) {
callback.Run(google_apis::HTTP_NOT_MODIFIED, "fake_access_token"); std::move(callback).Run(google_apis::HTTP_NOT_MODIFIED, "fake_access_token");
} }
bool DummyDriveService::HasRefreshToken() const { return true; } bool DummyDriveService::HasRefreshToken() const { return true; }
......
...@@ -28,8 +28,7 @@ class DummyDriveService : public DriveServiceInterface { ...@@ -28,8 +28,7 @@ class DummyDriveService : public DriveServiceInterface {
void RemoveObserver(DriveServiceObserver* observer) override; void RemoveObserver(DriveServiceObserver* observer) override;
bool CanSendRequest() const override; bool CanSendRequest() const override;
bool HasAccessToken() const override; bool HasAccessToken() const override;
void RequestAccessToken( void RequestAccessToken(google_apis::AuthStatusCallback callback) override;
const google_apis::AuthStatusCallback& callback) override;
bool HasRefreshToken() const override; bool HasRefreshToken() const override;
void ClearAccessToken() override; void ClearAccessToken() override;
void ClearRefreshToken() override; void ClearRefreshToken() override;
......
...@@ -326,10 +326,10 @@ bool FakeDriveService::HasAccessToken() const { ...@@ -326,10 +326,10 @@ bool FakeDriveService::HasAccessToken() const {
return true; return true;
} }
void FakeDriveService::RequestAccessToken(const AuthStatusCallback& callback) { void FakeDriveService::RequestAccessToken(AuthStatusCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(callback); DCHECK(callback);
callback.Run(google_apis::HTTP_NOT_MODIFIED, "fake_access_token"); std::move(callback).Run(google_apis::HTTP_NOT_MODIFIED, "fake_access_token");
} }
bool FakeDriveService::HasRefreshToken() const { bool FakeDriveService::HasRefreshToken() const {
......
...@@ -129,8 +129,7 @@ class FakeDriveService : public DriveServiceInterface { ...@@ -129,8 +129,7 @@ class FakeDriveService : public DriveServiceInterface {
bool CanSendRequest() const override; bool CanSendRequest() const override;
std::string GetRootResourceId() const override; std::string GetRootResourceId() const override;
bool HasAccessToken() const override; bool HasAccessToken() const override;
void RequestAccessToken( void RequestAccessToken(google_apis::AuthStatusCallback callback) override;
const google_apis::AuthStatusCallback& callback) override;
bool HasRefreshToken() const override; bool HasRefreshToken() const override;
void ClearAccessToken() override; void ClearAccessToken() override;
void ClearRefreshToken() override; void ClearRefreshToken() override;
......
...@@ -42,7 +42,7 @@ class AuthRequest { ...@@ -42,7 +42,7 @@ class AuthRequest {
AuthRequest(signin::IdentityManager* identity_manager, AuthRequest(signin::IdentityManager* identity_manager,
const CoreAccountId& account_id, const CoreAccountId& account_id,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const AuthStatusCallback& callback, AuthStatusCallback callback,
const std::vector<std::string>& scopes); const std::vector<std::string>& scopes);
~AuthRequest(); ~AuthRequest();
...@@ -61,11 +61,11 @@ AuthRequest::AuthRequest( ...@@ -61,11 +61,11 @@ AuthRequest::AuthRequest(
signin::IdentityManager* identity_manager, signin::IdentityManager* identity_manager,
const CoreAccountId& account_id, const CoreAccountId& account_id,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const AuthStatusCallback& callback, AuthStatusCallback callback,
const std::vector<std::string>& scopes) const std::vector<std::string>& scopes)
: callback_(callback) { : callback_(std::move(callback)) {
DCHECK(identity_manager); DCHECK(identity_manager);
DCHECK(!callback_.is_null()); DCHECK(callback_);
access_token_fetcher_ = identity_manager->CreateAccessTokenFetcherForAccount( access_token_fetcher_ = identity_manager->CreateAccessTokenFetcherForAccount(
account_id, "auth_service", url_loader_factory, account_id, "auth_service", url_loader_factory,
...@@ -84,7 +84,7 @@ void AuthRequest::OnAccessTokenFetchComplete( ...@@ -84,7 +84,7 @@ void AuthRequest::OnAccessTokenFetchComplete(
if (error.state() == GoogleServiceAuthError::NONE) { if (error.state() == GoogleServiceAuthError::NONE) {
RecordAuthResultHistogram(kSuccessRatioHistogramSuccess); RecordAuthResultHistogram(kSuccessRatioHistogramSuccess);
callback_.Run(HTTP_SUCCESS, token_info.token); std::move(callback_).Run(HTTP_SUCCESS, token_info.token);
} else { } else {
LOG(WARNING) << "AuthRequest: token request using refresh token failed: " LOG(WARNING) << "AuthRequest: token request using refresh token failed: "
<< error.ToString(); << error.ToString();
...@@ -94,14 +94,14 @@ void AuthRequest::OnAccessTokenFetchComplete( ...@@ -94,14 +94,14 @@ void AuthRequest::OnAccessTokenFetchComplete(
// so that the file manager works while off-line. // so that the file manager works while off-line.
if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) { if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) {
RecordAuthResultHistogram(kSuccessRatioHistogramNoConnection); RecordAuthResultHistogram(kSuccessRatioHistogramNoConnection);
callback_.Run(DRIVE_NO_CONNECTION, std::string()); std::move(callback_).Run(DRIVE_NO_CONNECTION, std::string());
} else if (error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE) { } else if (error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE) {
RecordAuthResultHistogram(kSuccessRatioHistogramTemporaryFailure); RecordAuthResultHistogram(kSuccessRatioHistogramTemporaryFailure);
callback_.Run(HTTP_FORBIDDEN, std::string()); std::move(callback_).Run(HTTP_FORBIDDEN, std::string());
} else { } else {
// Permanent auth error. // Permanent auth error.
RecordAuthResultHistogram(kSuccessRatioHistogramFailure); RecordAuthResultHistogram(kSuccessRatioHistogramFailure);
callback_.Run(HTTP_UNAUTHORIZED, std::string()); std::move(callback_).Run(HTTP_UNAUTHORIZED, std::string());
} }
} }
...@@ -130,22 +130,25 @@ AuthService::~AuthService() { ...@@ -130,22 +130,25 @@ AuthService::~AuthService() {
identity_manager_->RemoveObserver(this); identity_manager_->RemoveObserver(this);
} }
void AuthService::StartAuthentication(const AuthStatusCallback& callback) { void AuthService::StartAuthentication(AuthStatusCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
if (HasAccessToken()) { if (HasAccessToken()) {
// We already have access token. Give it back to the caller asynchronously. // We already have access token. Give it back to the caller asynchronously.
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(callback, HTTP_SUCCESS, access_token_)); FROM_HERE,
base::BindOnce(std::move(callback), HTTP_SUCCESS, access_token_));
} else if (HasRefreshToken()) { } else if (HasRefreshToken()) {
// We have refresh token, let's get an access token. // We have refresh token, let's get an access token.
new AuthRequest(identity_manager_, account_id_, url_loader_factory_, new AuthRequest(
base::Bind(&AuthService::OnAuthCompleted, identity_manager_, account_id_, url_loader_factory_,
weak_ptr_factory_.GetWeakPtr(), callback), base::BindOnce(&AuthService::OnAuthCompleted,
scopes_); weak_ptr_factory_.GetWeakPtr(), std::move(callback)),
scopes_);
} else { } else {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(callback, DRIVE_NOT_READY, std::string())); FROM_HERE,
base::BindOnce(std::move(callback), DRIVE_NOT_READY, std::string()));
} }
} }
...@@ -169,11 +172,11 @@ void AuthService::ClearRefreshToken() { ...@@ -169,11 +172,11 @@ void AuthService::ClearRefreshToken() {
OnHandleRefreshToken(false); OnHandleRefreshToken(false);
} }
void AuthService::OnAuthCompleted(const AuthStatusCallback& callback, void AuthService::OnAuthCompleted(AuthStatusCallback callback,
DriveApiErrorCode error, DriveApiErrorCode error,
const std::string& access_token) { const std::string& access_token) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!callback.is_null()); DCHECK(callback);
if (error == HTTP_SUCCESS) { if (error == HTTP_SUCCESS) {
access_token_ = access_token; access_token_ = access_token;
...@@ -188,7 +191,7 @@ void AuthService::OnAuthCompleted(const AuthStatusCallback& callback, ...@@ -188,7 +191,7 @@ void AuthService::OnAuthCompleted(const AuthStatusCallback& callback,
ClearRefreshToken(); ClearRefreshToken();
} }
callback.Run(error, access_token); std::move(callback).Run(error, access_token);
} }
void AuthService::AddObserver(AuthServiceObserver* observer) { void AuthService::AddObserver(AuthServiceObserver* observer) {
......
...@@ -44,7 +44,7 @@ class AuthService : public AuthServiceInterface, ...@@ -44,7 +44,7 @@ class AuthService : public AuthServiceInterface,
// Overriden from AuthServiceInterface: // Overriden from AuthServiceInterface:
void AddObserver(AuthServiceObserver* observer) override; void AddObserver(AuthServiceObserver* observer) override;
void RemoveObserver(AuthServiceObserver* observer) override; void RemoveObserver(AuthServiceObserver* observer) override;
void StartAuthentication(const AuthStatusCallback& callback) override; void StartAuthentication(AuthStatusCallback callback) override;
bool HasAccessToken() const override; bool HasAccessToken() const override;
bool HasRefreshToken() const override; bool HasRefreshToken() const override;
const std::string& access_token() const override; const std::string& access_token() const override;
...@@ -63,7 +63,7 @@ class AuthService : public AuthServiceInterface, ...@@ -63,7 +63,7 @@ class AuthService : public AuthServiceInterface,
// Called when authentication request from StartAuthentication() is // Called when authentication request from StartAuthentication() is
// completed. // completed.
void OnAuthCompleted(const AuthStatusCallback& callback, void OnAuthCompleted(AuthStatusCallback callback,
DriveApiErrorCode error, DriveApiErrorCode error,
const std::string& access_token); const std::string& access_token);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <string> #include <string>
#include "base/callback_forward.h" #include "base/callback.h"
#include "google_apis/drive/drive_api_error_codes.h" #include "google_apis/drive/drive_api_error_codes.h"
namespace google_apis { namespace google_apis {
...@@ -15,8 +15,8 @@ namespace google_apis { ...@@ -15,8 +15,8 @@ namespace google_apis {
class AuthServiceObserver; class AuthServiceObserver;
// Called when fetching of access token is complete. // Called when fetching of access token is complete.
typedef base::Callback<void(DriveApiErrorCode error, typedef base::OnceCallback<void(DriveApiErrorCode error,
const std::string& access_token)> const std::string& access_token)>
AuthStatusCallback; AuthStatusCallback;
// This defines an interface for the authentication service which is required // This defines an interface for the authentication service which is required
...@@ -32,7 +32,7 @@ class AuthServiceInterface { ...@@ -32,7 +32,7 @@ class AuthServiceInterface {
// Starts fetching OAuth2 access token from the refresh token. // Starts fetching OAuth2 access token from the refresh token.
// |callback| must not be null. // |callback| must not be null.
virtual void StartAuthentication(const AuthStatusCallback& callback) = 0; virtual void StartAuthentication(AuthStatusCallback callback) = 0;
// True if an OAuth2 access token is retrieved and believed to be fresh. // True if an OAuth2 access token is retrieved and believed to be fresh.
// The access token is used to access the Drive server. // The access token is used to access the Drive server.
......
...@@ -17,8 +17,7 @@ void DummyAuthService::AddObserver(AuthServiceObserver* observer) { ...@@ -17,8 +17,7 @@ void DummyAuthService::AddObserver(AuthServiceObserver* observer) {
void DummyAuthService::RemoveObserver(AuthServiceObserver* observer) { void DummyAuthService::RemoveObserver(AuthServiceObserver* observer) {
} }
void DummyAuthService::StartAuthentication(const AuthStatusCallback& callback) { void DummyAuthService::StartAuthentication(AuthStatusCallback callback) {}
}
bool DummyAuthService::HasAccessToken() const { bool DummyAuthService::HasAccessToken() const {
return !access_token_.empty(); return !access_token_.empty();
......
...@@ -26,7 +26,7 @@ class DummyAuthService : public AuthServiceInterface { ...@@ -26,7 +26,7 @@ class DummyAuthService : public AuthServiceInterface {
// AuthServiceInterface overrides. // AuthServiceInterface overrides.
void AddObserver(AuthServiceObserver* observer) override; void AddObserver(AuthServiceObserver* observer) override;
void RemoveObserver(AuthServiceObserver* observer) override; void RemoveObserver(AuthServiceObserver* observer) override;
void StartAuthentication(const AuthStatusCallback& callback) override; void StartAuthentication(AuthStatusCallback callback) override;
bool HasAccessToken() const override; bool HasAccessToken() const override;
bool HasRefreshToken() const override; bool HasRefreshToken() const override;
const std::string& access_token() const override; const std::string& access_token() const override;
......
...@@ -50,8 +50,8 @@ base::Closure RequestSender::StartRequestWithAuthRetryInternal( ...@@ -50,8 +50,8 @@ base::Closure RequestSender::StartRequestWithAuthRetryInternal(
if (!auth_service_->HasAccessToken()) { if (!auth_service_->HasAccessToken()) {
// Fetch OAuth2 access token from the refresh token first. // Fetch OAuth2 access token from the refresh token first.
auth_service_->StartAuthentication( auth_service_->StartAuthentication(
base::Bind(&RequestSender::OnAccessTokenFetched, base::BindOnce(&RequestSender::OnAccessTokenFetched,
weak_ptr_factory_.GetWeakPtr(), request->GetWeakPtr())); weak_ptr_factory_.GetWeakPtr(), request->GetWeakPtr()));
} else { } else {
request->Start(auth_service_->access_token(), custom_user_agent_, request->Start(auth_service_->access_token(), custom_user_agent_,
base::BindRepeating(&RequestSender::RetryRequest, base::BindRepeating(&RequestSender::RetryRequest,
......
...@@ -34,7 +34,7 @@ class TestAuthService : public DummyAuthService { ...@@ -34,7 +34,7 @@ class TestAuthService : public DummyAuthService {
public: public:
TestAuthService() : auth_try_count_(0) {} TestAuthService() : auth_try_count_(0) {}
void StartAuthentication(const AuthStatusCallback& callback) override { void StartAuthentication(AuthStatusCallback callback) override {
// RequestSender should clear the rejected access token before starting // RequestSender should clear the rejected access token before starting
// to request another one. // to request another one.
EXPECT_FALSE(HasAccessToken()); EXPECT_FALSE(HasAccessToken());
...@@ -45,10 +45,10 @@ class TestAuthService : public DummyAuthService { ...@@ -45,10 +45,10 @@ class TestAuthService : public DummyAuthService {
const std::string token = const std::string token =
kTestAccessToken + base::NumberToString(auth_try_count_); kTestAccessToken + base::NumberToString(auth_try_count_);
set_access_token(token); set_access_token(token);
callback.Run(HTTP_SUCCESS, token); std::move(callback).Run(HTTP_SUCCESS, token);
} else { } else {
set_access_token(""); set_access_token("");
callback.Run(HTTP_UNAUTHORIZED, ""); std::move(callback).Run(HTTP_UNAUTHORIZED, "");
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment