OLD | NEW |
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_CRYPTAUTH_CRYPTAUTH_CLIENT_IMPL_H_ | 5 #ifndef COMPONENTS_CRYPTAUTH_CRYPTAUTH_CLIENT_IMPL_H_ |
6 #define COMPONENTS_CRYPTAUTH_CRYPTAUTH_CLIENT_IMPL_H_ | 6 #define COMPONENTS_CRYPTAUTH_CRYPTAUTH_CLIENT_IMPL_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "components/cryptauth/cryptauth_access_token_fetcher.h" | 10 #include "components/cryptauth/cryptauth_access_token_fetcher.h" |
11 #include "components/cryptauth/cryptauth_api_call_flow.h" | 11 #include "components/cryptauth/cryptauth_api_call_flow.h" |
12 #include "components/cryptauth/cryptauth_client.h" | 12 #include "components/cryptauth/cryptauth_client.h" |
13 #include "components/cryptauth/proto/cryptauth_api.pb.h" | 13 #include "components/cryptauth/proto/cryptauth_api.pb.h" |
| 14 #include "net/traffic_annotation/network_traffic_annotation.h" |
14 #include "net/url_request/url_request_context_getter.h" | 15 #include "net/url_request/url_request_context_getter.h" |
15 | 16 |
16 class OAuth2TokenService; | 17 class OAuth2TokenService; |
17 | 18 |
18 namespace cryptauth { | 19 namespace cryptauth { |
19 | 20 |
20 // Implementation of CryptAuthClient. | 21 // Implementation of CryptAuthClient. |
21 // Note: There is no need to set the |device_classifier| field in request | 22 // Note: There is no need to set the |device_classifier| field in request |
22 // messages. CryptAuthClient will fill this field for all requests. | 23 // messages. CryptAuthClient will fill this field for all requests. |
23 class CryptAuthClientImpl : public CryptAuthClient { | 24 class CryptAuthClientImpl : public CryptAuthClient { |
24 public: | 25 public: |
25 typedef base::Callback<void(const std::string&)> ErrorCallback; | 26 typedef base::Callback<void(const std::string&)> ErrorCallback; |
26 | 27 |
27 // Creates the client using |url_request_context| to make the HTTP request | 28 // Creates the client using |url_request_context| to make the HTTP request |
28 // through |api_call_flow|. CryptAuthClientImpl takes ownership of | 29 // through |api_call_flow|. CryptAuthClientImpl takes ownership of |
29 // |access_token_fetcher|, which provides the access token authorizing | 30 // |access_token_fetcher|, which provides the access token authorizing |
30 // CryptAuth requests. The |device_classifier| argument contains basic device | 31 // CryptAuth requests. The |device_classifier| argument contains basic device |
31 // information of the caller (e.g. version and device type). | 32 // information of the caller (e.g. version and device type). |
32 CryptAuthClientImpl( | 33 CryptAuthClientImpl( |
33 std::unique_ptr<CryptAuthApiCallFlow> api_call_flow, | 34 std::unique_ptr<CryptAuthApiCallFlow> api_call_flow, |
34 std::unique_ptr<CryptAuthAccessTokenFetcher> access_token_fetcher, | 35 std::unique_ptr<CryptAuthAccessTokenFetcher> access_token_fetcher, |
35 scoped_refptr<net::URLRequestContextGetter> url_request_context, | 36 scoped_refptr<net::URLRequestContextGetter> url_request_context, |
36 const DeviceClassifier& device_classifier); | 37 const DeviceClassifier& device_classifier); |
37 ~CryptAuthClientImpl() override; | 38 ~CryptAuthClientImpl() override; |
38 | 39 |
39 // CryptAuthClient: | 40 // CryptAuthClient: |
40 void GetMyDevices(const GetMyDevicesRequest& request, | 41 void GetMyDevices(const GetMyDevicesRequest& request, |
41 const GetMyDevicesCallback& callback, | 42 const GetMyDevicesCallback& callback, |
42 const ErrorCallback& error_callback) override; | 43 const ErrorCallback& error_callback, |
| 44 const net::PartialNetworkTrafficAnnotationTag& |
| 45 partial_traffic_annotation) override; |
43 void FindEligibleUnlockDevices( | 46 void FindEligibleUnlockDevices( |
44 const FindEligibleUnlockDevicesRequest& request, | 47 const FindEligibleUnlockDevicesRequest& request, |
45 const FindEligibleUnlockDevicesCallback& callback, | 48 const FindEligibleUnlockDevicesCallback& callback, |
46 const ErrorCallback& error_callback) override; | 49 const ErrorCallback& error_callback) override; |
47 void SendDeviceSyncTickle( | 50 void SendDeviceSyncTickle(const SendDeviceSyncTickleRequest& request, |
48 const SendDeviceSyncTickleRequest& request, | 51 const SendDeviceSyncTickleCallback& callback, |
49 const SendDeviceSyncTickleCallback& callback, | 52 const ErrorCallback& error_callback, |
50 const ErrorCallback& error_callback) override; | 53 const net::PartialNetworkTrafficAnnotationTag& |
| 54 partial_traffic_annotation) override; |
51 void ToggleEasyUnlock(const ToggleEasyUnlockRequest& request, | 55 void ToggleEasyUnlock(const ToggleEasyUnlockRequest& request, |
52 const ToggleEasyUnlockCallback& callback, | 56 const ToggleEasyUnlockCallback& callback, |
53 const ErrorCallback& error_callback) override; | 57 const ErrorCallback& error_callback) override; |
54 void SetupEnrollment(const SetupEnrollmentRequest& request, | 58 void SetupEnrollment(const SetupEnrollmentRequest& request, |
55 const SetupEnrollmentCallback& callback, | 59 const SetupEnrollmentCallback& callback, |
56 const ErrorCallback& error_callback) override; | 60 const ErrorCallback& error_callback) override; |
57 void FinishEnrollment(const FinishEnrollmentRequest& request, | 61 void FinishEnrollment(const FinishEnrollmentRequest& request, |
58 const FinishEnrollmentCallback& callback, | 62 const FinishEnrollmentCallback& callback, |
59 const ErrorCallback& error_callback) override; | 63 const ErrorCallback& error_callback) override; |
60 std::string GetAccessTokenUsed() override; | 64 std::string GetAccessTokenUsed() override; |
61 | 65 |
62 private: | 66 private: |
63 // Starts a call to the API given by |request_path|, with the templated | 67 // Starts a call to the API given by |request_path|, with the templated |
64 // request and response types. The client first fetches the access token and | 68 // request and response types. The client first fetches the access token and |
65 // then makes the HTTP request. | 69 // then makes the HTTP request. |
66 template <class RequestProto, class ResponseProto> | 70 template <class RequestProto, class ResponseProto> |
67 void MakeApiCall( | 71 void MakeApiCall( |
68 const std::string& request_path, | 72 const std::string& request_path, |
69 const RequestProto& request_proto, | 73 const RequestProto& request_proto, |
70 const base::Callback<void(const ResponseProto&)>& response_callback, | 74 const base::Callback<void(const ResponseProto&)>& response_callback, |
71 const ErrorCallback& error_callback); | 75 const ErrorCallback& error_callback, |
| 76 const net::PartialNetworkTrafficAnnotationTag& |
| 77 partial_traffic_annotation); |
72 | 78 |
73 // Called when the access token is obtained so the API request can be made. | 79 // Called when the access token is obtained so the API request can be made. |
74 template <class ResponseProto> | 80 template <class ResponseProto> |
75 void OnAccessTokenFetched( | 81 void OnAccessTokenFetched( |
76 const std::string& serialized_request, | 82 const std::string& serialized_request, |
77 const base::Callback<void(const ResponseProto&)>& response_callback, | 83 const base::Callback<void(const ResponseProto&)>& response_callback, |
78 const std::string& access_token); | 84 const std::string& access_token); |
79 | 85 |
80 // Called with CryptAuthApiCallFlow completes successfully to deserialize and | 86 // Called with CryptAuthApiCallFlow completes successfully to deserialize and |
81 // return the result. | 87 // return the result. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 const std::string account_id_; | 147 const std::string account_id_; |
142 const scoped_refptr<net::URLRequestContextGetter> url_request_context_; | 148 const scoped_refptr<net::URLRequestContextGetter> url_request_context_; |
143 const DeviceClassifier device_classifier_; | 149 const DeviceClassifier device_classifier_; |
144 | 150 |
145 DISALLOW_COPY_AND_ASSIGN(CryptAuthClientFactoryImpl); | 151 DISALLOW_COPY_AND_ASSIGN(CryptAuthClientFactoryImpl); |
146 }; | 152 }; |
147 | 153 |
148 } // namespace cryptauth | 154 } // namespace cryptauth |
149 | 155 |
150 #endif // COMPONENTS_CRYPTAUTH_CRYPTAUTH_CLIENT_IMPL_H_ | 156 #endif // COMPONENTS_CRYPTAUTH_CRYPTAUTH_CLIENT_IMPL_H_ |
OLD | NEW |