| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 }; | 145 }; |
| 146 | 146 |
| 147 typedef Vector<BlobDataItem> BlobDataItemList; | 147 typedef Vector<BlobDataItem> BlobDataItemList; |
| 148 | 148 |
| 149 class PLATFORM_EXPORT BlobData { | 149 class PLATFORM_EXPORT BlobData { |
| 150 USING_FAST_MALLOC(BlobData); | 150 USING_FAST_MALLOC(BlobData); |
| 151 WTF_MAKE_NONCOPYABLE(BlobData); | 151 WTF_MAKE_NONCOPYABLE(BlobData); |
| 152 | 152 |
| 153 public: | 153 public: |
| 154 static std::unique_ptr<BlobData> create(); | 154 static std::unique_ptr<BlobData> create(); |
| 155 // Calling append* on the returned object will check-fail. The caller can only | 155 |
| 156 // have an unknown-length file if it is the only item in the blob. | 156 // Calling append* on objects returned by createFor___WithUnknownSize will |
| 157 // check-fail. The caller can only have an unknown-length file if it is the |
| 158 // only item in the blob. |
| 157 static std::unique_ptr<BlobData> createForFileWithUnknownSize( | 159 static std::unique_ptr<BlobData> createForFileWithUnknownSize( |
| 158 const String& path); | 160 const String& path); |
| 161 static std::unique_ptr<BlobData> createForFileWithUnknownSize( |
| 162 const String& path, |
| 163 double expectedModificationTime); |
| 164 static std::unique_ptr<BlobData> createForFileSystemURLWithUnknownSize( |
| 165 const KURL& fileSystemURL, |
| 166 double expectedModificationTime); |
| 159 | 167 |
| 160 // Detaches from current thread so that it can be passed to another thread. | 168 // Detaches from current thread so that it can be passed to another thread. |
| 161 void detachFromCurrentThread(); | 169 void detachFromCurrentThread(); |
| 162 | 170 |
| 163 const String& contentType() const { return m_contentType; } | 171 const String& contentType() const { return m_contentType; } |
| 164 void setContentType(const String&); | 172 void setContentType(const String&); |
| 165 | 173 |
| 166 const BlobDataItemList& items() const { return m_items; } | 174 const BlobDataItemList& items() const { return m_items; } |
| 167 | 175 |
| 168 void appendBytes(const void*, size_t length); | 176 void appendBytes(const void*, size_t length); |
| 169 void appendData(PassRefPtr<RawData>, long long offset, long long length); | 177 void appendData(PassRefPtr<RawData>, long long offset, long long length); |
| 170 void appendFile(const String& path, | 178 void appendFile(const String& path, |
| 171 long long offset, | 179 long long offset, |
| 172 long long length, | 180 long long length, |
| 173 double expectedModificationTime); | 181 double expectedModificationTime); |
| 182 |
| 183 // The given blob must not be a file with unknown size. Please use the |
| 184 // File::appendTo instead. |
| 174 void appendBlob(PassRefPtr<BlobDataHandle>, | 185 void appendBlob(PassRefPtr<BlobDataHandle>, |
| 175 long long offset, | 186 long long offset, |
| 176 long long length); | 187 long long length); |
| 177 void appendFileSystemURL(const KURL&, | 188 void appendFileSystemURL(const KURL&, |
| 178 long long offset, | 189 long long offset, |
| 179 long long length, | 190 long long length, |
| 180 double expectedModificationTime); | 191 double expectedModificationTime); |
| 181 void appendText(const String&, bool normalizeLineEndingsToNative); | 192 void appendText(const String&, bool normalizeLineEndingsToNative); |
| 182 | 193 |
| 183 // The value of the size property for a Blob who has this data. | 194 // The value of the size property for a Blob who has this data. |
| 184 // BlobDataItem::toEndOfFile if the Blob has a file whose size was not yet | 195 // BlobDataItem::toEndOfFile if the Blob has a file whose size was not yet |
| 185 // determined. | 196 // determined. |
| 186 long long length() const; | 197 long long length() const; |
| 187 | 198 |
| 199 bool isSingleUnknownSizeFile() const { |
| 200 return m_fileComposition == FileCompositionStatus::SINGLE_UNKNOWN_SIZE_FILE; |
| 201 } |
| 202 |
| 188 private: | 203 private: |
| 189 FRIEND_TEST_ALL_PREFIXES(BlobDataTest, Consolidation); | 204 FRIEND_TEST_ALL_PREFIXES(BlobDataTest, Consolidation); |
| 190 | 205 |
| 191 enum class FileCompositionStatus { | 206 enum class FileCompositionStatus { |
| 192 SINGLE_UNKNOWN_SIZE_FILE, | 207 SINGLE_UNKNOWN_SIZE_FILE, |
| 193 NO_UNKNOWN_SIZE_FILES | 208 NO_UNKNOWN_SIZE_FILES |
| 194 }; | 209 }; |
| 195 | 210 |
| 196 explicit BlobData(FileCompositionStatus composition) | 211 explicit BlobData(FileCompositionStatus composition) |
| 197 : m_fileComposition(composition) {} | 212 : m_fileComposition(composition) {} |
| (...skipping 23 matching lines...) Expand all Loading... |
| 221 static PassRefPtr<BlobDataHandle> create(const String& uuid, | 236 static PassRefPtr<BlobDataHandle> create(const String& uuid, |
| 222 const String& type, | 237 const String& type, |
| 223 long long size) { | 238 long long size) { |
| 224 return adoptRef(new BlobDataHandle(uuid, type, size)); | 239 return adoptRef(new BlobDataHandle(uuid, type, size)); |
| 225 } | 240 } |
| 226 | 241 |
| 227 String uuid() const { return m_uuid.isolatedCopy(); } | 242 String uuid() const { return m_uuid.isolatedCopy(); } |
| 228 String type() const { return m_type.isolatedCopy(); } | 243 String type() const { return m_type.isolatedCopy(); } |
| 229 unsigned long long size() const { return m_size; } | 244 unsigned long long size() const { return m_size; } |
| 230 | 245 |
| 246 bool isSingleUnknownSizeFile() const { return m_isSingleUnknownSizeFile; } |
| 247 |
| 231 ~BlobDataHandle(); | 248 ~BlobDataHandle(); |
| 232 | 249 |
| 233 private: | 250 private: |
| 234 BlobDataHandle(); | 251 BlobDataHandle(); |
| 235 BlobDataHandle(std::unique_ptr<BlobData>, long long size); | 252 BlobDataHandle(std::unique_ptr<BlobData>, long long size); |
| 236 BlobDataHandle(const String& uuid, const String& type, long long size); | 253 BlobDataHandle(const String& uuid, const String& type, long long size); |
| 237 | 254 |
| 238 const String m_uuid; | 255 const String m_uuid; |
| 239 const String m_type; | 256 const String m_type; |
| 240 const long long m_size; | 257 const long long m_size; |
| 258 const bool m_isSingleUnknownSizeFile; |
| 241 }; | 259 }; |
| 242 | 260 |
| 243 } // namespace blink | 261 } // namespace blink |
| 244 | 262 |
| 245 #endif // BlobData_h | 263 #endif // BlobData_h |
| OLD | NEW |