| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 "chrome/browser/chromeos/policy/upload_job_impl.h" | 5 #include "chrome/browser/chromeos/policy/upload_job_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 bool UploadJobImpl::SetUpMultipart() { | 205 bool UploadJobImpl::SetUpMultipart() { |
| 206 DCHECK_EQ(ACQUIRING_TOKEN, state_); | 206 DCHECK_EQ(ACQUIRING_TOKEN, state_); |
| 207 state_ = PREPARING_CONTENT; | 207 state_ = PREPARING_CONTENT; |
| 208 | 208 |
| 209 if (mime_boundary_ && post_data_) | 209 if (mime_boundary_ && post_data_) |
| 210 return true; | 210 return true; |
| 211 | 211 |
| 212 std::set<std::string> used_names; | 212 std::set<std::string> used_names; |
| 213 | 213 |
| 214 // Check uniqueness of header field names. | 214 // Check uniqueness of header field names. |
| 215 for (const auto& data_segment : data_segments_) { | 215 for (auto* data_segment : data_segments_) { |
| 216 if (!used_names.insert(data_segment->GetName()).second) | 216 if (!used_names.insert(data_segment->GetName()).second) |
| 217 return false; | 217 return false; |
| 218 } | 218 } |
| 219 | 219 |
| 220 mime_boundary_.reset( | 220 mime_boundary_.reset( |
| 221 new std::string(boundary_generator_->GenerateBoundary())); | 221 new std::string(boundary_generator_->GenerateBoundary())); |
| 222 | 222 |
| 223 // Estimate an upper bound for the total message size to make memory | 223 // Estimate an upper bound for the total message size to make memory |
| 224 // allocation more efficient. It is not an error if this turns out to be too | 224 // allocation more efficient. It is not an error if this turns out to be too |
| 225 // small as std::string will take care of the realloc. | 225 // small as std::string will take care of the realloc. |
| 226 size_t size = 0; | 226 size_t size = 0; |
| 227 for (const auto& data_segment : data_segments_) { | 227 for (auto* data_segment : data_segments_) { |
| 228 for (const auto& entry : data_segment->GetHeaderEntries()) | 228 for (const auto& entry : data_segment->GetHeaderEntries()) |
| 229 size += entry.first.size() + entry.second.size(); | 229 size += entry.first.size() + entry.second.size(); |
| 230 size += kMaxMimeBoundarySize + data_segment->GetName().size() + | 230 size += kMaxMimeBoundarySize + data_segment->GetName().size() + |
| 231 data_segment->GetFilename().size() + data_segment->GetDataSize(); | 231 data_segment->GetFilename().size() + data_segment->GetDataSize(); |
| 232 // Add some extra space for all the constants and control characters. | 232 // Add some extra space for all the constants and control characters. |
| 233 size += 128; | 233 size += 128; |
| 234 } | 234 } |
| 235 | 235 |
| 236 // Allocate memory of the expected size. | 236 // Allocate memory of the expected size. |
| 237 post_data_.reset(new std::string); | 237 post_data_.reset(new std::string); |
| 238 post_data_->reserve(size); | 238 post_data_->reserve(size); |
| 239 | 239 |
| 240 for (const auto& data_segment : data_segments_) { | 240 for (auto* data_segment : data_segments_) { |
| 241 post_data_->append("--" + *mime_boundary_.get() + "\r\n"); | 241 post_data_->append("--" + *mime_boundary_.get() + "\r\n"); |
| 242 post_data_->append("Content-Disposition: form-data; name=\"" + | 242 post_data_->append("Content-Disposition: form-data; name=\"" + |
| 243 data_segment->GetName() + "\""); | 243 data_segment->GetName() + "\""); |
| 244 if (!data_segment->GetFilename().empty()) { | 244 if (!data_segment->GetFilename().empty()) { |
| 245 post_data_->append("; filename=\"" + data_segment->GetFilename() + "\""); | 245 post_data_->append("; filename=\"" + data_segment->GetFilename() + "\""); |
| 246 } | 246 } |
| 247 post_data_->append("\r\n"); | 247 post_data_->append("\r\n"); |
| 248 | 248 |
| 249 // Add custom header fields. | 249 // Add custom header fields. |
| 250 for (const auto& entry : data_segment->GetHeaderEntries()) { | 250 for (const auto& entry : data_segment->GetHeaderEntries()) { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 HandleError(AUTHENTICATION_ERROR); | 379 HandleError(AUTHENTICATION_ERROR); |
| 380 } else { | 380 } else { |
| 381 CHROMEOS_SYSLOG(ERROR) << "POST request failed with HTTP status code " | 381 CHROMEOS_SYSLOG(ERROR) << "POST request failed with HTTP status code " |
| 382 << response_code << "."; | 382 << response_code << "."; |
| 383 HandleError(SERVER_ERROR); | 383 HandleError(SERVER_ERROR); |
| 384 } | 384 } |
| 385 } | 385 } |
| 386 } | 386 } |
| 387 | 387 |
| 388 } // namespace policy | 388 } // namespace policy |
| OLD | NEW |