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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_API_CALL_FLOW_H
6 #define COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_API_CALL_FLOW_H
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "google_apis/gaia/oauth2_api_call_flow.h"
14 namespace proximity_auth
{
16 // Google API call flow implementation underlying all CryptAuth API calls.
17 // CryptAuth is a Google service that manages authorization and cryptographic
18 // credentials for users' devices (eg. public keys).
19 class CryptAuthApiCallFlow
: public OAuth2ApiCallFlow
{
21 typedef base::Callback
<void(const std::string
& serialized_response
)>
23 typedef base::Callback
<void(const std::string
& error_message
)> ErrorCallback
;
25 CryptAuthApiCallFlow();
26 ~CryptAuthApiCallFlow() override
;
28 // Starts the API call.
29 // request_url: The URL endpoint of the API request.
30 // context: The URL context used to make the request.
31 // access_token: The access token for whom to make the to make the request.
32 // serialized_request: A serialized proto containing the request data.
33 // result_callback: Called when the flow completes successfully with a
34 // serialized response proto.
35 // error_callback: Called when the flow completes with an error.
36 virtual void Start(const GURL
& request_url
,
37 net::URLRequestContextGetter
* context
,
38 const std::string
& access_token
,
39 const std::string
& serialized_request
,
40 const ResultCallback
& result_callback
,
41 const ErrorCallback
& error_callback
);
44 // Reduce the visibility of OAuth2ApiCallFlow::Start() to avoid exposing
45 // overloaded methods.
46 using OAuth2ApiCallFlow::Start
;
48 // google_apis::OAuth2ApiCallFlow:
49 GURL
CreateApiCallUrl() override
;
50 std::string
CreateApiCallBody() override
;
51 std::string
CreateApiCallBodyContentType() override
;
52 net::URLFetcher::RequestType
GetRequestTypeForBody(
53 const std::string
& body
) override
;
54 void ProcessApiCallSuccess(const net::URLFetcher
* source
) override
;
55 void ProcessApiCallFailure(const net::URLFetcher
* source
) override
;
58 // The URL of the CryptAuth endpoint serving the request.
61 // Serialized request message proto that will be sent in the API request.
62 std::string serialized_request_
;
64 // Callback invoked with the serialized response message proto when the flow
65 // completes successfully.
66 ResultCallback result_callback_
;
68 // Callback invoked with an error message when the flow fails.
69 ErrorCallback error_callback_
;
71 DISALLOW_COPY_AND_ASSIGN(CryptAuthApiCallFlow
);
74 } // namespace proximity_auth
76 #endif // COMPONENTS_PROXIMITY_AUTH_CRYPTAUTH_API_CALL_FLOW_H