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

Unified Diff: webkit/glue/webupload_data.h

Issue 10834289: Split net::UploadData into two: for IPC and for upload handling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 | « webkit/glue/webkit_glue.gypi ('k') | webkit/glue/webupload_data.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/glue/webupload_data.h
diff --git a/webkit/glue/webupload_data.h b/webkit/glue/webupload_data.h
new file mode 100644
index 0000000000000000000000000000000000000000..d5f3cd8fa94bf22ffaa015d9aac86e082e64fb8e
--- /dev/null
+++ b/webkit/glue/webupload_data.h
@@ -0,0 +1,160 @@
+// Copyright (c) 2012 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.
+
+#ifndef WEBKIT_GLUE_WEBUPLOAD_DATA_H_
+#define WEBKIT_GLUE_WEBUPLOAD_DATA_H_
+
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/file_path.h"
+#include "base/memory/ref_counted.h"
+#include "base/supports_user_data.h"
+#include "base/time.h"
+#include "googleurl/src/gurl.h"
+#include "webkit/glue/webkit_glue_export.h"
+
+namespace net {
+class UploadData;
+}
+
+// A struct used to represent upload data. The data field is populated by
+// WebURLLoader from the data given as WebHTTPBody.
+class WEBKIT_GLUE_EXPORT WebUploadData
kinuko 2012/08/13 15:52:09 Having this in webkit/glue is probably not ideal
darin (slow to review) 2012/08/13 16:48:49 Seems like it could live in content/public/common/
darin (slow to review) 2012/08/13 20:47:36 Also, it might be good to use a prefix of "Resourc
kinuko 2012/08/14 15:33:32 I think I like the latter idea (since it can kill
+ : public base::RefCounted<WebUploadData>,
+ public base::SupportsUserData {
+ public:
+ enum Type {
+ TYPE_BYTES,
+ TYPE_FILE,
+ TYPE_BLOB,
+ };
+
+ class WEBKIT_GLUE_EXPORT Element {
+ public:
+ Element();
+ ~Element();
+
+ Type type() const { return type_; }
+ // Explicitly sets the type of this Element. Used during IPC
+ // marshalling.
+ void set_type(Type type) {
+ type_ = type;
+ }
+
+ const std::vector<char>& bytes() const { return bytes_; }
+ const FilePath& file_path() const { return file_path_; }
+ uint64 file_range_offset() const { return file_range_offset_; }
+ uint64 file_range_length() const { return file_range_length_; }
+ // If NULL time is returned, we do not do the check.
+ const base::Time& expected_file_modification_time() const {
+ return expected_file_modification_time_;
+ }
+ const GURL& blob_url() const { return blob_url_; }
+
+ void SetToBytes(const char* bytes, int bytes_len) {
+ type_ = TYPE_BYTES;
+ bytes_.assign(bytes, bytes + bytes_len);
+ }
+
+ void SetToFilePath(const FilePath& path) {
+ SetToFilePathRange(path, 0, kuint64max, base::Time());
+ }
+
+ // If expected_modification_time is NULL, we do not check for the file
+ // change. Also note that the granularity for comparison is time_t, not
+ // the full precision.
+ void SetToFilePathRange(const FilePath& path,
+ uint64 offset, uint64 length,
+ const base::Time& expected_modification_time) {
+ type_ = TYPE_FILE;
+ file_path_ = path;
+ file_range_offset_ = offset;
+ file_range_length_ = length;
+ expected_file_modification_time_ = expected_modification_time;
+ }
+
+ void SetToBlobUrl(const GURL& blob_url) {
+ type_ = TYPE_BLOB;
+ blob_url_ = blob_url;
+ }
+
+ private:
+ Type type_;
+ std::vector<char> bytes_;
+ FilePath file_path_;
+ uint64 file_range_offset_;
+ uint64 file_range_length_;
+ base::Time expected_file_modification_time_;
+ GURL blob_url_;
+ };
+
+ WebUploadData();
+
+ void AppendBytes(const char* bytes, int bytes_len);
+ void AppendFileRange(const FilePath& file_path,
+ uint64 offset, uint64 length,
+ const base::Time& expected_modification_time);
+ void AppendBlob(const GURL& blob_url);
+
+ // Populate the given |net_upload_data| using the elements data.
+ // At this stage the elements should not contain any TYPE_BLOB items
+ // (i.e. must have resolved them by ResolveBlobReferencesInUploadData).
+ // TODO(kinuko): Clean up this hack.
+ void PopulateUploadData(net::UploadData* upload_data) const;
+
+ const std::vector<Element>* elements() const {
+ return &elements_;
+ }
+
+ std::vector<Element>* elements_mutable() {
+ return &elements_;
+ }
+
+ void swap_elements(std::vector<Element>* elements) {
+ elements_.swap(*elements);
+ }
+
+ // Identifies a particular upload instance, which is used by the cache to
+ // formulate a cache key. This value should be unique across browser
+ // sessions. A value of 0 is used to indicate an unspecified identifier.
+ void set_identifier(int64 id) { identifier_ = id; }
+ int64 identifier() const { return identifier_; }
+
+ private:
+ friend class base::RefCounted<WebUploadData>;
+ virtual ~WebUploadData();
+
+ std::vector<Element> elements_;
+ int64 identifier_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebUploadData);
+};
+
+#if defined(UNIT_TEST)
+inline bool operator==(const WebUploadData::Element& a,
+ const WebUploadData::Element& b) {
+ if (a.type() != b.type())
+ return false;
+ if (a.type() == WebUploadData::TYPE_BYTES)
+ return a.bytes() == b.bytes();
+ if (a.type() == WebUploadData::TYPE_FILE) {
+ return a.file_path() == b.file_path() &&
+ a.file_range_offset() == b.file_range_offset() &&
+ a.file_range_length() == b.file_range_length() &&
+ a.expected_file_modification_time() ==
+ b.expected_file_modification_time();
+ }
+ if (a.type() == WebUploadData::TYPE_BLOB)
+ return a.blob_url() == b.blob_url();
+ return false;
+}
+
+inline bool operator!=(const WebUploadData::Element& a,
+ const WebUploadData::Element& b) {
+ return !(a == b);
+}
+#endif // defined(UNIT_TEST)
+
+#endif // WEBKIT_GLUE_WEBUPLOAD_DATA_H_
« no previous file with comments | « webkit/glue/webkit_glue.gypi ('k') | webkit/glue/webupload_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698