Chromium Code Reviews| 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 "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/rand_util.h" | |
| 12 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
| 13 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 15 #include "base/task_runner_util.h" | 14 #include "base/task_runner_util.h" |
| 16 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
| 17 #include "base/values.h" | 16 #include "base/values.h" |
| 18 #include "google_apis/drive/drive_api_parser.h" | 17 #include "google_apis/drive/drive_api_parser.h" |
| 19 #include "google_apis/drive/request_sender.h" | 18 #include "google_apis/drive/request_sender.h" |
| 20 #include "google_apis/drive/request_util.h" | 19 #include "google_apis/drive/request_util.h" |
| 21 #include "google_apis/drive/task_util.h" | 20 #include "google_apis/drive/task_util.h" |
| 22 #include "google_apis/drive/time_util.h" | 21 #include "google_apis/drive/time_util.h" |
| 23 #include "net/base/elements_upload_data_stream.h" | 22 #include "net/base/elements_upload_data_stream.h" |
| 24 #include "net/base/io_buffer.h" | 23 #include "net/base/io_buffer.h" |
| 25 #include "net/base/load_flags.h" | 24 #include "net/base/load_flags.h" |
| 25 #include "net/base/mime_util.h" | |
| 26 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
| 27 #include "net/base/upload_bytes_element_reader.h" | 27 #include "net/base/upload_bytes_element_reader.h" |
| 28 #include "net/base/upload_data_stream.h" | 28 #include "net/base/upload_data_stream.h" |
| 29 #include "net/base/upload_element_reader.h" | 29 #include "net/base/upload_element_reader.h" |
| 30 #include "net/base/upload_file_element_reader.h" | 30 #include "net/base/upload_file_element_reader.h" |
| 31 #include "net/http/http_byte_range.h" | 31 #include "net/http/http_byte_range.h" |
| 32 #include "net/http/http_response_headers.h" | 32 #include "net/http/http_response_headers.h" |
| 33 #include "net/http/http_util.h" | 33 #include "net/http/http_util.h" |
| 34 #include "net/url_request/url_fetcher.h" | 34 #include "net/url_request/url_fetcher.h" |
| 35 #include "net/url_request/url_request_status.h" | 35 #include "net/url_request/url_request_status.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 65 // Mime type of multipart mixed. | 65 // Mime type of multipart mixed. |
| 66 const char kMultipartMixedMimeTypePrefix[] = | 66 const char kMultipartMixedMimeTypePrefix[] = |
| 67 "multipart/mixed; boundary="; | 67 "multipart/mixed; boundary="; |
| 68 | 68 |
| 69 // Header for each item in a multipart message. | 69 // Header for each item in a multipart message. |
| 70 const char kMultipartItemHeaderFormat[] = "--%s\nContent-Type: %s\n\n"; | 70 const char kMultipartItemHeaderFormat[] = "--%s\nContent-Type: %s\n\n"; |
| 71 | 71 |
| 72 // Footer for whole multipart message. | 72 // Footer for whole multipart message. |
| 73 const char kMultipartFooterFormat[] = "--%s--"; | 73 const char kMultipartFooterFormat[] = "--%s--"; |
| 74 | 74 |
| 75 // Characters to be used for multipart/related boundary. | |
| 76 const char kBoundaryCharacters[] = | |
| 77 "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
| 78 | |
| 79 // Size of multipart/related's boundary. | |
| 80 const char kBoundarySize = 70; | |
| 81 | |
| 82 // Parses JSON passed in |json| on |blocking_task_runner|. Runs |callback| on | 75 // Parses JSON passed in |json| on |blocking_task_runner|. Runs |callback| on |
| 83 // the calling thread when finished with either success or failure. | 76 // the calling thread when finished with either success or failure. |
| 84 // The callback must not be null. | 77 // The callback must not be null. |
| 85 void ParseJsonOnBlockingPool( | 78 void ParseJsonOnBlockingPool( |
| 86 base::TaskRunner* blocking_task_runner, | 79 base::TaskRunner* blocking_task_runner, |
| 87 const std::string& json, | 80 const std::string& json, |
| 88 const base::Callback<void(scoped_ptr<base::Value> value)>& callback) { | 81 const base::Callback<void(scoped_ptr<base::Value> value)>& callback) { |
| 89 base::PostTaskAndReplyWithResult( | 82 base::PostTaskAndReplyWithResult( |
| 90 blocking_task_runner, | 83 blocking_task_runner, |
| 91 FROM_HERE, | 84 FROM_HERE, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 | 209 |
| 217 void GenerateMultipartBody(MultipartType multipart_type, | 210 void GenerateMultipartBody(MultipartType multipart_type, |
| 218 const std::string& predetermined_boundary, | 211 const std::string& predetermined_boundary, |
| 219 const std::vector<ContentTypeAndData>& parts, | 212 const std::vector<ContentTypeAndData>& parts, |
| 220 ContentTypeAndData* output, | 213 ContentTypeAndData* output, |
| 221 std::vector<uint64>* data_offset) { | 214 std::vector<uint64>* data_offset) { |
| 222 std::string boundary; | 215 std::string boundary; |
| 223 // Generate random boundary. | 216 // Generate random boundary. |
| 224 if (predetermined_boundary.empty()) { | 217 if (predetermined_boundary.empty()) { |
| 225 while (true) { | 218 while (true) { |
| 226 boundary.resize(kBoundarySize); | 219 boundary = net::GenerateMimeMultipartBoundary(); |
|
Ryan Sleevi
2015/12/28 23:30:00
Ditto as to whether needed?
Łukasz Anforowicz
2015/12/29 18:53:19
Done.
| |
| 227 for (int i = 0; i < kBoundarySize; ++i) { | |
| 228 // Subtract 2 from the array size to exclude '\0', and to turn the size | |
| 229 // into the last index. | |
| 230 const int last_char_index = arraysize(kBoundaryCharacters) - 2; | |
| 231 boundary[i] = kBoundaryCharacters[base::RandInt(0, last_char_index)]; | |
| 232 } | |
| 233 bool conflict_with_content = false; | 220 bool conflict_with_content = false; |
| 234 for (auto& part : parts) { | 221 for (auto& part : parts) { |
| 235 if (part.data.find(boundary, 0) != std::string::npos) { | 222 if (part.data.find(boundary, 0) != std::string::npos) { |
| 236 conflict_with_content = true; | 223 conflict_with_content = true; |
| 237 break; | 224 break; |
| 238 } | 225 } |
| 239 } | 226 } |
| 240 if (!conflict_with_content) | 227 if (!conflict_with_content) |
| 241 break; | 228 break; |
| 242 } | 229 } |
| (...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1013 download_action_callback_.Run(code, temp_file); | 1000 download_action_callback_.Run(code, temp_file); |
| 1014 OnProcessURLFetchResultsComplete(); | 1001 OnProcessURLFetchResultsComplete(); |
| 1015 } | 1002 } |
| 1016 | 1003 |
| 1017 void DownloadFileRequestBase::RunCallbackOnPrematureFailure( | 1004 void DownloadFileRequestBase::RunCallbackOnPrematureFailure( |
| 1018 DriveApiErrorCode code) { | 1005 DriveApiErrorCode code) { |
| 1019 download_action_callback_.Run(code, base::FilePath()); | 1006 download_action_callback_.Run(code, base::FilePath()); |
| 1020 } | 1007 } |
| 1021 | 1008 |
| 1022 } // namespace google_apis | 1009 } // namespace google_apis |
| OLD | NEW |