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

Unified Diff: webkit/glue/resource_request_body.h

Issue 10827414: Factor out common Element struct from BlobData and ResourceRequestBody (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: webkit/common -> webkit/base 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/blob/webkit_blob.gypi ('k') | webkit/glue/resource_request_body.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/glue/resource_request_body.h
diff --git a/webkit/glue/resource_request_body.h b/webkit/glue/resource_request_body.h
index cddd496953a0b2a5bc7e02c803628c1c5b2137ce..ad98889bcaf7c44af5f6499d07a38efdea5237f5 100644
--- a/webkit/glue/resource_request_body.h
+++ b/webkit/glue/resource_request_body.h
@@ -8,11 +8,9 @@
#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/base/data_element.h"
#include "webkit/glue/webkit_glue_export.h"
namespace net {
@@ -28,90 +26,11 @@ namespace webkit_glue {
// A struct used to represent upload data. The data field is populated by
// WebURLLoader from the data given as WebHTTPBody.
-// TODO(kinuko): This is basically a duplicate of net::UploadData but
-// with support for higher-level abstraction data. We should reduce the
-// code duplicate by sharing code for similar data structs:
-// ResourceRequestBody::Element and BlobData::Item.
class WEBKIT_GLUE_EXPORT ResourceRequestBody
: public base::RefCounted<ResourceRequestBody>,
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 char* bytes() const { return bytes_start_ ? bytes_start_ : &buf_[0]; }
- uint64 bytes_length() const { return buf_.size() + bytes_length_; }
- 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;
- buf_.assign(bytes, bytes + bytes_len);
- }
-
- // This does not copy the given data and the caller should make sure
- // the data is secured somewhere else (e.g. by attaching the data
- // using SetUserData).
- void SetToSharedBytes(const char* bytes, int bytes_len) {
- type_ = TYPE_BYTES;
- bytes_start_ = bytes;
- bytes_length_ = 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> buf_;
- const char* bytes_start_;
- uint64 bytes_length_;
- FilePath file_path_;
- uint64 file_range_offset_;
- uint64 file_range_length_;
- base::Time expected_file_modification_time_;
- GURL blob_url_;
- };
+ typedef webkit_base::DataElement Element;
ResourceRequestBody();
@@ -127,14 +46,8 @@ class WEBKIT_GLUE_EXPORT ResourceRequestBody
net::UploadData* ResolveElementsAndCreateUploadData(
webkit_blob::BlobStorageController* blob_controller);
- const std::vector<Element>* elements() const {
- return &elements_;
- }
-
- std::vector<Element>* elements_mutable() {
- return &elements_;
- }
-
+ 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);
}
@@ -161,32 +74,6 @@ class WEBKIT_GLUE_EXPORT ResourceRequestBody
DISALLOW_COPY_AND_ASSIGN(ResourceRequestBody);
};
-#if defined(UNIT_TEST)
-inline bool operator==(const ResourceRequestBody::Element& a,
- const ResourceRequestBody::Element& b) {
- if (a.type() != b.type())
- return false;
- if (a.type() == ResourceRequestBody::TYPE_BYTES)
- return a.bytes_length() == b.bytes_length() &&
- memcmp(a.bytes(), b.bytes(), b.bytes_length()) == 0;
- if (a.type() == ResourceRequestBody::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() == ResourceRequestBody::TYPE_BLOB)
- return a.blob_url() == b.blob_url();
- return false;
-}
-
-inline bool operator!=(const ResourceRequestBody::Element& a,
- const ResourceRequestBody::Element& b) {
- return !(a == b);
-}
-#endif // defined(UNIT_TEST)
-
} // namespace webkit_glue
#endif // WEBKIT_GLUE_RESOURCE_REQUEST_BODY_H_
« no previous file with comments | « webkit/blob/webkit_blob.gypi ('k') | webkit/glue/resource_request_body.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698