Index: chrome/browser/chromeos/arc/arc_auth_fetcher.cc |
diff --git a/chrome/browser/chromeos/arc/arc_auth_fetcher.cc b/chrome/browser/chromeos/arc/arc_auth_fetcher.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d11d61318b3fe4ea0f5ac7cb6402231d28b57767 |
--- /dev/null |
+++ b/chrome/browser/chromeos/arc/arc_auth_fetcher.cc |
@@ -0,0 +1,65 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/chromeos/arc/arc_auth_fetcher.h" |
+ |
+#include "base/strings/stringprintf.h" |
+#include "google_apis/gaia/gaia_auth_fetcher.h" |
xiyuan
2016/01/27 23:56:05
nit: not needed since we included it in header
khmel
2016/01/28 05:22:08
Done.
|
+#include "google_apis/gaia/gaia_constants.h" |
+#include "google_apis/gaia/gaia_urls.h" |
+ |
+namespace arc { |
+ |
+namespace { |
+ |
+const char kGMSCoreClientId[] = |
+ "1070009224336-sdh77n7uot3oc99ais00jmuft6sk2fg9.apps.googleusercontent.com"; |
+ |
+} // namespace |
+ |
+ArcAuthFetcher::ArcAuthFetcher(net::URLRequestContextGetter* getter, |
+ Delegate* delegate) |
+ : delegate_(delegate), auth_fetcher_(this, "", getter) { |
+ FetchAuthCode(); |
+} |
+ |
+ArcAuthFetcher::~ArcAuthFetcher() {} |
+ |
+// static |
+GURL ArcAuthFetcher::CreateURL() { |
+ std::string query_string = |
+ base::StringPrintf("?scope=%s&client_id=%s", |
+ GaiaConstants::kOAuth1LoginScope, kGMSCoreClientId); |
+ return GaiaUrls::GetInstance()->client_login_to_oauth2_url().Resolve( |
+ query_string); |
+} |
+ |
+void ArcAuthFetcher::FetchAuthCode() { |
+ DCHECK(!auth_fetcher_.HasPendingFetch()); |
+ auth_fetcher_.StartCookieForOAuthLoginTokenExchangeWithClientIdAndDeviceId( |
+ false, /* fetch_token_from_auth_code */ |
+ "", /* session_index */ |
+ kGMSCoreClientId, "" /* device_id */); |
+} |
+ |
+void ArcAuthFetcher::OnClientOAuthCode(const std::string& auth_code) { |
+ DCHECK(!auth_fetcher_.HasPendingFetch()); |
+ delegate_->OnAuthCodeFetched(auth_code); |
+} |
+ |
+void ArcAuthFetcher::OnClientOAuthSuccess(const ClientOAuthResult& result) { |
+ NOTREACHED(); |
+} |
xiyuan
2016/01/27 23:56:05
Seems we don't really need OnClientOAuthSuccess. R
khmel
2016/01/28 05:22:08
Yes, this is redundant. I added this check for gai
|
+void ArcAuthFetcher::OnClientOAuthFailure(const GoogleServiceAuthError& error) { |
+ // UNEXPECTED_SERVICE_RESPONSE indicates no cookies in response, but request |
+ // is completed successfully. |
+ if (error.state() == GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE) { |
+ delegate_->OnAuthCodeNeedUI(); |
+ } else { |
+ VLOG(2) << "ARC Auth request failed: " << error.ToString() << "."; |
+ delegate_->OnAuthCodeFailed(); |
+ } |
+} |
+ |
+} // namespace arc |