Chromium Code Reviews| 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 #include "components/cryptauth/cryptauth_api_call_flow.h" | 5 #include "components/cryptauth/cryptauth_api_call_flow.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "components/proximity_auth/logging/logging.h" | 8 #include "components/proximity_auth/logging/logging.h" |
| 9 #include "net/traffic_annotation/network_traffic_annotation.h" | |
| 9 #include "net/url_request/url_fetcher.h" | 10 #include "net/url_request/url_fetcher.h" |
| 10 | 11 |
| 11 namespace cryptauth { | 12 namespace cryptauth { |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 const char kResponseBodyError[] = "Failed to get response body"; | 16 const char kResponseBodyError[] = "Failed to get response body"; |
| 16 const char kRequestFailedError[] = "Request failed"; | 17 const char kRequestFailedError[] = "Request failed"; |
| 17 const char kHttpStatusErrorPrefix[] = "HTTP status: "; | 18 const char kHttpStatusErrorPrefix[] = "HTTP status: "; |
| 18 | 19 |
| 19 } // namespace | 20 } // namespace |
| 20 | 21 |
| 21 CryptAuthApiCallFlow::CryptAuthApiCallFlow() { | 22 CryptAuthApiCallFlow::CryptAuthApiCallFlow() { |
| 22 } | 23 } |
| 23 | 24 |
| 24 CryptAuthApiCallFlow::~CryptAuthApiCallFlow() { | 25 CryptAuthApiCallFlow::~CryptAuthApiCallFlow() { |
| 25 } | 26 } |
| 26 | 27 |
| 27 void CryptAuthApiCallFlow::Start(const GURL& request_url, | 28 void CryptAuthApiCallFlow::Start(const GURL& request_url, |
| 28 net::URLRequestContextGetter* context, | 29 net::URLRequestContextGetter* context, |
| 29 const std::string& access_token, | 30 const std::string& access_token, |
| 30 const std::string& serialized_request, | 31 const std::string& serialized_request, |
| 31 const ResultCallback& result_callback, | 32 const ResultCallback& result_callback, |
| 32 const ErrorCallback& error_callback) { | 33 const ErrorCallback& error_callback) { |
| 33 request_url_ = request_url; | 34 request_url_ = request_url; |
| 34 serialized_request_ = serialized_request; | 35 serialized_request_ = serialized_request; |
| 35 result_callback_ = result_callback; | 36 result_callback_ = result_callback; |
| 36 error_callback_ = error_callback; | 37 error_callback_ = error_callback; |
| 37 OAuth2ApiCallFlow::Start(context, access_token); | 38 net::NetworkTrafficAnnotationTag traffic_annotation = |
| 39 net::DefineNetworkTrafficAnnotation("...", R"( | |
| 40 semantics { | |
| 41 sender: "..." | |
| 42 description: "..." | |
|
Tim Song
2017/05/17 19:10:37
This class is a generic wrapper for all API calls
Ramin Halavati
2017/05/24 13:04:41
Done.
| |
| 43 trigger: "..." | |
| 44 data: "..." | |
| 45 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER/LOCAL | |
| 46 } | |
| 47 policy { | |
| 48 cookies_allowed: false/true | |
| 49 cookies_store: "..." | |
| 50 setting: "..." | |
| 51 chrome_policy { | |
| 52 [POLICY_NAME] { | |
| 53 policy_options {mode: MANDATORY/RECOMMENDED/UNSET} | |
| 54 [POLICY_NAME]: ... //(value to disable it) | |
| 55 } | |
| 56 } | |
| 57 policy_exception_justification: "..." | |
| 58 })"); | |
| 59 OAuth2ApiCallFlow::Start(context, access_token, traffic_annotation); | |
| 38 } | 60 } |
| 39 | 61 |
| 40 GURL CryptAuthApiCallFlow::CreateApiCallUrl() { | 62 GURL CryptAuthApiCallFlow::CreateApiCallUrl() { |
| 41 return request_url_; | 63 return request_url_; |
| 42 } | 64 } |
| 43 | 65 |
| 44 std::string CryptAuthApiCallFlow::CreateApiCallBody() { | 66 std::string CryptAuthApiCallFlow::CreateApiCallBody() { |
| 45 return serialized_request_; | 67 return serialized_request_; |
| 46 } | 68 } |
| 47 | 69 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 74 error_message = kRequestFailedError; | 96 error_message = kRequestFailedError; |
| 75 } | 97 } |
| 76 | 98 |
| 77 std::string response; | 99 std::string response; |
| 78 source->GetResponseAsString(&response); | 100 source->GetResponseAsString(&response); |
| 79 PA_LOG(INFO) << "API call failed:\n" << response; | 101 PA_LOG(INFO) << "API call failed:\n" << response; |
| 80 error_callback_.Run(error_message); | 102 error_callback_.Run(error_message); |
| 81 } | 103 } |
| 82 | 104 |
| 83 } // namespace cryptauth | 105 } // namespace cryptauth |
| OLD | NEW |