Commit 324138ca authored by Jochen Eisinger's avatar Jochen Eisinger Committed by Commit Bot

Convert FeedbackUploaderChrome to use Identity Service

BUG=797942
R=blundell@chromium.org

Change-Id: I51f4a5830f26c945747e9f9d3b48482b46c5239f
Reviewed-on: https://chromium-review.googlesource.com/1078848Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Commit-Queue: Jochen Eisinger <jochen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#564870}
parent 7052b23c
...@@ -6,12 +6,10 @@ ...@@ -6,12 +6,10 @@
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" #include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager.h"
#include "content/public/browser/browser_context.h"
#include "net/url_request/url_fetcher.h" #include "net/url_request/url_fetcher.h"
#include "services/identity/public/cpp/identity_manager.h"
#include "services/identity/public/cpp/primary_account_access_token_fetcher.h"
namespace feedback { namespace feedback {
...@@ -25,44 +23,46 @@ constexpr char kAuthenticationErrorLogMessage[] = ...@@ -25,44 +23,46 @@ constexpr char kAuthenticationErrorLogMessage[] =
FeedbackUploaderChrome::FeedbackUploaderChrome( FeedbackUploaderChrome::FeedbackUploaderChrome(
content::BrowserContext* context, content::BrowserContext* context,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) scoped_refptr<base::SingleThreadTaskRunner> task_runner)
: OAuth2TokenService::Consumer("feedback_uploader_chrome"), : FeedbackUploader(context, task_runner) {}
FeedbackUploader(context, task_runner) {}
FeedbackUploaderChrome::~FeedbackUploaderChrome() = default; FeedbackUploaderChrome::~FeedbackUploaderChrome() = default;
void FeedbackUploaderChrome::OnGetTokenSuccess( void FeedbackUploaderChrome::AccessTokenAvailable(
const OAuth2TokenService::Request* request, const GoogleServiceAuthError& error,
const std::string& access_token, const std::string& access_token) {
const base::Time& expiration_time) { DCHECK(token_fetcher_);
access_token_request_.reset(); std::unique_ptr<identity::PrimaryAccountAccessTokenFetcher>
access_token_ = access_token; token_fetcher_deleter(std::move(token_fetcher_));
FeedbackUploader::StartDispatchingReport(); if (error.state() == GoogleServiceAuthError::NONE) {
} DCHECK(!access_token.empty());
access_token_ = access_token;
void FeedbackUploaderChrome::OnGetTokenFailure( } else {
const OAuth2TokenService::Request* request, LOG(ERROR) << "Failed to get the access token. "
const GoogleServiceAuthError& error) { << kAuthenticationErrorLogMessage;
LOG(ERROR) << "Failed to get the access token. " }
<< kAuthenticationErrorLogMessage;
access_token_request_.reset();
FeedbackUploader::StartDispatchingReport(); FeedbackUploader::StartDispatchingReport();
} }
void FeedbackUploaderChrome::StartDispatchingReport() { void FeedbackUploaderChrome::StartDispatchingReport() {
access_token_.clear(); access_token_.clear();
// TODO(crbug.com/849591): Instead of getting the IdentityManager from the
// profile, we should pass the IdentityManager to FeedbackUploaderChrome's
// ctor.
Profile* profile = Profile::FromBrowserContext(context()); Profile* profile = Profile::FromBrowserContext(context());
DCHECK(profile); DCHECK(profile);
auto* oauth2_token_service = identity::IdentityManager* identity_manager =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile); IdentityManagerFactory::GetForProfile(profile);
auto* signin_manager = SigninManagerFactory::GetForProfile(profile);
if (oauth2_token_service && signin_manager && if (identity_manager && identity_manager->HasPrimaryAccount()) {
signin_manager->IsAuthenticated()) {
std::string account_id = signin_manager->GetAuthenticatedAccountId();
OAuth2TokenService::ScopeSet scopes; OAuth2TokenService::ScopeSet scopes;
scopes.insert("https://www.googleapis.com/auth/supportcontent"); scopes.insert("https://www.googleapis.com/auth/supportcontent");
access_token_request_ = token_fetcher_ =
oauth2_token_service->StartRequest(account_id, scopes, this); identity_manager->CreateAccessTokenFetcherForPrimaryAccount(
"feedback_uploader_chrome", scopes,
base::BindOnce(&FeedbackUploaderChrome::AccessTokenAvailable,
base::Unretained(this)),
identity::PrimaryAccountAccessTokenFetcher::Mode::kImmediate);
return; return;
} }
......
...@@ -10,12 +10,16 @@ ...@@ -10,12 +10,16 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "components/feedback/feedback_uploader.h" #include "components/feedback/feedback_uploader.h"
#include "google_apis/gaia/oauth2_token_service.h"
namespace identity {
class PrimaryAccountAccessTokenFetcher;
} // namespace identity
class GoogleServiceAuthError;
namespace feedback { namespace feedback {
class FeedbackUploaderChrome : public OAuth2TokenService::Consumer, class FeedbackUploaderChrome : public FeedbackUploader {
public FeedbackUploader {
public: public:
FeedbackUploaderChrome( FeedbackUploaderChrome(
content::BrowserContext* context, content::BrowserContext* context,
...@@ -23,18 +27,14 @@ class FeedbackUploaderChrome : public OAuth2TokenService::Consumer, ...@@ -23,18 +27,14 @@ class FeedbackUploaderChrome : public OAuth2TokenService::Consumer,
~FeedbackUploaderChrome() override; ~FeedbackUploaderChrome() override;
private: private:
// OAuth2TokenService::Consumer:
void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
const std::string& access_token,
const base::Time& expiration_time) override;
void OnGetTokenFailure(const OAuth2TokenService::Request* request,
const GoogleServiceAuthError& error) override;
// feedback::FeedbackUploader: // feedback::FeedbackUploader:
void StartDispatchingReport() override; void StartDispatchingReport() override;
void AppendExtraHeadersToUploadRequest(net::URLFetcher* fetcher) override; void AppendExtraHeadersToUploadRequest(net::URLFetcher* fetcher) override;
std::unique_ptr<OAuth2TokenService::Request> access_token_request_; void AccessTokenAvailable(const GoogleServiceAuthError& error,
const std::string& access_token);
std::unique_ptr<identity::PrimaryAccountAccessTokenFetcher> token_fetcher_;
std::string access_token_; std::string access_token_;
......
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