Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Unified Diff: google_apis/drive/base_requests.cc

Issue 1547593002: Introducing a net::GenerateMimeMultipartBoundary helper. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing... Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: google_apis/drive/base_requests.cc
diff --git a/google_apis/drive/base_requests.cc b/google_apis/drive/base_requests.cc
index 3e5b0d1d4c75754b0ddc52eeed4fb6cd51e0aa94..359339ad8853d5b24aac35d6e7eb7802917344c8 100644
--- a/google_apis/drive/base_requests.cc
+++ b/google_apis/drive/base_requests.cc
@@ -27,6 +27,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 +77,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.
@@ -226,24 +220,7 @@ void GenerateMultipartBody(MultipartType multipart_type,
std::string boundary;
// 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)];
- }
- bool conflict_with_content = false;
hashimoto 2016/01/05 07:16:09 The new implementation generates much less variety
Łukasz Anforowicz 2016/01/05 19:16:49 The new implementation is generating 256^30 string
hashimoto 2016/01/07 05:15:48 lgtm
Łukasz Anforowicz 2016/01/07 19:04:13 Thank you very much for pointing this out. This d
- for (auto& part : parts) {
- if (part.data.find(boundary, 0) != std::string::npos) {
- conflict_with_content = true;
- break;
- }
- }
- if (!conflict_with_content)
- break;
- }
+ boundary = net::GenerateMimeMultipartBoundary();
} else {
boundary = predetermined_boundary;
}

Powered by Google App Engine
This is Rietveld 408576698