2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include "PlatformString.h"
36 #include <wtf/Forward.h>
37 #include <wtf/ThreadSafeRefCounted.h>
41 class RawData : public ThreadSafeRefCounted<RawData> {
43 static PassRefPtr<RawData> create()
45 return adoptRef(new RawData());
48 void detachFromCurrentThread();
50 const char* data() const { return m_data.data(); }
51 size_t length() const { return m_data.size(); }
52 Vector<char>* mutableData() { return &m_data; }
61 static const long long toEndOfFile;
62 static const double doNotCheckFileChange;
64 // Default constructor.
69 , expectedModificationTime(doNotCheckFileChange)
73 // Constructor for String type (complete string).
74 explicit BlobDataItem(PassRefPtr<RawData> data)
79 , expectedModificationTime(doNotCheckFileChange)
83 // Constructor for File type (complete file).
84 explicit BlobDataItem(const String& path)
89 , expectedModificationTime(doNotCheckFileChange)
93 // Constructor for File type (partial file).
94 BlobDataItem(const String& path, long long offset, long long length, double expectedModificationTime)
99 , expectedModificationTime(expectedModificationTime)
103 // Constructor for Blob type.
104 BlobDataItem(const KURL& url, long long offset, long long length)
109 , expectedModificationTime(doNotCheckFileChange)
113 // Detaches from current thread so that it can be passed to another thread.
114 void detachFromCurrentThread();
116 enum { Data, File, Blob } type;
119 RefPtr<RawData> data;
129 double expectedModificationTime;
132 friend class BlobData;
134 // Constructor for String type (partial string).
135 BlobDataItem(PassRefPtr<RawData> data, long long offset, long long length)
140 , expectedModificationTime(doNotCheckFileChange)
145 typedef Vector<BlobDataItem> BlobDataItemList;
148 WTF_MAKE_FAST_ALLOCATED;
150 static PassOwnPtr<BlobData> create();
152 // Detaches from current thread so that it can be passed to another thread.
153 void detachFromCurrentThread();
155 const String& contentType() const { return m_contentType; }
156 void setContentType(const String& contentType) { m_contentType = contentType; }
158 const String& contentDisposition() const { return m_contentDisposition; }
159 void setContentDisposition(const String& contentDisposition) { m_contentDisposition = contentDisposition; }
161 const BlobDataItemList& items() const { return m_items; }
162 void swapItems(BlobDataItemList&);
164 void appendData(PassRefPtr<RawData>, long long offset, long long length);
165 void appendFile(const String& path);
166 void appendFile(const String& path, long long offset, long long length, double expectedModificationTime);
167 void appendBlob(const KURL&, long long offset, long long length);
170 friend class BlobRegistryImpl;
171 friend class BlobStorageData;
175 // This is only exposed to BlobStorageData.
176 void appendData(const RawData&, long long offset, long long length);
178 String m_contentType;
179 String m_contentDisposition;
180 BlobDataItemList m_items;
183 } // namespace WebCore