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

Unified Diff: chrome/browser/chromeos/arc/arc_auth_context.cc

Issue 2498363002: Remove delegates from ArcAuthCodeFetcher and ArcAuthContext. (Closed)
Patch Set: rebase Created 4 years, 1 month 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/arc/arc_auth_context.cc
diff --git a/chrome/browser/chromeos/arc/arc_auth_context.cc b/chrome/browser/chromeos/arc/arc_auth_context.cc
index ffbd671313cd6fc38d95ebc4faa106199046add1..6278c6e90f96dac8eed12fe77d285522887be227 100644
--- a/chrome/browser/chromeos/arc/arc_auth_context.cc
+++ b/chrome/browser/chromeos/arc/arc_auth_context.cc
@@ -4,8 +4,8 @@
#include "chrome/browser/chromeos/arc/arc_auth_context.h"
+#include "base/callback_helpers.h"
#include "base/strings/stringprintf.h"
-#include "chrome/browser/chromeos/arc/arc_auth_context_delegate.h"
#include "chrome/browser/chromeos/arc/arc_support_host.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
@@ -22,13 +22,12 @@ namespace arc {
namespace {
-constexpr int kRefreshTokenTimeoutSeconds = 10;
+constexpr base::TimeDelta kRefreshTokenTimeout =
+ base::TimeDelta::FromSeconds(10);
} // namespace
-ArcAuthContext::ArcAuthContext(ArcAuthContextDelegate* delegate,
- Profile* profile)
- : delegate_(delegate) {
+ArcAuthContext::ArcAuthContext(Profile* profile) {
// Reuse storage used in ARC OptIn platform app.
const std::string site_url = base::StringPrintf(
"%s://%s/persist?%s", content::kGuestScheme, ArcSupportHost::kHostAppId,
@@ -49,6 +48,26 @@ ArcAuthContext::~ArcAuthContext() {
token_service_->RemoveObserver(this);
}
+void ArcAuthContext::Prepare(const PrepareCallback& callback) {
+ if (context_prepared_) {
+ callback.Run(storage_partition_->GetURLRequestContext());
+ return;
+ }
+
+ callback_ = callback;
+ token_service_->RemoveObserver(this);
+ refresh_token_timeout_.Stop();
+
+ if (!token_service_->RefreshTokenIsAvailable(account_id_)) {
+ token_service_->AddObserver(this);
+ refresh_token_timeout_.Start(FROM_HERE, kRefreshTokenTimeout, this,
+ &ArcAuthContext::OnRefreshTokenTimeout);
+ return;
+ }
+
+ StartFetchers();
+}
+
void ArcAuthContext::OnRefreshTokenAvailable(const std::string& account_id) {
if (account_id != account_id_)
return;
@@ -64,20 +83,16 @@ void ArcAuthContext::OnRefreshTokensLoaded() {
void ArcAuthContext::OnRefreshTokenTimeout() {
VLOG(2) << "Failed to wait for refresh token.";
token_service_->RemoveObserver(this);
- delegate_->OnPrepareContextFailed();
+ base::ResetAndReturn(&callback_).Run(nullptr);
}
-void ArcAuthContext::OnMergeSessionSuccess(const std::string& data) {
- context_prepared_ = true;
- ResetFetchers();
- delegate_->OnContextReady();
-}
-
-void ArcAuthContext::OnMergeSessionFailure(
- const GoogleServiceAuthError& error) {
- VLOG(2) << "Failed to merge gaia session " << error.ToString() << ".";
+void ArcAuthContext::StartFetchers() {
+ DCHECK(!refresh_token_timeout_.IsRunning());
ResetFetchers();
- delegate_->OnPrepareContextFailed();
+ ubertoken_fetcher_.reset(
+ new UbertokenFetcher(token_service_, this, GaiaConstants::kChromeOSSource,
+ storage_partition_->GetURLRequestContext()));
+ ubertoken_fetcher_->StartFetchingToken(account_id_);
}
void ArcAuthContext::OnUbertokenSuccess(const std::string& token) {
@@ -91,36 +106,21 @@ void ArcAuthContext::OnUbertokenSuccess(const std::string& token) {
void ArcAuthContext::OnUbertokenFailure(const GoogleServiceAuthError& error) {
VLOG(2) << "Failed to get ubertoken " << error.ToString() << ".";
ResetFetchers();
- delegate_->OnPrepareContextFailed();
+ base::ResetAndReturn(&callback_).Run(nullptr);
}
-void ArcAuthContext::PrepareContext() {
- if (context_prepared_) {
- delegate_->OnContextReady();
- return;
- }
-
- token_service_->RemoveObserver(this);
- refresh_token_timeout_.Stop();
-
- if (!token_service_->RefreshTokenIsAvailable(account_id_)) {
- token_service_->AddObserver(this);
- refresh_token_timeout_.Start(
- FROM_HERE, base::TimeDelta::FromSeconds(kRefreshTokenTimeoutSeconds),
- this, &ArcAuthContext::OnRefreshTokenTimeout);
- return;
- }
-
- StartFetchers();
+void ArcAuthContext::OnMergeSessionSuccess(const std::string& data) {
+ context_prepared_ = true;
+ ResetFetchers();
+ base::ResetAndReturn(&callback_)
+ .Run(storage_partition_->GetURLRequestContext());
}
-void ArcAuthContext::StartFetchers() {
- DCHECK(!refresh_token_timeout_.IsRunning());
+void ArcAuthContext::OnMergeSessionFailure(
+ const GoogleServiceAuthError& error) {
+ VLOG(2) << "Failed to merge gaia session " << error.ToString() << ".";
ResetFetchers();
- ubertoken_fetcher_.reset(
- new UbertokenFetcher(token_service_, this, GaiaConstants::kChromeOSSource,
- storage_partition_->GetURLRequestContext()));
- ubertoken_fetcher_->StartFetchingToken(account_id_);
+ base::ResetAndReturn(&callback_).Run(nullptr);
}
void ArcAuthContext::ResetFetchers() {
@@ -128,9 +128,4 @@ void ArcAuthContext::ResetFetchers() {
ubertoken_fetcher_.reset();
}
-net::URLRequestContextGetter* ArcAuthContext::GetURLRequestContext() {
- DCHECK(context_prepared_);
- return storage_partition_->GetURLRequestContext();
-}
-
} // namespace arc
« no previous file with comments | « chrome/browser/chromeos/arc/arc_auth_context.h ('k') | chrome/browser/chromeos/arc/arc_auth_context_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698