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

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: Self-review. Created 5 years 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 18846cba9a5789be48af6e336b09d53a10210d05..fb7a85a68cd284b70b20d8b96bd91404ba3bf936 100644
--- a/google_apis/drive/base_requests.cc
+++ b/google_apis/drive/base_requests.cc
@@ -8,7 +8,6 @@
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/location.h"
-#include "base/rand_util.h"
#include "base/sequenced_task_runner.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
@@ -23,6 +22,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"
@@ -72,13 +72,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.
@@ -223,13 +216,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();
Ryan Sleevi 2015/12/28 23:30:00 Ditto as to whether needed?
Łukasz Anforowicz 2015/12/29 18:53:19 Done.
bool conflict_with_content = false;
for (auto& part : parts) {
if (part.data.find(boundary, 0) != std::string::npos) {

Powered by Google App Engine
This is Rietveld 408576698