| 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 21 matching lines...) Expand all Loading... |
| 32 #define BlobData_h | 32 #define BlobData_h |
| 33 | 33 |
| 34 #include "FileSystem.h" | 34 #include "FileSystem.h" |
| 35 #include "KURL.h" | 35 #include "KURL.h" |
| 36 #include <wtf/Forward.h> | 36 #include <wtf/Forward.h> |
| 37 #include <wtf/ThreadSafeRefCounted.h> | 37 #include <wtf/ThreadSafeRefCounted.h> |
| 38 #include <wtf/text/WTFString.h> | 38 #include <wtf/text/WTFString.h> |
| 39 | 39 |
| 40 namespace WebCore { | 40 namespace WebCore { |
| 41 | 41 |
| 42 class BlobDataHandle; |
| 43 |
| 42 class RawData : public ThreadSafeRefCounted<RawData> { | 44 class RawData : public ThreadSafeRefCounted<RawData> { |
| 43 public: | 45 public: |
| 44 static PassRefPtr<RawData> create() | 46 static PassRefPtr<RawData> create() |
| 45 { | 47 { |
| 46 return adoptRef(new RawData()); | 48 return adoptRef(new RawData()); |
| 47 } | 49 } |
| 48 | 50 |
| 49 void detachFromCurrentThread(); | 51 void detachFromCurrentThread(); |
| 50 | 52 |
| 51 const char* data() const { return m_data.data(); } | 53 const char* data() const { return m_data.data(); } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 BlobDataItem(const String& path, long long offset, long long length, double
expectedModificationTime) | 96 BlobDataItem(const String& path, long long offset, long long length, double
expectedModificationTime) |
| 95 : type(File) | 97 : type(File) |
| 96 , path(path) | 98 , path(path) |
| 97 , offset(offset) | 99 , offset(offset) |
| 98 , length(length) | 100 , length(length) |
| 99 , expectedModificationTime(expectedModificationTime) | 101 , expectedModificationTime(expectedModificationTime) |
| 100 { | 102 { |
| 101 } | 103 } |
| 102 | 104 |
| 103 // Constructor for Blob type. | 105 // Constructor for Blob type. |
| 104 BlobDataItem(const KURL& url, long long offset, long long length) | 106 BlobDataItem(PassRefPtr<BlobDataHandle> blobDataHandle, long long offset, lo
ng long length) |
| 105 : type(Blob) | 107 : type(Blob) |
| 106 , url(url) | 108 , blobDataHandle(blobDataHandle) |
| 107 , offset(offset) | 109 , offset(offset) |
| 108 , length(length) | 110 , length(length) |
| 109 , expectedModificationTime(invalidFileTime()) | 111 , expectedModificationTime(invalidFileTime()) |
| 110 { | 112 { |
| 111 } | 113 } |
| 112 | 114 |
| 113 #if ENABLE(FILE_SYSTEM) | 115 #if ENABLE(FILE_SYSTEM) |
| 114 // Constructor for URL type (e.g. FileSystem files). | 116 // Constructor for URL type (e.g. FileSystem files). |
| 115 BlobDataItem(const KURL& url, long long offset, long long length, double exp
ectedModificationTime) | 117 BlobDataItem(const KURL& fileSystemURL, long long offset, long long length,
double expectedModificationTime) |
| 116 : type(URL) | 118 : type(FileSystemURL) |
| 117 , url(url) | 119 , fileSystemURL(fileSystemURL) |
| 118 , offset(offset) | 120 , offset(offset) |
| 119 , length(length) | 121 , length(length) |
| 120 , expectedModificationTime(expectedModificationTime) | 122 , expectedModificationTime(expectedModificationTime) |
| 121 { | 123 { |
| 122 } | 124 } |
| 123 #endif | 125 #endif |
| 124 | 126 |
| 125 // Detaches from current thread so that it can be passed to another thread. | 127 // Detaches from current thread so that it can be passed to another thread. |
| 126 void detachFromCurrentThread(); | 128 void detachFromCurrentThread(); |
| 127 | 129 |
| 128 enum { | 130 enum { |
| 129 Data, | 131 Data, |
| 130 File, | 132 File, |
| 131 Blob | 133 Blob |
| 132 #if ENABLE(FILE_SYSTEM) | 134 #if ENABLE(FILE_SYSTEM) |
| 133 , URL | 135 , FileSystemURL |
| 134 #endif | 136 #endif |
| 135 } type; | 137 } type; |
| 136 | 138 |
| 137 // For Data type. | 139 // For Data type. |
| 138 RefPtr<RawData> data; | 140 RefPtr<RawData> data; |
| 139 | 141 |
| 140 // For File type. | 142 // For File type. |
| 141 String path; | 143 String path; |
| 142 | 144 |
| 143 // For Blob or URL type. | 145 // For FileSystem URL type. |
| 144 KURL url; | 146 KURL fileSystemURL; |
| 147 |
| 148 // For Blob type. |
| 149 RefPtr<BlobDataHandle> blobDataHandle; |
| 145 | 150 |
| 146 long long offset; | 151 long long offset; |
| 147 long long length; | 152 long long length; |
| 148 double expectedModificationTime; | 153 double expectedModificationTime; |
| 149 | 154 |
| 150 private: | 155 private: |
| 151 friend class BlobData; | 156 friend class BlobData; |
| 152 | 157 |
| 153 // Constructor for String type (partial string). | 158 // Constructor for String type (partial string). |
| 154 BlobDataItem(PassRefPtr<RawData> data, long long offset, long long length) | 159 BlobDataItem(PassRefPtr<RawData> data, long long offset, long long length) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 176 | 181 |
| 177 const String& contentDisposition() const { return m_contentDisposition; } | 182 const String& contentDisposition() const { return m_contentDisposition; } |
| 178 void setContentDisposition(const String& contentDisposition) { m_contentDisp
osition = contentDisposition; } | 183 void setContentDisposition(const String& contentDisposition) { m_contentDisp
osition = contentDisposition; } |
| 179 | 184 |
| 180 const BlobDataItemList& items() const { return m_items; } | 185 const BlobDataItemList& items() const { return m_items; } |
| 181 void swapItems(BlobDataItemList&); | 186 void swapItems(BlobDataItemList&); |
| 182 | 187 |
| 183 void appendData(PassRefPtr<RawData>, long long offset, long long length); | 188 void appendData(PassRefPtr<RawData>, long long offset, long long length); |
| 184 void appendFile(const String& path); | 189 void appendFile(const String& path); |
| 185 void appendFile(const String& path, long long offset, long long length, doub
le expectedModificationTime); | 190 void appendFile(const String& path, long long offset, long long length, doub
le expectedModificationTime); |
| 186 void appendBlob(const KURL&, long long offset, long long length); | 191 void appendBlob(PassRefPtr<BlobDataHandle>, long long offset, long long leng
th); |
| 187 #if ENABLE(FILE_SYSTEM) | 192 #if ENABLE(FILE_SYSTEM) |
| 188 void appendURL(const KURL&, long long offset, long long length, double expec
tedModificationTime); | 193 void appendFileSystemURL(const KURL&, long long offset, long long length, do
uble expectedModificationTime); |
| 189 #endif | 194 #endif |
| 190 | 195 |
| 191 private: | 196 private: |
| 192 friend class BlobRegistryImpl; | 197 friend class BlobRegistryImpl; |
| 193 friend class BlobStorageData; | 198 friend class BlobStorageData; |
| 194 | 199 |
| 195 BlobData() { } | 200 BlobData() { } |
| 196 | 201 |
| 197 // This is only exposed to BlobStorageData. | 202 // This is only exposed to BlobStorageData. |
| 198 void appendData(const RawData&, long long offset, long long length); | 203 void appendData(const RawData&, long long offset, long long length); |
| 199 | 204 |
| 200 String m_contentType; | 205 String m_contentType; |
| 201 String m_contentDisposition; | 206 String m_contentDisposition; |
| 202 BlobDataItemList m_items; | 207 BlobDataItemList m_items; |
| 203 }; | 208 }; |
| 204 | 209 |
| 210 class BlobDataHandle : public ThreadSafeRefCounted<BlobDataHandle> { |
| 211 public: |
| 212 // For empty blob construction. |
| 213 static PassRefPtr<BlobDataHandle> create() |
| 214 { |
| 215 return adoptRef(new BlobDataHandle()); |
| 216 } |
| 217 |
| 218 // For initial creation. |
| 219 static PassRefPtr<BlobDataHandle> create(PassOwnPtr<BlobData> data, long lon
g size) |
| 220 { |
| 221 return adoptRef(new BlobDataHandle(data, size)); |
| 222 } |
| 223 |
| 224 // For deserialization of script values and ipc messages. |
| 225 static PassRefPtr<BlobDataHandle> create(const String& uuid, const String& t
ype, long long size) |
| 226 { |
| 227 return adoptRef(new BlobDataHandle(uuid, type, size)); |
| 228 } |
| 229 |
| 230 String uuid() const { return m_uuid.isolatedCopy(); } |
| 231 String type() const { return m_type.isolatedCopy(); } |
| 232 unsigned long long size() { return m_size; } |
| 233 |
| 234 ~BlobDataHandle(); |
| 235 |
| 236 private: |
| 237 BlobDataHandle(); |
| 238 BlobDataHandle(PassOwnPtr<BlobData> data, long long size); |
| 239 BlobDataHandle(const String& uuid, const String& type, long long size); |
| 240 |
| 241 // FIXME: check that null or empty strings don't have some wierd thread affi
nity that isolatedCopy() doesn't evade??? |
| 242 const String m_uuid; |
| 243 const String m_type; |
| 244 const long long m_size; |
| 245 }; |
| 246 |
| 205 } // namespace WebCore | 247 } // namespace WebCore |
| 206 | 248 |
| 207 #endif // BlobData_h | 249 #endif // BlobData_h |
| OLD | NEW |