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

Side by Side Diff: components/proximity_auth/cryptauth/cryptauth_client_factory.h

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 unified diff | Download patch
OLDNEW
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 #ifndef COMPONENTS_PROXIMITY_AUTH_CRYPT_AUTH_CLIENT_FACTORY_H 5 #ifndef COMPONENTS_PROXIMITY_AUTH_CRYPT_AUTH_CLIENT_FACTORY_H
6 #define COMPONENTS_PROXIMITY_AUTH_CRYPT_AUTH_CLIENT_FACTORY_H 6 #define COMPONENTS_PROXIMITY_AUTH_CRYPT_AUTH_CLIENT_FACTORY_H
7 7
8 #include "base/macros.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "components/proximity_auth/cryptauth/cryptauth_client.h"
11 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h" 10 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h"
12 #include "google_apis/gaia/oauth2_token_service.h" 11
13 #include "net/url_request/url_request_context_getter.h" 12 class OAuth2TokenService;
13
14 namespace net {
15 class URLRequestContextGetter;
16 }
14 17
15 namespace proximity_auth { 18 namespace proximity_auth {
16 19
17 class CryptAuthClient; 20 class CryptAuthClient;
18 21
19 // Factory for creating CryptAuthClient instances. Because each CryptAuthClient 22 // Interface for creating CryptAuthClient instances. Because each
20 // instance can only be used for one API call, this class helps making multiple 23 // CryptAuthClient instance can only be used for one API call, a factory helps
21 // requests in sequence or parallel easier. 24 // making multiple requests in sequence or parallel easier.
Ilya Sherman 2015/04/06 18:53:33 I don't see the advantage of creating an interface
Tim Song 2015/04/06 23:21:17 Discussed in person.
22 class CryptAuthClientFactory { 25 class CryptAuthClientFactory {
23 public: 26 public:
24 // Creates the factory. 27 virtual ~CryptAuthClientFactory() {}
28
29 virtual scoped_ptr<CryptAuthClient> CreateInstance() = 0;
Ilya Sherman 2015/04/06 18:53:34 Why did you make this virtual?
Tim Song 2015/04/06 23:21:17 Discussed in person.
30
31 // Creates a default CryptAuthClientFactory.
25 // |token_service|: Gets the user's access token. 32 // |token_service|: Gets the user's access token.
26 // Needs to outlive this object. 33 // Needs to outlive this object.
27 // |account_id|: The account id of the user. 34 // |account_id|: The account id of the user.
28 // |url_request_context|: The request context to make the HTTP requests. 35 // |url_request_context|: The request context to make the HTTP requests.
29 // |device_classifier|: Contains basic device information of the client. 36 // |device_classifier|: Contains basic device information of the client.
30 CryptAuthClientFactory( 37 static scoped_ptr<CryptAuthClientFactory> CreateDefault(
31 OAuth2TokenService* token_service, 38 OAuth2TokenService* token_service,
32 const std::string& account_id, 39 const std::string& account_id,
33 scoped_refptr<net::URLRequestContextGetter> url_request_context, 40 scoped_refptr<net::URLRequestContextGetter> url_request_context,
34 const cryptauth::DeviceClassifier& device_classifier); 41 const cryptauth::DeviceClassifier& device_classifier);
35 virtual ~CryptAuthClientFactory();
36
37 // Creates and returns a CryptAuthClient instance that is owned by the caller.
38 scoped_ptr<CryptAuthClient> CreateInstance();
39
40 private:
41 OAuth2TokenService* token_service_;
42 const std::string account_id_;
43 const scoped_refptr<net::URLRequestContextGetter> url_request_context_;
44 const cryptauth::DeviceClassifier device_classifier_;
45
46 DISALLOW_COPY_AND_ASSIGN(CryptAuthClientFactory);
47 }; 42 };
48 43
49 } // namespace proximity_auth 44 } // namespace proximity_auth
50 45
51 #endif // COMPONENTS_PROXIMITY_AUTH_CRYPT_AUTH_CLIENT_FACTORY_H 46 #endif // COMPONENTS_PROXIMITY_AUTH_CRYPT_AUTH_CLIENT_FACTORY_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698