OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/proximity_auth/cryptauth/cryptauth_client_factory.h" | 5 #include "components/proximity_auth/cryptauth/cryptauth_client_factory.h" |
6 | 6 |
7 #include "components/proximity_auth/cryptauth/cryptauth_account_token_fetcher.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/weak_ptr.h" |
| 9 #include "components/proximity_auth/cryptauth/cryptauth_access_token_fetcher.h" |
| 10 #include "components/proximity_auth/cryptauth/cryptauth_api_call_flow.h" |
| 11 #include "components/proximity_auth/cryptauth/cryptauth_client_impl.h" |
| 12 #include "google_apis/gaia/oauth2_token_service.h" |
| 13 #include "net/url_request/url_request_context_getter.h" |
8 | 14 |
9 namespace proximity_auth { | 15 namespace proximity_auth { |
10 | 16 |
11 CryptAuthClientFactory::CryptAuthClientFactory( | 17 namespace { |
| 18 |
| 19 class CryptAuthClientFactoryImpl : public CryptAuthClientFactory { |
| 20 public: |
| 21 CryptAuthClientFactoryImpl( |
| 22 OAuth2TokenService* token_service, |
| 23 const std::string& account_id, |
| 24 scoped_refptr<net::URLRequestContextGetter> url_request_context, |
| 25 const cryptauth::DeviceClassifier& device_classifier); |
| 26 ~CryptAuthClientFactoryImpl() override; |
| 27 |
| 28 // Creates and returns a CryptAuthClient instance that is owned by the caller. |
| 29 scoped_ptr<CryptAuthClient> CreateInstance() override; |
| 30 |
| 31 private: |
| 32 OAuth2TokenService* token_service_; |
| 33 const std::string account_id_; |
| 34 const scoped_refptr<net::URLRequestContextGetter> url_request_context_; |
| 35 const cryptauth::DeviceClassifier device_classifier_; |
| 36 |
| 37 DISALLOW_COPY_AND_ASSIGN(CryptAuthClientFactoryImpl); |
| 38 }; |
| 39 |
| 40 CryptAuthClientFactoryImpl::CryptAuthClientFactoryImpl( |
12 OAuth2TokenService* token_service, | 41 OAuth2TokenService* token_service, |
13 const std::string& account_id, | 42 const std::string& account_id, |
14 scoped_refptr<net::URLRequestContextGetter> url_request_context, | 43 scoped_refptr<net::URLRequestContextGetter> url_request_context, |
15 const cryptauth::DeviceClassifier& device_classifier) | 44 const cryptauth::DeviceClassifier& device_classifier) |
16 : token_service_(token_service), | 45 : token_service_(token_service), |
17 account_id_(account_id), | 46 account_id_(account_id), |
18 url_request_context_(url_request_context), | 47 url_request_context_(url_request_context), |
19 device_classifier_(device_classifier) { | 48 device_classifier_(device_classifier) { |
20 } | 49 } |
21 | 50 |
22 CryptAuthClientFactory::~CryptAuthClientFactory() { | 51 CryptAuthClientFactoryImpl::~CryptAuthClientFactoryImpl() { |
23 } | 52 } |
24 | 53 |
25 scoped_ptr<CryptAuthClient> CryptAuthClientFactory::CreateInstance() { | 54 scoped_ptr<CryptAuthClient> CryptAuthClientFactoryImpl::CreateInstance() { |
26 scoped_ptr<CryptAuthAccessTokenFetcher> access_token_fetcher( | 55 scoped_ptr<CryptAuthAccessTokenFetcher> access_token_fetcher( |
27 new CryptAuthAccountTokenFetcher(token_service_, account_id_)); | 56 CryptAuthAccessTokenFetcher::CreateDefault(token_service_, account_id_)); |
28 return make_scoped_ptr(new CryptAuthClient( | 57 return make_scoped_ptr(new CryptAuthClientImpl( |
29 access_token_fetcher.Pass(), url_request_context_, device_classifier_)); | 58 make_scoped_ptr(new CryptAuthApiCallFlow()), access_token_fetcher.Pass(), |
| 59 url_request_context_, device_classifier_)); |
| 60 } |
| 61 |
| 62 } // namespace |
| 63 |
| 64 // static. |
| 65 scoped_ptr<CryptAuthClientFactory> CryptAuthClientFactory::CreateDefault( |
| 66 OAuth2TokenService* token_service, |
| 67 const std::string& account_id, |
| 68 scoped_refptr<net::URLRequestContextGetter> url_request_context, |
| 69 const cryptauth::DeviceClassifier& device_classifier) { |
| 70 return make_scoped_ptr(new CryptAuthClientFactoryImpl( |
| 71 token_service, account_id, url_request_context, device_classifier)); |
30 } | 72 } |
31 | 73 |
32 } // namespace proximity_auth | 74 } // namespace proximity_auth |
OLD | NEW |