| 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 #include "google_apis/drive/base_requests.h" | 5 #include "google_apis/drive/base_requests.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 10 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
| 11 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 12 #include "base/location.h" | 13 #include "base/location.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/rand_util.h" | 15 #include "base/rand_util.h" |
| 15 #include "base/sequenced_task_runner.h" | 16 #include "base/sequenced_task_runner.h" |
| 16 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 // Take the first 50 and the last 10 bytes. | 208 // Take the first 50 and the last 10 bytes. |
| 208 trimmed_json = base::StringPrintf( | 209 trimmed_json = base::StringPrintf( |
| 209 "%s [%s bytes] %s", | 210 "%s [%s bytes] %s", |
| 210 json.substr(0, 50).c_str(), | 211 json.substr(0, 50).c_str(), |
| 211 base::Uint64ToString(json.size() - 60).c_str(), | 212 base::Uint64ToString(json.size() - 60).c_str(), |
| 212 json.substr(json.size() - 10).c_str()); | 213 json.substr(json.size() - 10).c_str()); |
| 213 } | 214 } |
| 214 LOG(WARNING) << "Error while parsing entry response: " << error_message | 215 LOG(WARNING) << "Error while parsing entry response: " << error_message |
| 215 << ", code: " << error_code << ", json:\n" << trimmed_json; | 216 << ", code: " << error_code << ", json:\n" << trimmed_json; |
| 216 } | 217 } |
| 217 return value.Pass(); | 218 return value; |
| 218 } | 219 } |
| 219 | 220 |
| 220 void GenerateMultipartBody(MultipartType multipart_type, | 221 void GenerateMultipartBody(MultipartType multipart_type, |
| 221 const std::string& predetermined_boundary, | 222 const std::string& predetermined_boundary, |
| 222 const std::vector<ContentTypeAndData>& parts, | 223 const std::vector<ContentTypeAndData>& parts, |
| 223 ContentTypeAndData* output, | 224 ContentTypeAndData* output, |
| 224 std::vector<uint64_t>* data_offset) { | 225 std::vector<uint64_t>* data_offset) { |
| 225 std::string boundary; | 226 std::string boundary; |
| 226 // Generate random boundary. | 227 // Generate random boundary. |
| 227 if (predetermined_boundary.empty()) { | 228 if (predetermined_boundary.empty()) { |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 UploadRangeResponse(code, -1, -1), scoped_ptr<base::Value>()); | 736 UploadRangeResponse(code, -1, -1), scoped_ptr<base::Value>()); |
| 736 OnProcessURLFetchResultsComplete(); | 737 OnProcessURLFetchResultsComplete(); |
| 737 } | 738 } |
| 738 } | 739 } |
| 739 | 740 |
| 740 void UploadRangeRequestBase::OnDataParsed(DriveApiErrorCode code, | 741 void UploadRangeRequestBase::OnDataParsed(DriveApiErrorCode code, |
| 741 scoped_ptr<base::Value> value) { | 742 scoped_ptr<base::Value> value) { |
| 742 DCHECK(CalledOnValidThread()); | 743 DCHECK(CalledOnValidThread()); |
| 743 DCHECK(code == HTTP_CREATED || code == HTTP_SUCCESS); | 744 DCHECK(code == HTTP_CREATED || code == HTTP_SUCCESS); |
| 744 | 745 |
| 745 OnRangeRequestComplete(UploadRangeResponse(code, -1, -1), value.Pass()); | 746 OnRangeRequestComplete(UploadRangeResponse(code, -1, -1), std::move(value)); |
| 746 OnProcessURLFetchResultsComplete(); | 747 OnProcessURLFetchResultsComplete(); |
| 747 } | 748 } |
| 748 | 749 |
| 749 void UploadRangeRequestBase::RunCallbackOnPrematureFailure( | 750 void UploadRangeRequestBase::RunCallbackOnPrematureFailure( |
| 750 DriveApiErrorCode code) { | 751 DriveApiErrorCode code) { |
| 751 OnRangeRequestComplete( | 752 OnRangeRequestComplete( |
| 752 UploadRangeResponse(code, 0, 0), scoped_ptr<base::Value>()); | 753 UploadRangeResponse(code, 0, 0), scoped_ptr<base::Value>()); |
| 753 } | 754 } |
| 754 | 755 |
| 755 //========================== ResumeUploadRequestBase ========================= | 756 //========================== ResumeUploadRequestBase ========================= |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1014 download_action_callback_.Run(code, temp_file); | 1015 download_action_callback_.Run(code, temp_file); |
| 1015 OnProcessURLFetchResultsComplete(); | 1016 OnProcessURLFetchResultsComplete(); |
| 1016 } | 1017 } |
| 1017 | 1018 |
| 1018 void DownloadFileRequestBase::RunCallbackOnPrematureFailure( | 1019 void DownloadFileRequestBase::RunCallbackOnPrematureFailure( |
| 1019 DriveApiErrorCode code) { | 1020 DriveApiErrorCode code) { |
| 1020 download_action_callback_.Run(code, base::FilePath()); | 1021 download_action_callback_.Run(code, base::FilePath()); |
| 1021 } | 1022 } |
| 1022 | 1023 |
| 1023 } // namespace google_apis | 1024 } // namespace google_apis |
| OLD | NEW |