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

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

Issue 1066453002: Refactor CryptAuth component to be more testable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cryptauth_securemessage
Patch Set: rename tests 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_CRYPTAUTH_API_CALL_FLOW_H 5 #ifndef COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_API_CALL_FLOW_H
6 #define COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_API_CALL_FLOW_H 6 #define COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_API_CALL_FLOW_H
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "google_apis/gaia/oauth2_api_call_flow.h" 12 #include "google_apis/gaia/oauth2_api_call_flow.h"
13 13
14 namespace proximity_auth { 14 namespace proximity_auth {
15 15
16 // Google API call flow implementation underlying all CryptAuth API calls. 16 // Google API call flow implementation underlying all CryptAuth API calls.
17 // CryptAuth is a Google service that manages authorization and cryptographic 17 // CryptAuth is a Google service that manages authorization and cryptographic
18 // credentials for users' devices (eg. public keys). 18 // credentials for users' devices (eg. public keys).
19 class CryptAuthApiCallFlow : public OAuth2ApiCallFlow { 19 class CryptAuthApiCallFlow : public OAuth2ApiCallFlow {
20 public: 20 public:
21 typedef base::Callback<void(const std::string& serialized_response)> 21 typedef base::Callback<void(const std::string& serialized_response)>
22 ResultCallback; 22 ResultCallback;
23 typedef base::Callback<void(const std::string& error_message)> ErrorCallback; 23 typedef base::Callback<void(const std::string& error_message)> ErrorCallback;
24 24
25 CryptAuthApiCallFlow(const GURL& request_url); 25 CryptAuthApiCallFlow();
26 ~CryptAuthApiCallFlow() override; 26 ~CryptAuthApiCallFlow() override;
27 27
28 // Starts the API call. 28 // Starts the API call.
29 // request_url: The URL endpoint of the API request.
29 // context: The URL context used to make the request. 30 // context: The URL context used to make the request.
30 // access_token: The access token for whom to make the to make the request. 31 // access_token: The access token for whom to make the to make the request.
31 // serialized_request: A serialized proto containing the request data. 32 // serialized_request: A serialized proto containing the request data.
32 // result_callback: Called when the flow completes successfully with a 33 // result_callback: Called when the flow completes successfully with a
33 // serialized response proto. 34 // serialized response proto.
34 // error_callback: Called when the flow completes with an error. 35 // error_callback: Called when the flow completes with an error.
35 virtual void Start(net::URLRequestContextGetter* context, 36 virtual void Start(const GURL& request_url,
37 net::URLRequestContextGetter* context,
36 const std::string& access_token, 38 const std::string& access_token,
37 const std::string& serialized_request, 39 const std::string& serialized_request,
38 const ResultCallback& result_callback, 40 const ResultCallback& result_callback,
39 const ErrorCallback& error_callback); 41 const ErrorCallback& error_callback);
40 42
41 protected: 43 protected:
42 // Reduce the visibility of OAuth2ApiCallFlow::Start() to avoid exposing 44 // Reduce the visibility of OAuth2ApiCallFlow::Start() to avoid exposing
43 // overloaded methods. 45 // overloaded methods.
44 using OAuth2ApiCallFlow::Start; 46 using OAuth2ApiCallFlow::Start;
45 47
46 // google_apis::OAuth2ApiCallFlow: 48 // google_apis::OAuth2ApiCallFlow:
47 GURL CreateApiCallUrl() override; 49 GURL CreateApiCallUrl() override;
48 std::string CreateApiCallBody() override; 50 std::string CreateApiCallBody() override;
49 std::string CreateApiCallBodyContentType() override; 51 std::string CreateApiCallBodyContentType() override;
50 void ProcessApiCallSuccess(const net::URLFetcher* source) override; 52 void ProcessApiCallSuccess(const net::URLFetcher* source) override;
51 void ProcessApiCallFailure(const net::URLFetcher* source) override; 53 void ProcessApiCallFailure(const net::URLFetcher* source) override;
52 54
53 private: 55 private:
54 // The URL of the CryptAuth endpoint serving the request. 56 // The URL of the CryptAuth endpoint serving the request.
55 const GURL request_url_; 57 GURL request_url_;
56 58
57 // Serialized request message proto that will be sent in the API request. 59 // Serialized request message proto that will be sent in the API request.
58 std::string serialized_request_; 60 std::string serialized_request_;
59 61
60 // Callback invoked with the serialized response message proto when the flow 62 // Callback invoked with the serialized response message proto when the flow
61 // completes successfully. 63 // completes successfully.
62 ResultCallback result_callback_; 64 ResultCallback result_callback_;
63 65
64 // Callback invoked with an error message when the flow fails. 66 // Callback invoked with an error message when the flow fails.
65 ErrorCallback error_callback_; 67 ErrorCallback error_callback_;
66 68
67 DISALLOW_COPY_AND_ASSIGN(CryptAuthApiCallFlow); 69 DISALLOW_COPY_AND_ASSIGN(CryptAuthApiCallFlow);
68 }; 70 };
69 71
70 } // namespace proximity_auth 72 } // namespace proximity_auth
71 73
72 #endif // COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_API_CALL_FLOW_H 74 #endif // COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_API_CALL_FLOW_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698