| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 expected_modification_time_ = expected_modification_time; | 66 expected_modification_time_ = expected_modification_time; |
| 67 } | 67 } |
| 68 | 68 |
| 69 void SetToBlob(const GURL& blob_url, uint64 offset, uint64 length) { | 69 void SetToBlob(const GURL& blob_url, uint64 offset, uint64 length) { |
| 70 type_ = TYPE_BLOB; | 70 type_ = TYPE_BLOB; |
| 71 blob_url_ = blob_url; | 71 blob_url_ = blob_url; |
| 72 offset_ = offset; | 72 offset_ = offset; |
| 73 length_ = length; | 73 length_ = length; |
| 74 } | 74 } |
| 75 | 75 |
| 76 #if defined(UNIT_TEST) | |
| 77 bool operator==(const Item& other) const { | |
| 78 if (type_ != other.type_) | |
| 79 return false; | |
| 80 if (type_ == TYPE_DATA) { | |
| 81 return data_ == other.data_ && | |
| 82 offset_ == other.offset_ && | |
| 83 length_ == other.length_; | |
| 84 } | |
| 85 if (type_ == TYPE_FILE) { | |
| 86 return file_path_ == other.file_path_ && | |
| 87 offset_ == other.offset_ && | |
| 88 length_ == other.length_ && | |
| 89 expected_modification_time_ == other.expected_modification_time_; | |
| 90 } | |
| 91 if (type_ == TYPE_BLOB) { | |
| 92 return blob_url_ == other.blob_url_ && | |
| 93 offset_ == other.offset_ && | |
| 94 length_ == other.length_; | |
| 95 } | |
| 96 return false; | |
| 97 } | |
| 98 | |
| 99 bool operator!=(const Item& other) const { | |
| 100 return !(*this == other); | |
| 101 } | |
| 102 #endif // defined(UNIT_TEST) | |
| 103 | |
| 104 private: | 76 private: |
| 105 Type type_; | 77 Type type_; |
| 106 | 78 |
| 107 // For Data type. | 79 // For Data type. |
| 108 std::string data_; | 80 std::string data_; |
| 109 | 81 |
| 110 // For File type. | 82 // For File type. |
| 111 FilePath file_path_; | 83 FilePath file_path_; |
| 112 | 84 |
| 113 // For Blob typ. | 85 // For Blob typ. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 content_type_ = content_type; | 130 content_type_ = content_type; |
| 159 } | 131 } |
| 160 | 132 |
| 161 const std::string& content_disposition() const { | 133 const std::string& content_disposition() const { |
| 162 return content_disposition_; | 134 return content_disposition_; |
| 163 } | 135 } |
| 164 void set_content_disposition(const std::string& content_disposition) { | 136 void set_content_disposition(const std::string& content_disposition) { |
| 165 content_disposition_ = content_disposition; | 137 content_disposition_ = content_disposition; |
| 166 } | 138 } |
| 167 | 139 |
| 168 #if defined(UNIT_TEST) | |
| 169 bool operator==(const BlobData& other) const { | |
| 170 if (content_type_ != other.content_type_) | |
| 171 return false; | |
| 172 if (content_disposition_ != other.content_disposition_) | |
| 173 return false; | |
| 174 if (items_.size() != other.items_.size()) | |
| 175 return false; | |
| 176 for (size_t i = 0; i < items_.size(); ++i) { | |
| 177 if (items_[i] != other.items_[i]) | |
| 178 return false; | |
| 179 } | |
| 180 return true; | |
| 181 } | |
| 182 #endif // defined(UNIT_TEST) | |
| 183 | |
| 184 private: | 140 private: |
| 185 friend class base::RefCounted<BlobData>; | 141 friend class base::RefCounted<BlobData>; |
| 186 | 142 |
| 187 virtual ~BlobData() { } | 143 virtual ~BlobData() { } |
| 188 | 144 |
| 189 std::string content_type_; | 145 std::string content_type_; |
| 190 std::string content_disposition_; | 146 std::string content_disposition_; |
| 191 std::vector<Item> items_; | 147 std::vector<Item> items_; |
| 192 }; | 148 }; |
| 193 | 149 |
| 150 #if defined(UNIT_TEST) |
| 151 inline bool operator==(const BlobData::Item& a, const BlobData::Item& b) { |
| 152 if (a.type() != b.type()) |
| 153 return false; |
| 154 if (a.type() == BlobData::TYPE_DATA) { |
| 155 return a.data() == b.data() && |
| 156 a.offset() == b.offset() && |
| 157 a.length() == b.length(); |
| 158 } |
| 159 if (a.type() == BlobData::TYPE_FILE) { |
| 160 return a.file_path() == b.file_path() && |
| 161 a.offset() == b.offset() && |
| 162 a.length() == b.length() && |
| 163 a.expected_modification_time() == b.expected_modification_time(); |
| 164 } |
| 165 if (a.type() == BlobData::TYPE_BLOB) { |
| 166 return a.blob_url() == b.blob_url() && |
| 167 a.offset() == b.offset() && |
| 168 a.length() == b.length(); |
| 169 } |
| 170 return false; |
| 171 } |
| 172 |
| 173 inline bool operator!=(const BlobData::Item& a, const BlobData::Item& b) { |
| 174 return !(a == b); |
| 175 } |
| 176 |
| 177 inline bool operator==(const BlobData& a, const BlobData& b) { |
| 178 if (a.content_type() != b.content_type()) |
| 179 return false; |
| 180 if (a.content_disposition() != b.content_disposition()) |
| 181 return false; |
| 182 if (a.items().size() != b.items().size()) |
| 183 return false; |
| 184 for (size_t i = 0; i < a.items().size(); ++i) { |
| 185 if (a.items()[i] != b.items()[i]) |
| 186 return false; |
| 187 } |
| 188 return true; |
| 189 } |
| 190 |
| 191 inline bool operator!=(const BlobData& a, const BlobData& b) { |
| 192 return !(a == b); |
| 193 } |
| 194 #endif // defined(UNIT_TEST) |
| 195 |
| 194 } // namespace webkit_blob | 196 } // namespace webkit_blob |
| 195 | 197 |
| 196 #endif // WEBKIT_BLOB_BLOB_DATA_H_ | 198 #endif // WEBKIT_BLOB_BLOB_DATA_H_ |
| OLD | NEW |