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

Side by Side 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, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef WEBKIT_BLOB_BLOB_DATA_H_ 5 #ifndef WEBKIT_BLOB_BLOB_DATA_H_
6 #define WEBKIT_BLOB_BLOB_DATA_H_ 6 #define WEBKIT_BLOB_BLOB_DATA_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 10 matching lines...) Expand all
21 namespace webkit_blob { 21 namespace webkit_blob {
22 22
23 class BlobData : public base::RefCounted<BlobData> { 23 class BlobData : public base::RefCounted<BlobData> {
24 public: 24 public:
25 enum Type { 25 enum Type {
26 TYPE_DATA, 26 TYPE_DATA,
27 TYPE_FILE, 27 TYPE_FILE,
28 TYPE_BLOB 28 TYPE_BLOB
29 }; 29 };
30 30
31 class Item { 31 struct Item {
32 public:
33 Item(); 32 Item();
34 ~Item(); 33 ~Item();
35 34
36 Type type() const { return type_; }
37 const std::string& data() const { return data_; }
38 const FilePath& file_path() const { return file_path_; }
39 const GURL& blob_url() const { return blob_url_; }
40 uint64 offset() const { return offset_; }
41 uint64 length() const { return length_; }
42 const base::Time& expected_modification_time() const {
43 return expected_modification_time_;
44 }
45
46 void SetToData(const std::string& data) { 35 void SetToData(const std::string& data) {
47 SetToData(data, 0, static_cast<uint32>(data.size())); 36 SetToData(data, 0, static_cast<uint32>(data.size()));
48 } 37 }
49 38
50 void SetToData(const std::string& data, uint32 offset, uint32 length) { 39 void SetToData(const std::string& data, uint32 offset, uint32 length) {
51 // TODO(jianli): Need to implement ref-counting vector storage. 40 // TODO(jianli): Need to implement ref-counting vector storage.
52 type_ = TYPE_DATA; 41 type = TYPE_DATA;
53 data_ = data; 42 this->data = data;
54 offset_ = offset; 43 this->offset = offset;
55 length_ = length; 44 this->length = length;
45 }
46
47 void SetToData(const char* data, size_t length) {
48 type = TYPE_DATA;
49 this->data.assign(data, length);
50 this->offset = 0;
51 this->length = length;
56 } 52 }
57 53
58 void SetToFile(const FilePath& file_path, uint64 offset, uint64 length, 54 void SetToFile(const FilePath& file_path, uint64 offset, uint64 length,
59 const base::Time& expected_modification_time) { 55 const base::Time& expected_modification_time) {
60 type_ = TYPE_FILE; 56 type = TYPE_FILE;
61 file_path_ = file_path; 57 this->file_path = file_path;
62 offset_ = offset; 58 this->offset = offset;
63 length_ = length; 59 this->length = length;
64 expected_modification_time_ = expected_modification_time; 60 this->expected_modification_time = expected_modification_time;
65 } 61 }
66 62
67 void SetToBlob(const GURL& blob_url, uint64 offset, uint64 length) { 63 void SetToBlob(const GURL& blob_url, uint64 offset, uint64 length) {
68 type_ = TYPE_BLOB; 64 type = TYPE_BLOB;
69 blob_url_ = blob_url; 65 this->blob_url = blob_url;
70 offset_ = offset; 66 this->offset = offset;
71 length_ = length; 67 this->length = length;
72 } 68 }
73 69
74 private: 70 Type type;
75 Type type_; 71 std::string data; // For Data type.
76 72 GURL blob_url; // For Blob type.
77 // For Data type. 73 FilePath file_path; // For File type.
78 std::string data_; 74 base::Time expected_modification_time; // Also for File type.
79 75 uint64 offset;
80 // For File type. 76 uint64 length;
81 FilePath file_path_;
82
83 // For Blob typ.
84 GURL blob_url_;
85
86 uint64 offset_;
87 uint64 length_;
88 base::Time expected_modification_time_;
89 }; 77 };
90 78
91 BlobData(); 79 BlobData();
92 explicit BlobData(const WebKit::WebBlobData& data); 80 explicit BlobData(const WebKit::WebBlobData& data);
93 81
82 void AppendItem(const Item& item) {
83 items_.push_back(item);
84 }
85
94 void AppendData(const std::string& data) { 86 void AppendData(const std::string& data) {
95 // TODO(jianli): Consider writing the big data to the disk. 87 // TODO(jianli): Consider writing the big data to the disk.
96 AppendData(data, 0, static_cast<uint32>(data.size())); 88 AppendData(data, 0, static_cast<uint32>(data.size()));
97 } 89 }
98 90
99 void AppendData(const std::string& data, uint32 offset, uint32 length) { 91 void AppendData(const std::string& data, uint32 offset, uint32 length) {
100 if (length > 0) { 92 if (length > 0) {
101 items_.push_back(Item()); 93 items_.push_back(Item());
102 items_.back().SetToData(data, offset, length); 94 items_.back().SetToData(data, offset, length);
103 } 95 }
(...skipping 22 matching lines...) Expand all
126 content_type_ = content_type; 118 content_type_ = content_type;
127 } 119 }
128 120
129 const std::string& content_disposition() const { 121 const std::string& content_disposition() const {
130 return content_disposition_; 122 return content_disposition_;
131 } 123 }
132 void set_content_disposition(const std::string& content_disposition) { 124 void set_content_disposition(const std::string& content_disposition) {
133 content_disposition_ = content_disposition; 125 content_disposition_ = content_disposition;
134 } 126 }
135 127
136 // Should only be called by the IPC ParamTraits for this class. 128 int64 GetMemoryUsage() const {
137 void swap_items(std::vector<Item>* items) { 129 int64 memory = 0;
138 items_.swap(*items); 130 for (std::vector<Item>::const_iterator iter = items_.begin();
131 iter != items_.end(); ++iter) {
132 if (iter->type == TYPE_DATA)
133 memory += iter->data.size();
134 }
135 return memory;
139 } 136 }
140 137
141 private: 138 private:
142 friend class base::RefCounted<BlobData>; 139 friend class base::RefCounted<BlobData>;
143 140
144 virtual ~BlobData(); 141 virtual ~BlobData();
145 142
146 std::string content_type_; 143 std::string content_type_;
147 std::string content_disposition_; 144 std::string content_disposition_;
148 std::vector<Item> items_; 145 std::vector<Item> items_;
149 std::vector<scoped_refptr<DeletableFileReference> > deletable_files_; 146 std::vector<scoped_refptr<DeletableFileReference> > deletable_files_;
150 147
151 DISALLOW_COPY_AND_ASSIGN(BlobData); 148 DISALLOW_COPY_AND_ASSIGN(BlobData);
152 }; 149 };
153 150
154 #if defined(UNIT_TEST) 151 #if defined(UNIT_TEST)
155 inline bool operator==(const BlobData::Item& a, const BlobData::Item& b) { 152 inline bool operator==(const BlobData::Item& a, const BlobData::Item& b) {
156 if (a.type() != b.type()) 153 if (a.type != b.type)
157 return false; 154 return false;
158 if (a.type() == BlobData::TYPE_DATA) { 155 if (a.type == BlobData::TYPE_DATA) {
159 return a.data() == b.data() && 156 return a.data == b.data &&
160 a.offset() == b.offset() && 157 a.offset == b.offset &&
161 a.length() == b.length(); 158 a.length == b.length;
162 } 159 }
163 if (a.type() == BlobData::TYPE_FILE) { 160 if (a.type == BlobData::TYPE_FILE) {
164 return a.file_path() == b.file_path() && 161 return a.file_path == b.file_path &&
165 a.offset() == b.offset() && 162 a.offset == b.offset &&
166 a.length() == b.length() && 163 a.length == b.length &&
167 a.expected_modification_time() == b.expected_modification_time(); 164 a.expected_modification_time == b.expected_modification_time;
168 } 165 }
169 if (a.type() == BlobData::TYPE_BLOB) { 166 if (a.type == BlobData::TYPE_BLOB) {
170 return a.blob_url() == b.blob_url() && 167 return a.blob_url == b.blob_url &&
171 a.offset() == b.offset() && 168 a.offset == b.offset &&
172 a.length() == b.length(); 169 a.length == b.length;
173 } 170 }
174 return false; 171 return false;
175 } 172 }
176 173
177 inline bool operator!=(const BlobData::Item& a, const BlobData::Item& b) { 174 inline bool operator!=(const BlobData::Item& a, const BlobData::Item& b) {
178 return !(a == b); 175 return !(a == b);
179 } 176 }
180 177
181 inline bool operator==(const BlobData& a, const BlobData& b) { 178 inline bool operator==(const BlobData& a, const BlobData& b) {
182 if (a.content_type() != b.content_type()) 179 if (a.content_type() != b.content_type())
(...skipping 10 matching lines...) Expand all
193 } 190 }
194 191
195 inline bool operator!=(const BlobData& a, const BlobData& b) { 192 inline bool operator!=(const BlobData& a, const BlobData& b) {
196 return !(a == b); 193 return !(a == b);
197 } 194 }
198 #endif // defined(UNIT_TEST) 195 #endif // defined(UNIT_TEST)
199 196
200 } // namespace webkit_blob 197 } // namespace webkit_blob
201 198
202 #endif // WEBKIT_BLOB_BLOB_DATA_H_ 199 #endif // WEBKIT_BLOB_BLOB_DATA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698