| OLD | NEW |
| 1 // Copyright (c) 2012 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" |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 uint64 length; | 78 uint64 length; |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 BlobData(); | 81 BlobData(); |
| 82 explicit BlobData(const WebKit::WebBlobData& data); | 82 explicit BlobData(const WebKit::WebBlobData& data); |
| 83 | 83 |
| 84 void AppendData(const std::string& data) { | 84 void AppendData(const std::string& data) { |
| 85 AppendData(data.c_str(), data.size()); | 85 AppendData(data.c_str(), data.size()); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void AppendData(const char* data, size_t length); | 88 void AppendData(const char* data, size_t length) { |
| 89 if (length > 0) { |
| 90 items_.push_back(Item()); |
| 91 items_.back().SetToData(data, length); |
| 92 } |
| 93 } |
| 89 | 94 |
| 90 void AppendFile(const FilePath& file_path, uint64 offset, uint64 length, | 95 void AppendFile(const FilePath& file_path, uint64 offset, uint64 length, |
| 91 const base::Time& expected_modification_time); | 96 const base::Time& expected_modification_time) { |
| 97 items_.push_back(Item()); |
| 98 items_.back().SetToFile(file_path, offset, length, |
| 99 expected_modification_time); |
| 100 } |
| 92 | 101 |
| 93 void AppendBlob(const GURL& blob_url, uint64 offset, uint64 length); | 102 void AppendBlob(const GURL& blob_url, uint64 offset, uint64 length) { |
| 103 items_.push_back(Item()); |
| 104 items_.back().SetToBlob(blob_url, offset, length); |
| 105 } |
| 94 | 106 |
| 95 void AttachShareableFileReference(ShareableFileReference* reference) { | 107 void AttachShareableFileReference(ShareableFileReference* reference) { |
| 96 shareable_files_.push_back(reference); | 108 shareable_files_.push_back(reference); |
| 97 } | 109 } |
| 98 | 110 |
| 99 const std::vector<Item>& items() const { return items_; } | 111 const std::vector<Item>& items() const { return items_; } |
| 100 | 112 |
| 101 const std::string& content_type() const { return content_type_; } | 113 const std::string& content_type() const { return content_type_; } |
| 102 void set_content_type(const std::string& content_type) { | 114 void set_content_type(const std::string& content_type) { |
| 103 content_type_ = content_type; | 115 content_type_ = content_type; |
| 104 } | 116 } |
| 105 | 117 |
| 106 const std::string& content_disposition() const { | 118 const std::string& content_disposition() const { |
| 107 return content_disposition_; | 119 return content_disposition_; |
| 108 } | 120 } |
| 109 void set_content_disposition(const std::string& content_disposition) { | 121 void set_content_disposition(const std::string& content_disposition) { |
| 110 content_disposition_ = content_disposition; | 122 content_disposition_ = content_disposition; |
| 111 } | 123 } |
| 112 | 124 |
| 113 int64 GetMemoryUsage() const; | 125 int64 GetMemoryUsage() const { |
| 126 int64 memory = 0; |
| 127 for (std::vector<Item>::const_iterator iter = items_.begin(); |
| 128 iter != items_.end(); ++iter) { |
| 129 if (iter->type == TYPE_DATA) |
| 130 memory += iter->data.size(); |
| 131 } |
| 132 return memory; |
| 133 } |
| 114 | 134 |
| 115 private: | 135 private: |
| 116 friend class base::RefCounted<BlobData>; | 136 friend class base::RefCounted<BlobData>; |
| 117 | 137 |
| 118 virtual ~BlobData(); | 138 virtual ~BlobData(); |
| 119 | 139 |
| 120 std::string content_type_; | 140 std::string content_type_; |
| 121 std::string content_disposition_; | 141 std::string content_disposition_; |
| 122 std::vector<Item> items_; | 142 std::vector<Item> items_; |
| 123 std::vector<scoped_refptr<ShareableFileReference> > shareable_files_; | 143 std::vector<scoped_refptr<ShareableFileReference> > shareable_files_; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 } | 187 } |
| 168 | 188 |
| 169 inline bool operator!=(const BlobData& a, const BlobData& b) { | 189 inline bool operator!=(const BlobData& a, const BlobData& b) { |
| 170 return !(a == b); | 190 return !(a == b); |
| 171 } | 191 } |
| 172 #endif // defined(UNIT_TEST) | 192 #endif // defined(UNIT_TEST) |
| 173 | 193 |
| 174 } // namespace webkit_blob | 194 } // namespace webkit_blob |
| 175 | 195 |
| 176 #endif // WEBKIT_BLOB_BLOB_DATA_H_ | 196 #endif // WEBKIT_BLOB_BLOB_DATA_H_ |
| OLD | NEW |