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

Unified Diff: chrome/common/net/gaia/authentication_fetcher.h

Issue 6894027: Initial refactoring complete Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixed some tests that were broken by previous refactoring Created 9 years, 8 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/common/net/gaia/authentication_fetcher.h
diff --git a/chrome/common/net/gaia/authentication_fetcher.h b/chrome/common/net/gaia/authentication_fetcher.h
new file mode 100644
index 0000000000000000000000000000000000000000..bbff195ccd875e35305772a49908425aa1859507
--- /dev/null
+++ b/chrome/common/net/gaia/authentication_fetcher.h
@@ -0,0 +1,175 @@
+// Copyright (c) 2011 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.
+
+#ifndef CHROME_COMMON_NET_GAIA_AUTHENTICATION_FETCHER_H_
+#define CHROME_COMMON_NET_GAIA_AUTHENTICATION_FETCHER_H_
+#pragma once
+
+#include <string>
+
+#include "base/gtest_prod_util.h"
+#include "base/memory/scoped_ptr.h"
+#include "chrome/common/net/gaia/authentication_consumer.h"
+#include "chrome/common/net/url_fetcher.h"
+#include "googleurl/src/gurl.h"
+
+// Authenticate a user against the Google Accounts Authentication API
+// with various capabilities and return results to a AuthenticationConsumer.
+//
+// In the future, we will also issue auth tokens from this class.
+// This class should be used on a single thread, but it can be whichever thread
+// that you like.
+//
+// This class can handle one request at a time. To parallelize requests,
+// create multiple AuthenticationFetcher's.
+
+class AuthenticationFetcherTest;
+
+class AuthenticationFetcher : public URLFetcher::Delegate {
+ public:
+ enum HostedAccountsSetting {
+ HostedAccountsAllowed,
+ HostedAccountsNotAllowed
+ };
+
+ // The URLs for different calls in the Google Accounts programmatic login API.
+ static const char kAuthenticationUrl[];
+ static const char kIssueAuthTokenUrl[];
+ static const char kGetUserInfoUrl[];
+
+ // Magic string indicating that, while a second factor is still
+ // needed to complete authentication, the user provided the right password.
+ static const char kSecondFactor[];
+
+ // Create a fetcher useable for making any Authentication request.
+ static AuthenticationFetcher* CreateAuthenticationFetcher(
+ const std::string& variant,
+ AuthenticationConsumer* consumer,
+ const std::string& source,
+ net::URLRequestContextGetter* getter);
+
+ virtual ~AuthenticationFetcher();
+
+ // AuthenticationConsumer will be called on the original thread
+ // after results come back. This class is thread agnostic.
+ // You can't make more than request at a time.
+ virtual void StartAuthentication(const std::string& username,
+ const std::string& password,
+ const char* const service,
+ const std::string& login_token,
+ const std::string& login_captcha,
+ HostedAccountsSetting allow_hosted_accounts)
+ = 0;
+
+ // AuthenticationConsumer will be called on the original thread
+ // after results come back. This class is thread agnostic.
+ // You can't make more than one request at a time.
+ virtual void StartIssueAuthToken(
+ const AuthenticationConsumer::AuthenticationResult& credentials,
+ const char* const service) = 0;
+
+ // Start a request to get a particular key from user info.
+ // AuthenticationConsumer will be called back on the same thread when
+ // results come back.
+ // You can't make more than one request at a time.
+ virtual void StartGetUserInfo(const std::string& lsid,
+ const std::string& info_key) = 0;
+
+ // Implementation of URLFetcher::Delegate
+ virtual void OnURLFetchComplete(const URLFetcher* source,
+ const GURL& url,
+ const net::URLRequestStatus& status,
+ int response_code,
+ const ResponseCookies& cookies,
+ const std::string& data) = 0;
+
+ // StartAuthentication been called && results not back yet?
+ bool HasPendingFetch() const;
+
+ // Stop any URL fetches in progress.
+ void CancelRequest();
+
+ protected:
+ AuthenticationFetcher(AuthenticationConsumer* consumer,
+ const std::string& source,
+ net::URLRequestContextGetter* getter);
+
+ // Authentication body constants that don't change
+ static const char kCookiePersistence[];
+ static const char kAccountTypeHostedOrGoogle[];
+ static const char kAccountTypeGoogle[];
+
+ // The format of the POST body for Authentication.
+ static const char kAuthenticationFormat[];
+ // The format of said POST body when CAPTCHA token & answer are specified.
+ static const char kAuthenticationCaptchaFormat[];
+ // The format of the POST body for IssueAuthToken.
+ static const char kIssueAuthTokenFormat[];
+ // The format of the POSt body for GetUserInfo.
+ static const char kGetUserInfoFormat[];
+
+ // Constants for parsing Authentication errors.
+ static const char kAccountDeletedError[];
+ static const char kAccountDisabledError[];
+ static const char kBadAuthenticationError[];
+ static const char kCaptchaError[];
+ static const char kServiceUnavailableError[];
+ static const char kErrorParam[];
+ static const char kErrorUrlParam[];
+ static const char kCaptchaUrlParam[];
+ static const char kCaptchaTokenParam[];
+ static const char kCaptchaUrlPrefix[];
+
+ // Indicate no pending fetch.
+ void ClearPending();
+
+ // Indicate a pending fetch.
+ void SetPending();
+
+ // Process the results of a Authentication fetch.
+ virtual void OnAuthenticationFetched(const std::string& data,
+ const net::URLRequestStatus& status,
+ int response_code) = 0;
+
+ virtual void OnIssueAuthTokenFetched(const std::string& data,
+ const net::URLRequestStatus& status,
+ int response_code) = 0;
+
+ virtual void OnGetUserInfoFetched(const std::string& data,
+ const net::URLRequestStatus& status,
+ int response_code) = 0;
+
+ // Create a fetcher useable for making any Gaia request.
+ static URLFetcher* CreateAuthenticationFetcher(
+ net::URLRequestContextGetter* getter,
+ const std::string& body,
+ const GURL& gaia_gurl_,
+ URLFetcher::Delegate* delegate);
+
+ // These fields are common to AuthenticationFetcher, same every request
+ AuthenticationConsumer* const consumer_;
+ net::URLRequestContextGetter* const getter_;
+ std::string source_;
+
+ // While a fetch is going on:
+ scoped_ptr<AuthenticationFetcher> fetcher_;
+
+ private:
+ bool fetch_pending_;
+
+ friend class AuthenticationFetcherTest;
+ FRIEND_TEST_ALL_PREFIXES(AuthenticationFetcherTest, CaptchaParse);
+ FRIEND_TEST_ALL_PREFIXES(AuthenticationFetcherTest, AccountDeletedError);
+ FRIEND_TEST_ALL_PREFIXES(AuthenticationFetcherTest, AccountDisabledError);
+ FRIEND_TEST_ALL_PREFIXES(AuthenticationFetcherTest, BadAuthenticationError);
+ FRIEND_TEST_ALL_PREFIXES(AuthenticationFetcherTest, IncomprehensibleError);
+ FRIEND_TEST_ALL_PREFIXES(AuthenticationFetcherTest, ServiceUnavailableError);
+ FRIEND_TEST_ALL_PREFIXES(AuthenticationFetcherTest, CheckNormalErrorCode);
+ FRIEND_TEST_ALL_PREFIXES(AuthenticationFetcherTest, CheckTwoFactorResponse);
+ FRIEND_TEST_ALL_PREFIXES(AuthenticationFetcherTest, LoginNetFailure);
+
+ DISALLOW_COPY_AND_ASSIGN(AuthenticationFetcher);
+};
+
+#endif // CHROME_COMMON_NET_GAIA_AUTHENTICATION_FETCHER_H_
« no previous file with comments | « chrome/common/net/gaia/authentication_consumer_oauth.cc ('k') | chrome/common/net/gaia/authentication_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698