OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 GOOGLE_APIS_GAIA_OAUTH2_API_CALL_FLOW_H_ | 5 #ifndef GOOGLE_APIS_GAIA_OAUTH2_API_CALL_FLOW_H_ |
6 #define GOOGLE_APIS_GAIA_OAUTH2_API_CALL_FLOW_H_ | 6 #define GOOGLE_APIS_GAIA_OAUTH2_API_CALL_FLOW_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "net/traffic_annotation/network_traffic_annotation.h" |
12 #include "net/url_request/url_fetcher.h" | 13 #include "net/url_request/url_fetcher.h" |
13 #include "net/url_request/url_fetcher_delegate.h" | 14 #include "net/url_request/url_fetcher_delegate.h" |
14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
15 | 16 |
16 namespace net { | 17 namespace net { |
17 class URLFetcher; | 18 class URLFetcher; |
18 class URLRequestContextGetter; | 19 class URLRequestContextGetter; |
19 } | 20 } |
20 | 21 |
21 // Base class for all classes that implement a flow to call OAuth2 enabled APIs, | 22 // Base class for all classes that implement a flow to call OAuth2 enabled APIs, |
(...skipping 26 matching lines...) Expand all Loading... |
48 virtual net::URLFetcher::RequestType GetRequestTypeForBody( | 49 virtual net::URLFetcher::RequestType GetRequestTypeForBody( |
49 const std::string& body); | 50 const std::string& body); |
50 | 51 |
51 // Sub-classes can expose an appropriate observer interface by implementing | 52 // Sub-classes can expose an appropriate observer interface by implementing |
52 // these template methods. | 53 // these template methods. |
53 // Called when the API call finished successfully. | 54 // Called when the API call finished successfully. |
54 virtual void ProcessApiCallSuccess(const net::URLFetcher* source) = 0; | 55 virtual void ProcessApiCallSuccess(const net::URLFetcher* source) = 0; |
55 // Called when the API call failed. | 56 // Called when the API call failed. |
56 virtual void ProcessApiCallFailure(const net::URLFetcher* source) = 0; | 57 virtual void ProcessApiCallFailure(const net::URLFetcher* source) = 0; |
57 | 58 |
| 59 virtual net::PartialNetworkTrafficAnnotationTag |
| 60 GetNetworkTrafficAnnotationTag() = 0; |
| 61 |
58 private: | 62 private: |
59 enum State { | 63 enum State { |
60 INITIAL, | 64 INITIAL, |
61 API_CALL_STARTED, | 65 API_CALL_STARTED, |
62 API_CALL_DONE, | 66 API_CALL_DONE, |
63 ERROR_STATE | 67 ERROR_STATE |
64 }; | 68 }; |
65 | 69 |
66 // Creates an instance of URLFetcher that does not send or save cookies. | 70 // Creates an instance of URLFetcher that does not send or save cookies. |
67 // Template method CreateApiCallUrl is used to get the URL. | 71 // Template method CreateApiCallUrl is used to get the URL. |
68 // Template method CreateApiCallBody is used to get the body. | 72 // Template method CreateApiCallBody is used to get the body. |
69 // The URLFether's method will be GET if body is empty, POST otherwise. | 73 // The URLFether's method will be GET if body is empty, POST otherwise. |
70 std::unique_ptr<net::URLFetcher> CreateURLFetcher( | 74 std::unique_ptr<net::URLFetcher> CreateURLFetcher( |
71 net::URLRequestContextGetter* context, | 75 net::URLRequestContextGetter* context, |
72 const std::string& access_token); | 76 const std::string& access_token); |
73 | 77 |
74 // Helper methods to implement the state machine for the flow. | 78 // Helper methods to implement the state machine for the flow. |
75 void BeginApiCall(); | 79 void BeginApiCall(); |
76 void EndApiCall(const net::URLFetcher* source); | 80 void EndApiCall(const net::URLFetcher* source); |
77 | 81 |
78 State state_; | 82 State state_; |
79 std::unique_ptr<net::URLFetcher> url_fetcher_; | 83 std::unique_ptr<net::URLFetcher> url_fetcher_; |
80 | 84 |
81 DISALLOW_COPY_AND_ASSIGN(OAuth2ApiCallFlow); | 85 DISALLOW_COPY_AND_ASSIGN(OAuth2ApiCallFlow); |
82 }; | 86 }; |
83 | 87 |
84 #endif // GOOGLE_APIS_GAIA_OAUTH2_API_CALL_FLOW_H_ | 88 #endif // GOOGLE_APIS_GAIA_OAUTH2_API_CALL_FLOW_H_ |
OLD | NEW |