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

Unified Diff: content/renderer/http_body_conversions.cc

Issue 1987053002: Deduplicating code performing WebHTTPBody::Element conversions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/data/test_body/g Created 4 years, 7 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
« no previous file with comments | « content/renderer/http_body_conversions.h ('k') | content/renderer/render_frame_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/http_body_conversions.cc
diff --git a/content/renderer/http_body_conversions.cc b/content/renderer/http_body_conversions.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3089ce5ee41ad9cda3a557fda45e54d211110fec
--- /dev/null
+++ b/content/renderer/http_body_conversions.cc
@@ -0,0 +1,84 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/renderer/http_body_conversions.h"
+
+#include <stddef.h>
+
+#include "base/files/file_path.h"
+#include "base/strings/nullable_string16.h"
+#include "base/time/time.h"
+#include "third_party/WebKit/public/platform/WebData.h"
+#include "third_party/WebKit/public/platform/WebHTTPBody.h"
+#include "third_party/WebKit/public/platform/WebString.h"
+
+using blink::WebData;
+using blink::WebHTTPBody;
+using blink::WebString;
+
+namespace content {
+
+void ConvertToHttpBodyElement(const WebHTTPBody::Element& input,
+ ResourceRequestBody::Element* output) {
+ switch (input.type) {
+ case WebHTTPBody::Element::TypeData:
+ output->SetToBytes(input.data.data(), input.data.size());
+ break;
+ case WebHTTPBody::Element::TypeFile:
+ output->SetToFilePathRange(
+ base::FilePath::FromUTF8Unsafe(input.filePath.utf8()),
+ static_cast<uint64_t>(input.fileStart),
+ static_cast<uint64_t>(input.fileLength),
+ base::Time::FromDoubleT(input.modificationTime));
+ break;
+ case WebHTTPBody::Element::TypeFileSystemURL:
+ output->SetToFileSystemUrlRange(
+ input.fileSystemURL, static_cast<uint64_t>(input.fileStart),
+ static_cast<uint64_t>(input.fileLength),
+ base::Time::FromDoubleT(input.modificationTime));
+ break;
+ case WebHTTPBody::Element::TypeBlob:
+ output->SetToBlob(input.blobUUID.utf8());
+ break;
+ default:
+ output->SetToEmptyBytes();
+ NOTREACHED();
+ break;
+ }
+}
+
+void AppendHttpBodyElement(const ResourceRequestBody::Element& element,
+ WebHTTPBody* http_body) {
+ switch (element.type()) {
+ case storage::DataElement::TYPE_BYTES:
+ http_body->appendData(WebData(element.bytes(), element.length()));
+ break;
+ case storage::DataElement::TYPE_FILE:
+ http_body->appendFileRange(
+ element.path().AsUTF16Unsafe(), element.offset(),
+ (element.length() != std::numeric_limits<uint64_t>::max())
+ ? element.length()
+ : -1,
+ element.expected_modification_time().ToDoubleT());
+ break;
+ case storage::DataElement::TYPE_FILE_FILESYSTEM:
+ http_body->appendFileSystemURLRange(
+ element.filesystem_url(), element.offset(),
+ (element.length() != std::numeric_limits<uint64_t>::max())
+ ? element.length()
+ : -1,
+ element.expected_modification_time().ToDoubleT());
+ break;
+ case storage::DataElement::TYPE_BLOB:
+ http_body->appendBlob(WebString::fromUTF8(element.blob_uuid()));
+ break;
+ case storage::DataElement::TYPE_BYTES_DESCRIPTION:
+ case storage::DataElement::TYPE_DISK_CACHE_ENTRY:
+ default:
+ NOTREACHED();
+ break;
+ }
+}
+
+} // namespace content
« no previous file with comments | « content/renderer/http_body_conversions.h ('k') | content/renderer/render_frame_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698