Chromium Code Reviews| 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) { |
| + void SetToData(const std::string& data_str, uint32 off, uint32 len) { |
| // TODO(jianli): Need to implement ref-counting vector storage. |
| - type_ = TYPE_DATA; |
| - data_ = data; |
| - offset_ = offset; |
| - length_ = length; |
| + type = TYPE_DATA; |
| + data = data_str; |
|
jianli
2011/09/29 01:13:33
Nit: probably no need to rename parameter from dat
michaeln
2011/09/29 18:59:37
Done (duh... thnx)
|
| + offset = off; |
| + length = len; |
| } |
| - 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; |
| + void SetToData(const char* data_ptr, size_t len) { |
| + type = TYPE_DATA; |
| + data.assign(data_ptr, len); |
| + offset = 0; |
| + length = len; |
| } |
| - void SetToBlob(const GURL& blob_url, uint64 offset, uint64 length) { |
| - type_ = TYPE_BLOB; |
| - blob_url_ = blob_url; |
| - offset_ = offset; |
| - length_ = length; |
| + void SetToFile(const FilePath& path, uint64 off, uint64 len, |
| + const base::Time& expected_mtime) { |
| + type = TYPE_FILE; |
| + file_path = path; |
| + offset = off; |
| + length = len; |
| + expected_modification_time = expected_mtime; |
| } |
| - private: |
| - Type type_; |
| + void SetToBlob(const GURL& url, uint64 off, uint64 len) { |
| + type = TYPE_BLOB; |
| + blob_url = url; |
| + offset = off; |
| + length = len; |
| + } |
| - // 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; |
| } |