Chromium Code Reviews| 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..1c3ea419b73685a964342a0fb5096d6df92e0ad6 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/arc/arc_auth_fetcher.cc |
| @@ -0,0 +1,62 @@ |
| +// 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/28 16:18:07
nit: The header is still here. :)
khmel
2016/01/28 19:24:01
:) My fault. Thanks
|
| +#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_.StartCookieForOAuthLoginTokenExchange( |
| + false, /* fetch_token_from_auth_code */ |
| + "", /* session_index */ |
|
oshima
2016/01/28 17:46:40
std::string()
same for other ""s.
khmel
2016/01/28 19:24:01
Done.
|
| + kGMSCoreClientId, "" /* device_id */); |
| +} |
| + |
| +void ArcAuthFetcher::OnClientOAuthCode(const std::string& auth_code) { |
| + DCHECK(!auth_fetcher_.HasPendingFetch()); |
| + delegate_->OnAuthCodeFetched(auth_code); |
| +} |
| + |
| +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 |