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

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

Issue 2498363002: Remove delegates from ArcAuthCodeFetcher and ArcAuthContext. (Closed)
Patch Set: 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..8cd948d6a8bd8640857579034de22db2145a4436 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,
@@ -64,20 +63,21 @@ 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();
+ base::ResetAndReturn(&callback_)
+ .Run(storage_partition_->GetURLRequestContext());
}
void ArcAuthContext::OnMergeSessionFailure(
const GoogleServiceAuthError& error) {
VLOG(2) << "Failed to merge gaia session " << error.ToString() << ".";
ResetFetchers();
- delegate_->OnPrepareContextFailed();
+ base::ResetAndReturn(&callback_).Run(nullptr);
}
void ArcAuthContext::OnUbertokenSuccess(const std::string& token) {
@@ -86,28 +86,28 @@ void ArcAuthContext::OnUbertokenSuccess(const std::string& token) {
new GaiaAuthFetcher(this, GaiaConstants::kChromeOSSource,
storage_partition_->GetURLRequestContext()));
merger_fetcher_->StartMergeSession(token, std::string());
+ base::ResetAndReturn(&callback_).Run(nullptr);
}
void ArcAuthContext::OnUbertokenFailure(const GoogleServiceAuthError& error) {
VLOG(2) << "Failed to get ubertoken " << error.ToString() << ".";
ResetFetchers();
- delegate_->OnPrepareContextFailed();
Luis Héctor Chávez 2016/11/15 23:27:37 Is this intentionally missing? It _seems_ like it
hidehiko 2016/11/16 01:00:34 Good catch. unittest should capture this. A follow
}
-void ArcAuthContext::PrepareContext() {
+void ArcAuthContext::Prepare(const PrepareCallback& callback) {
if (context_prepared_) {
- delegate_->OnContextReady();
+ 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, base::TimeDelta::FromSeconds(kRefreshTokenTimeoutSeconds),
- this, &ArcAuthContext::OnRefreshTokenTimeout);
+ refresh_token_timeout_.Start(FROM_HERE, kRefreshTokenTimeout, this,
+ &ArcAuthContext::OnRefreshTokenTimeout);
return;
}
@@ -128,9 +128,4 @@ void ArcAuthContext::ResetFetchers() {
ubertoken_fetcher_.reset();
}
-net::URLRequestContextGetter* ArcAuthContext::GetURLRequestContext() {
- DCHECK(context_prepared_);
- return storage_partition_->GetURLRequestContext();
-}
-
} // namespace arc

Powered by Google App Engine
This is Rietveld 408576698