summaryrefslogtreecommitdiffstats
path: root/google_apis
diff options
context:
space:
mode:
authorlukasza <lukasza@chromium.org>2016-01-08 11:35:04 -0800
committerCommit bot <commit-bot@chromium.org>2016-01-08 19:36:02 +0000
commitc644f37125ab27311d697af61e56c64d0e29027e (patch)
treef9f73168acee7cfe259bcaaf5425deeab99071f8 /google_apis
parent5efcee9378877176a9ccf173e3bcfa4a902b55d9 (diff)
downloadchromium_src-c644f37125ab27311d697af61e56c64d0e29027e.zip
chromium_src-c644f37125ab27311d697af61e56c64d0e29027e.tar.gz
chromium_src-c644f37125ab27311d697af61e56c64d0e29027e.tar.bz2
Introducing a net::GenerateMimeMultipartBoundary helper.
... and using the helper in places that had introduced separate functions for generating a random Mime boundary (sometimes with bugs - i.e. using '*' characters is disallowed by RFC 1341). TBR=bartfab@chromium.org, stevet@chromium.org BUG=575733 Review URL: https://codereview.chromium.org/1547593002 Cr-Commit-Position: refs/heads/master@{#368404}
Diffstat (limited to 'google_apis')
-rw-r--r--google_apis/drive/base_requests.cc17
-rw-r--r--google_apis/drive/drive_api_requests_unittest.cc2
2 files changed, 3 insertions, 16 deletions
diff --git a/google_apis/drive/base_requests.cc b/google_apis/drive/base_requests.cc
index 3e5b0d1..8a4e38b 100644
--- a/google_apis/drive/base_requests.cc
+++ b/google_apis/drive/base_requests.cc
@@ -12,7 +12,6 @@
#include "base/json/json_writer.h"
#include "base/location.h"
#include "base/macros.h"
-#include "base/rand_util.h"
#include "base/sequenced_task_runner.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
@@ -27,6 +26,7 @@
#include "net/base/elements_upload_data_stream.h"
#include "net/base/io_buffer.h"
#include "net/base/load_flags.h"
+#include "net/base/mime_util.h"
#include "net/base/net_errors.h"
#include "net/base/upload_bytes_element_reader.h"
#include "net/base/upload_data_stream.h"
@@ -76,13 +76,6 @@ const char kMultipartItemHeaderFormat[] = "--%s\nContent-Type: %s\n\n";
// Footer for whole multipart message.
const char kMultipartFooterFormat[] = "--%s--";
-// Characters to be used for multipart/related boundary.
-const char kBoundaryCharacters[] =
- "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
-
-// Size of multipart/related's boundary.
-const char kBoundarySize = 70;
-
// Parses JSON passed in |json| on |blocking_task_runner|. Runs |callback| on
// the calling thread when finished with either success or failure.
// The callback must not be null.
@@ -227,13 +220,7 @@ void GenerateMultipartBody(MultipartType multipart_type,
// Generate random boundary.
if (predetermined_boundary.empty()) {
while (true) {
- boundary.resize(kBoundarySize);
- for (int i = 0; i < kBoundarySize; ++i) {
- // Subtract 2 from the array size to exclude '\0', and to turn the size
- // into the last index.
- const int last_char_index = arraysize(kBoundaryCharacters) - 2;
- boundary[i] = kBoundaryCharacters[base::RandInt(0, last_char_index)];
- }
+ boundary = net::GenerateMimeMultipartBoundary();
bool conflict_with_content = false;
for (auto& part : parts) {
if (part.data.find(boundary, 0) != std::string::npos) {
diff --git a/google_apis/drive/drive_api_requests_unittest.cc b/google_apis/drive/drive_api_requests_unittest.cc
index 0912d61..3200339 100644
--- a/google_apis/drive/drive_api_requests_unittest.cc
+++ b/google_apis/drive/drive_api_requests_unittest.cc
@@ -2141,7 +2141,7 @@ TEST_F(DriveApiRequestsTest, BatchUploadRequestProgress) {
new TestBatchableDelegate(GURL("http://example.com/test"),
"application/binary", std::string(0, 'c'),
base::Bind(&EmptyClosure))};
- const size_t kExpectedUploadDataPosition[] = {208, 517, 776};
+ const size_t kExpectedUploadDataPosition[] = {207, 515, 773};
const size_t kExpectedUploadDataSize = 851;
request->AddRequest(requests[0]);
request->AddRequest(requests[1]);