summaryrefslogtreecommitdiffstats
path: root/google_apis/gaia/ubertoken_fetcher.cc
diff options
context:
space:
mode:
authorblundell@chromium.org <blundell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-16 22:52:57 +0000
committerblundell@chromium.org <blundell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-16 22:52:57 +0000
commitdf6a024c8ef52bd882e2ef046d8b55fe9a4b2167 (patch)
tree618684a2cbfc4392fae0d2a15352180e356884a4 /google_apis/gaia/ubertoken_fetcher.cc
parent50136d7e76e9ab72c056f93c95a974352b993330 (diff)
downloadchromium_src-df6a024c8ef52bd882e2ef046d8b55fe9a4b2167.zip
chromium_src-df6a024c8ef52bd882e2ef046d8b55fe9a4b2167.tar.gz
chromium_src-df6a024c8ef52bd882e2ef046d8b55fe9a4b2167.tar.bz2
Move UbertokenFetcher from //chrome to //google_apis.
This CL eliminates //chrome- and //content-level dependencies from UbertokenFetcher and moves it to //google_apis/gaia. Notable changes: - Change UbertokenFetcher to take in the OAuth2TokenService and URLRequestContextGetter to use rather than the Profile. - Add a FakeOAuth2TokenService to enable moving the UbertokenFetcher unittest away from using FakeProfileOAuth2TokenService. BUG=330292 TBR=thakis Review URL: https://codereview.chromium.org/136723009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245359 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis/gaia/ubertoken_fetcher.cc')
-rw-r--r--google_apis/gaia/ubertoken_fetcher.cc64
1 files changed, 64 insertions, 0 deletions
diff --git a/google_apis/gaia/ubertoken_fetcher.cc b/google_apis/gaia/ubertoken_fetcher.cc
new file mode 100644
index 0000000..c32f2ec
--- /dev/null
+++ b/google_apis/gaia/ubertoken_fetcher.cc
@@ -0,0 +1,64 @@
+// Copyright 2014 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 "google_apis/gaia/ubertoken_fetcher.h"
+
+#include <vector>
+
+#include "base/logging.h"
+#include "google_apis/gaia/gaia_auth_fetcher.h"
+#include "google_apis/gaia/gaia_constants.h"
+#include "google_apis/gaia/gaia_urls.h"
+#include "google_apis/gaia/google_service_auth_error.h"
+#include "google_apis/gaia/oauth2_token_service.h"
+
+UbertokenFetcher::UbertokenFetcher(
+ OAuth2TokenService* token_service,
+ UbertokenConsumer* consumer,
+ net::URLRequestContextGetter* request_context)
+ : OAuth2TokenService::Consumer("uber_token_fetcher"),
+ token_service_(token_service),
+ consumer_(consumer),
+ request_context_(request_context) {
+ DCHECK(token_service);
+ DCHECK(consumer);
+ DCHECK(request_context);
+}
+
+UbertokenFetcher::~UbertokenFetcher() {
+}
+
+void UbertokenFetcher::StartFetchingToken(const std::string& account_id) {
+ OAuth2TokenService::ScopeSet scopes;
+ scopes.insert(GaiaUrls::GetInstance()->oauth1_login_scope());
+ access_token_request_ =
+ token_service_->StartRequest(account_id, scopes, this);
+}
+
+void UbertokenFetcher::OnUberAuthTokenSuccess(const std::string& token) {
+ consumer_->OnUbertokenSuccess(token);
+}
+
+void UbertokenFetcher::OnUberAuthTokenFailure(
+ const GoogleServiceAuthError& error) {
+ consumer_->OnUbertokenFailure(error);
+}
+
+void UbertokenFetcher::OnGetTokenSuccess(
+ const OAuth2TokenService::Request* request,
+ const std::string& access_token,
+ const base::Time& expiration_time) {
+ access_token_request_.reset();
+ gaia_auth_fetcher_.reset(new GaiaAuthFetcher(this,
+ GaiaConstants::kChromeSource,
+ request_context_));
+ gaia_auth_fetcher_->StartTokenFetchForUberAuthExchange(access_token);
+}
+
+void UbertokenFetcher::OnGetTokenFailure(
+ const OAuth2TokenService::Request* request,
+ const GoogleServiceAuthError& error) {
+ access_token_request_.reset();
+ consumer_->OnUbertokenFailure(error);
+}