Index: chrome/browser/chromeos/policy/upload_job_impl.cc |
diff --git a/chrome/browser/chromeos/policy/upload_job_impl.cc b/chrome/browser/chromeos/policy/upload_job_impl.cc |
index 22cbf4d2cf75b3b8b66dbd549c9aef8e5f03dba7..b4a10fb5c68890279c3244c43b6f94a98a2d805b 100644 |
--- a/chrome/browser/chromeos/policy/upload_job_impl.cc |
+++ b/chrome/browser/chromeos/policy/upload_job_impl.cc |
@@ -7,10 +7,10 @@ |
#include <set> |
#include "base/logging.h" |
-#include "base/rand_util.h" |
#include "base/strings/stringprintf.h" |
#include "google_apis/gaia/gaia_constants.h" |
#include "google_apis/gaia/google_service_auth_error.h" |
+#include "net/base/mime_util.h" |
#include "net/http/http_status_code.h" |
#include "net/url_request/url_request_status.h" |
@@ -18,41 +18,21 @@ namespace policy { |
namespace { |
-// Defines the characters that might appear in strings generated by |
-// GenerateRandomString(). |
-const char kAlphaNum[] = |
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; |
- |
// Format for bearer tokens in HTTP requests to access OAuth 2.0 protected |
// resources. |
const char kAuthorizationHeaderFormat[] = "Authorization: Bearer %s"; |
-// Prefix added to a randomly generated string when choosing the MIME boundary. |
-const char kMultipartBoundaryPrefix[] = "----**--"; |
- |
-// Postfix added to a randomly generated string when choosing the MIME boundary. |
-const char kMultipartBoundaryPostfix[] = "--**----"; |
- |
// Value the "Content-Type" field will be set to in the POST request. |
const char kUploadContentType[] = "multipart/form-data"; |
// Number of retries when randomly generating a MIME boundary. |
const int kMimeBoundaryRetries = 3; |
-// Length of the random string for the MIME boundary. |
-const int kMimeBoundarySize = 32; |
- |
// Number of upload retries. |
const int kMaxRetries = 1; |
-// Generates a random alphanumeric string of length |length|. |
-std::string GenerateRandomString(size_t length) { |
- std::string random; |
- random.reserve(length); |
- for (size_t i = 0; i < length; i++) |
- random.push_back(kAlphaNum[base::RandGenerator(sizeof(kAlphaNum) - 1)]); |
- return random; |
-} |
+// Max size of MIME boundary according to RFC 1341, section 7.2.1. |
+const size_t kMaxMimeBoundarySize = 70; |
} // namespace |
@@ -145,18 +125,9 @@ size_t DataSegment::GetDataSize() const { |
return data_->size(); |
} |
-std::string UploadJobImpl::RandomMimeBoundaryGenerator::GenerateBoundary( |
- size_t length) const { |
- std::string boundary; |
- boundary.reserve(length); |
- DCHECK_GT(length, sizeof(kMultipartBoundaryPrefix) + |
- sizeof(kMultipartBoundaryPostfix)); |
- const size_t random_part_length = length - sizeof(kMultipartBoundaryPrefix) - |
- sizeof(kMultipartBoundaryPostfix); |
- boundary.append(kMultipartBoundaryPrefix); |
- boundary.append(GenerateRandomString(random_part_length)); |
- boundary.append(kMultipartBoundaryPostfix); |
- return boundary; |
+std::string UploadJobImpl::RandomMimeBoundaryGenerator::GenerateBoundary() |
+ const { |
+ return net::GenerateMimeMultipartBoundary(); |
} |
UploadJobImpl::UploadJobImpl( |
@@ -241,8 +212,8 @@ bool UploadJobImpl::SetUpMultipart() { |
int retry = 0; |
do { |
found = true; |
- mime_boundary_.reset(new std::string( |
- boundary_generator_->GenerateBoundary(kMimeBoundarySize))); |
+ mime_boundary_.reset( |
+ new std::string(boundary_generator_->GenerateBoundary())); |
for (const auto& data_segment : data_segments_) { |
if (data_segment->CheckIfDataContains(*mime_boundary_)) { |
found = false; |
@@ -266,7 +237,7 @@ bool UploadJobImpl::SetUpMultipart() { |
for (const auto& data_segment : data_segments_) { |
for (const auto& entry : data_segment->GetHeaderEntries()) |
size += entry.first.size() + entry.second.size(); |
- size += kMimeBoundarySize + data_segment->GetName().size() + |
+ size += kMaxMimeBoundarySize + data_segment->GetName().size() + |
data_segment->GetFilename().size() + data_segment->GetDataSize(); |
// Add some extra space for all the constants and control characters. |
size += 128; |