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

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

Issue 789353003: Fix CryptAuthApiCallFlow resulting in an error if the server returns an empty string. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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 #include "components/proximity_auth/cryptauth/cryptauth_api_call_flow.h" 5 #include "components/proximity_auth/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 "net/url_request/url_fetcher.h" 8 #include "net/url_request/url_fetcher.h"
9 9
10 namespace proximity_auth { 10 namespace proximity_auth {
11 11
12 namespace { 12 namespace {
13 13
14 const char kNoResponseBodyError[] = "No response body"; 14 const char kResponseBodyError[] = "Failed to get response body";
15 const char kRequestFailedError[] = "Request failed"; 15 const char kRequestFailedError[] = "Request failed";
16 const char kHttpStatusErrorPrefix[] = "HTTP status: "; 16 const char kHttpStatusErrorPrefix[] = "HTTP status: ";
17 17
18 } // namespace 18 } // namespace
19 19
20 CryptAuthApiCallFlow::CryptAuthApiCallFlow(const GURL& request_url) 20 CryptAuthApiCallFlow::CryptAuthApiCallFlow(const GURL& request_url)
21 : request_url_(request_url) { 21 : request_url_(request_url) {
22 } 22 }
23 23
24 CryptAuthApiCallFlow::~CryptAuthApiCallFlow() { 24 CryptAuthApiCallFlow::~CryptAuthApiCallFlow() {
(...skipping 18 matching lines...) Expand all
43 return serialized_request_; 43 return serialized_request_;
44 } 44 }
45 45
46 std::string CryptAuthApiCallFlow::CreateApiCallBodyContentType() { 46 std::string CryptAuthApiCallFlow::CreateApiCallBodyContentType() {
47 return "application/x-protobuf"; 47 return "application/x-protobuf";
48 } 48 }
49 49
50 void CryptAuthApiCallFlow::ProcessApiCallSuccess( 50 void CryptAuthApiCallFlow::ProcessApiCallSuccess(
51 const net::URLFetcher* source) { 51 const net::URLFetcher* source) {
52 std::string serialized_response; 52 std::string serialized_response;
53 if (!source->GetResponseAsString(&serialized_response) || 53 if (!source->GetResponseAsString(&serialized_response)) {
54 serialized_response.empty()) { 54 error_callback_.Run(kResponseBodyError);
55 error_callback_.Run(kNoResponseBodyError);
56 return; 55 return;
57 } 56 }
58 result_callback_.Run(serialized_response); 57 result_callback_.Run(serialized_response);
59 } 58 }
60 59
61 void CryptAuthApiCallFlow::ProcessApiCallFailure( 60 void CryptAuthApiCallFlow::ProcessApiCallFailure(
62 const net::URLFetcher* source) { 61 const net::URLFetcher* source) {
63 std::string error_message; 62 std::string error_message;
64 if (source->GetStatus().status() == net::URLRequestStatus::SUCCESS) { 63 if (source->GetStatus().status() == net::URLRequestStatus::SUCCESS) {
65 error_message = 64 error_message =
66 kHttpStatusErrorPrefix + base::IntToString(source->GetResponseCode()); 65 kHttpStatusErrorPrefix + base::IntToString(source->GetResponseCode());
67 } else { 66 } else {
68 error_message = kRequestFailedError; 67 error_message = kRequestFailedError;
69 } 68 }
70 error_callback_.Run(error_message); 69 error_callback_.Run(error_message);
71 } 70 }
72 71
73 } // proximity_auth 72 } // proximity_auth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698