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

Unified Diff: components/proximity_auth/cryptauth/cryptauth_client_factory.cc

Issue 1066453002: Refactor CryptAuth component to be more testable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cryptauth_securemessage
Patch Set: rebase Created 5 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: components/proximity_auth/cryptauth/cryptauth_client_factory.cc
diff --git a/components/proximity_auth/cryptauth/cryptauth_client_factory.cc b/components/proximity_auth/cryptauth/cryptauth_client_factory.cc
index e7d79774ebe3ec97fdb41ed1ae6be6bf632b57aa..e743ca5eabe8d26afc0ece7a95f437349944ce42 100644
--- a/components/proximity_auth/cryptauth/cryptauth_client_factory.cc
+++ b/components/proximity_auth/cryptauth/cryptauth_client_factory.cc
@@ -4,11 +4,40 @@
#include "components/proximity_auth/cryptauth/cryptauth_client_factory.h"
-#include "components/proximity_auth/cryptauth/cryptauth_account_token_fetcher.h"
+#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+#include "components/proximity_auth/cryptauth/cryptauth_access_token_fetcher.h"
+#include "components/proximity_auth/cryptauth/cryptauth_api_call_flow.h"
+#include "components/proximity_auth/cryptauth/cryptauth_client_impl.h"
+#include "google_apis/gaia/oauth2_token_service.h"
+#include "net/url_request/url_request_context_getter.h"
namespace proximity_auth {
-CryptAuthClientFactory::CryptAuthClientFactory(
+namespace {
+
+class CryptAuthClientFactoryImpl : public CryptAuthClientFactory {
+ public:
+ CryptAuthClientFactoryImpl(
+ OAuth2TokenService* token_service,
+ const std::string& account_id,
+ scoped_refptr<net::URLRequestContextGetter> url_request_context,
+ const cryptauth::DeviceClassifier& device_classifier);
+ ~CryptAuthClientFactoryImpl() override;
+
+ // Creates and returns a CryptAuthClient instance that is owned by the caller.
+ scoped_ptr<CryptAuthClient> CreateInstance() override;
+
+ private:
+ OAuth2TokenService* token_service_;
+ const std::string account_id_;
+ const scoped_refptr<net::URLRequestContextGetter> url_request_context_;
+ const cryptauth::DeviceClassifier device_classifier_;
+
+ DISALLOW_COPY_AND_ASSIGN(CryptAuthClientFactoryImpl);
+};
+
+CryptAuthClientFactoryImpl::CryptAuthClientFactoryImpl(
OAuth2TokenService* token_service,
const std::string& account_id,
scoped_refptr<net::URLRequestContextGetter> url_request_context,
@@ -19,14 +48,27 @@ CryptAuthClientFactory::CryptAuthClientFactory(
device_classifier_(device_classifier) {
}
-CryptAuthClientFactory::~CryptAuthClientFactory() {
+CryptAuthClientFactoryImpl::~CryptAuthClientFactoryImpl() {
}
-scoped_ptr<CryptAuthClient> CryptAuthClientFactory::CreateInstance() {
+scoped_ptr<CryptAuthClient> CryptAuthClientFactoryImpl::CreateInstance() {
scoped_ptr<CryptAuthAccessTokenFetcher> access_token_fetcher(
- new CryptAuthAccountTokenFetcher(token_service_, account_id_));
- return make_scoped_ptr(new CryptAuthClient(
- access_token_fetcher.Pass(), url_request_context_, device_classifier_));
+ CryptAuthAccessTokenFetcher::CreateDefault(token_service_, account_id_));
+ return make_scoped_ptr(new CryptAuthClientImpl(
+ make_scoped_ptr(new CryptAuthApiCallFlow()), access_token_fetcher.Pass(),
+ url_request_context_, device_classifier_));
+}
+
+} // namespace
+
+// static.
+scoped_ptr<CryptAuthClientFactory> CryptAuthClientFactory::CreateDefault(
+ OAuth2TokenService* token_service,
+ const std::string& account_id,
+ scoped_refptr<net::URLRequestContextGetter> url_request_context,
+ const cryptauth::DeviceClassifier& device_classifier) {
+ return make_scoped_ptr(new CryptAuthClientFactoryImpl(
+ token_service, account_id, url_request_context, device_classifier));
}
} // namespace proximity_auth

Powered by Google App Engine
This is Rietveld 408576698