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

Unified Diff: chrome/browser/extensions/api/identity/gaia_web_auth_flow.cc

Issue 2145103003: Request the Identity API's Uber Token without a Channel ID (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months 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/extensions/api/identity/gaia_web_auth_flow.cc
diff --git a/chrome/browser/extensions/api/identity/gaia_web_auth_flow.cc b/chrome/browser/extensions/api/identity/gaia_web_auth_flow.cc
index d98d0fc84960fa841553a026652bdcab56e002e6..4eb711c4ec4611c64e6e7c1188dde44c756d578d 100644
--- a/chrome/browser/extensions/api/identity/gaia_web_auth_flow.cc
+++ b/chrome/browser/extensions/api/identity/gaia_web_auth_flow.cc
@@ -18,6 +18,9 @@
#include "google_apis/gaia/gaia_constants.h"
#include "google_apis/gaia/gaia_urls.h"
#include "net/base/escape.h"
+#include "net/ssl/channel_id_service.h"
+#include "net/url_request/url_request_context.h"
+#include "net/url_request/url_request_context_getter.h"
namespace extensions {
@@ -91,19 +94,79 @@ GaiaWebAuthFlow::~GaiaWebAuthFlow() {
}
void GaiaWebAuthFlow::Start() {
+ main_context_ = profile_->GetRequestContext();
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&GaiaWebAuthFlow::StartOnIOThread, base::Unretained(this)));
+}
+
+void GaiaWebAuthFlow::StartOnIOThread() {
+ net::URLRequestContext* base_context = main_context_->GetURLRequestContext();
+ // Create a temporary request context for the Uber Token Fetch that doesn't
+ // have a Channel ID. This way, the Uber Token will not be channel bound and
+ // will be useable for the MergeSession call that will take place in the app's
+ // request context.
+ ProfileIOData::AppRequestContext* context =
+ new ProfileIOData::AppRequestContext;
+ ubertoken_request_context_.reset(context);
+
+ context->CopyFrom(base_context);
+ context->SetChannelIDService(nullptr);
+
+ // Merely setting the Channel ID Service isn't enough, we also have to build a
+ // new HttpNetworkSession.
+ std::unique_ptr<net::HttpCache::BackendFactory> app_backend =
+ net::HttpCache::DefaultBackend::InMemory(0);
+ net::HttpNetworkSession::Params network_params =
+ *base_context->GetNetworkSessionParams();
+ network_params.channel_id_service = nullptr;
+ std::unique_ptr<net::HttpNetworkSession> http_network_session(
+ new net::HttpNetworkSession(network_params));
+ std::unique_ptr<net::HttpCache> app_http_cache(
+ new net::HttpCache(http_network_session.get(),
+ std::move(app_backend), true));
+
+ context->SetHttpNetworkSession(
+ std::move(http_network_session));
+ context->SetHttpTransactionFactory(std::move(app_http_cache));
+
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&GaiaWebAuthFlow::StartUberTokenFetch,
+ base::Unretained(this)));
+}
+
+void GaiaWebAuthFlow::StartUberTokenFetch() {
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
+ context_getter_ = new net::TrivialURLRequestContextGetter(
+ ubertoken_request_context_.get(),
+ main_context_->GetNetworkTaskRunner());
ubertoken_fetcher_.reset(new UbertokenFetcher(token_service,
this,
GaiaConstants::kChromeSource,
- profile_->GetRequestContext()));
+ context_getter_.get()));
ubertoken_fetcher_->StartFetchingToken(account_id_);
}
+void GaiaWebAuthFlow::CleanupRequestContextOnIOThread() {
+ ubertoken_request_context_.reset();
+}
+
void GaiaWebAuthFlow::OnUbertokenSuccess(const std::string& token) {
TRACE_EVENT_ASYNC_STEP_PAST0(
"identity", "GaiaWebAuthFlow", this, "OnUbertokenSuccess");
+ // The temporary request context isn't required after the Uber Token request
+ // completes. It needs to be deleted on the IO Thread, so do that here.
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&GaiaWebAuthFlow::CleanupRequestContextOnIOThread,
+ base::Unretained(this)));
+
const char kMergeSessionQueryFormat[] = "?uberauth=%s&"
"continue=%s&"
"source=appsv2";
@@ -127,6 +190,14 @@ void GaiaWebAuthFlow::OnUbertokenFailure(const GoogleServiceAuthError& error) {
"error",
error.ToString());
+ // The temporary request context isn't required after the Uber Token request
+ // completes. It needs to be deleted on the IO Thread, so do that here.
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&GaiaWebAuthFlow::CleanupRequestContextOnIOThread,
+ base::Unretained(this)));
+
DVLOG(1) << "OnUbertokenFailure: " << error.error_message();
delegate_->OnGaiaFlowFailure(
GaiaWebAuthFlow::SERVICE_AUTH_ERROR, error, std::string());

Powered by Google App Engine
This is Rietveld 408576698