This source file includes following definitions.
- signin_manager_
- Shutdown
- OnRefreshTokenAvailable
- OnGetTokenSuccess
- OnGetTokenFailure
- OnInitializationCompleted
- Initialize
- RequestAccessToken
#include "chrome/browser/chromeos/policy/user_cloud_policy_token_forwarder.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h"
#include "components/policy/core/common/cloud/cloud_policy_core.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager.h"
#include "content/public/browser/notification_source.h"
#include "google_apis/gaia/gaia_constants.h"
namespace policy {
UserCloudPolicyTokenForwarder::UserCloudPolicyTokenForwarder(
UserCloudPolicyManagerChromeOS* manager,
ProfileOAuth2TokenService* token_service,
SigninManagerBase* signin_manager)
: OAuth2TokenService::Consumer("policy_token_forwarder"),
manager_(manager),
token_service_(token_service),
signin_manager_(signin_manager) {
if (manager_->core()->service()->IsInitializationComplete()) {
Initialize();
} else {
manager_->core()->service()->AddObserver(this);
}
}
UserCloudPolicyTokenForwarder::~UserCloudPolicyTokenForwarder() {}
void UserCloudPolicyTokenForwarder::Shutdown() {
request_.reset();
token_service_->RemoveObserver(this);
manager_->core()->service()->RemoveObserver(this);
}
void UserCloudPolicyTokenForwarder::OnRefreshTokenAvailable(
const std::string& account_id) {
RequestAccessToken();
}
void UserCloudPolicyTokenForwarder::OnGetTokenSuccess(
const OAuth2TokenService::Request* request,
const std::string& access_token,
const base::Time& expiration_time) {
manager_->OnAccessTokenAvailable(access_token);
Shutdown();
}
void UserCloudPolicyTokenForwarder::OnGetTokenFailure(
const OAuth2TokenService::Request* request,
const GoogleServiceAuthError& error) {
Shutdown();
}
void UserCloudPolicyTokenForwarder::OnInitializationCompleted(
CloudPolicyService* service) {
Initialize();
}
void UserCloudPolicyTokenForwarder::Initialize() {
if (token_service_->RefreshTokenIsAvailable(
signin_manager_->GetAuthenticatedAccountId()))
RequestAccessToken();
else
token_service_->AddObserver(this);
}
void UserCloudPolicyTokenForwarder::RequestAccessToken() {
OAuth2TokenService::ScopeSet scopes;
scopes.insert(GaiaConstants::kDeviceManagementServiceOAuth);
scopes.insert(GaiaConstants::kOAuthWrapBridgeUserInfoScope);
request_ = token_service_->StartRequest(
signin_manager_->GetAuthenticatedAccountId(), scopes, this);
}
}