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

Unified Diff: webkit/blob/blob_data.h

Issue 7974011: Break large blobs into multiple ipcs during creation. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 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: webkit/blob/blob_data.h
===================================================================
--- webkit/blob/blob_data.h (revision 103169)
+++ webkit/blob/blob_data.h (working copy)
@@ -28,69 +28,61 @@
TYPE_BLOB
};
- class Item {
- public:
+ struct Item {
Item();
~Item();
- Type type() const { return type_; }
- const std::string& data() const { return data_; }
- const FilePath& file_path() const { return file_path_; }
- const GURL& blob_url() const { return blob_url_; }
- uint64 offset() const { return offset_; }
- uint64 length() const { return length_; }
- const base::Time& expected_modification_time() const {
- return expected_modification_time_;
- }
-
void SetToData(const std::string& data) {
SetToData(data, 0, static_cast<uint32>(data.size()));
}
void SetToData(const std::string& data, uint32 offset, uint32 length) {
// TODO(jianli): Need to implement ref-counting vector storage.
- type_ = TYPE_DATA;
- data_ = data;
- offset_ = offset;
- length_ = length;
+ type = TYPE_DATA;
+ this->data = data;
+ this->offset = offset;
+ this->length = length;
}
+ void SetToData(const char* data, size_t length) {
+ type = TYPE_DATA;
+ this->data.assign(data, length);
+ this->offset = 0;
+ this->length = length;
+ }
+
void SetToFile(const FilePath& file_path, uint64 offset, uint64 length,
const base::Time& expected_modification_time) {
- type_ = TYPE_FILE;
- file_path_ = file_path;
- offset_ = offset;
- length_ = length;
- expected_modification_time_ = expected_modification_time;
+ type = TYPE_FILE;
+ this->file_path = file_path;
+ this->offset = offset;
+ this->length = length;
+ this->expected_modification_time = expected_modification_time;
}
void SetToBlob(const GURL& blob_url, uint64 offset, uint64 length) {
- type_ = TYPE_BLOB;
- blob_url_ = blob_url;
- offset_ = offset;
- length_ = length;
+ type = TYPE_BLOB;
+ this->blob_url = blob_url;
+ this->offset = offset;
+ this->length = length;
}
- private:
- Type type_;
-
- // For Data type.
- std::string data_;
-
- // For File type.
- FilePath file_path_;
-
- // For Blob typ.
- GURL blob_url_;
-
- uint64 offset_;
- uint64 length_;
- base::Time expected_modification_time_;
+ Type type;
+ std::string data; // For Data type.
+ GURL blob_url; // For Blob type.
+ FilePath file_path; // For File type.
+ base::Time expected_modification_time; // Also for File type.
+ uint64 offset;
+ uint64 length;
};
BlobData();
explicit BlobData(const WebKit::WebBlobData& data);
+ void AppendItem(const Item& item) {
+ items_.push_back(item);
+ }
+
void AppendData(const std::string& data) {
// TODO(jianli): Consider writing the big data to the disk.
AppendData(data, 0, static_cast<uint32>(data.size()));
@@ -133,9 +125,14 @@
content_disposition_ = content_disposition;
}
- // Should only be called by the IPC ParamTraits for this class.
- void swap_items(std::vector<Item>* items) {
- items_.swap(*items);
+ int64 GetMemoryUsage() const {
+ int64 memory = 0;
+ for (std::vector<Item>::const_iterator iter = items_.begin();
+ iter != items_.end(); ++iter) {
+ if (iter->type == TYPE_DATA)
+ memory += iter->data.size();
+ }
+ return memory;
}
private:
@@ -153,23 +150,23 @@
#if defined(UNIT_TEST)
inline bool operator==(const BlobData::Item& a, const BlobData::Item& b) {
- if (a.type() != b.type())
+ if (a.type != b.type)
return false;
- if (a.type() == BlobData::TYPE_DATA) {
- return a.data() == b.data() &&
- a.offset() == b.offset() &&
- a.length() == b.length();
+ if (a.type == BlobData::TYPE_DATA) {
+ return a.data == b.data &&
+ a.offset == b.offset &&
+ a.length == b.length;
}
- if (a.type() == BlobData::TYPE_FILE) {
- return a.file_path() == b.file_path() &&
- a.offset() == b.offset() &&
- a.length() == b.length() &&
- a.expected_modification_time() == b.expected_modification_time();
+ if (a.type == BlobData::TYPE_FILE) {
+ return a.file_path == b.file_path &&
+ a.offset == b.offset &&
+ a.length == b.length &&
+ a.expected_modification_time == b.expected_modification_time;
}
- if (a.type() == BlobData::TYPE_BLOB) {
- return a.blob_url() == b.blob_url() &&
- a.offset() == b.offset() &&
- a.length() == b.length();
+ if (a.type == BlobData::TYPE_BLOB) {
+ return a.blob_url == b.blob_url &&
+ a.offset == b.offset &&
+ a.length == b.length;
}
return false;
}

Powered by Google App Engine
This is Rietveld 408576698