Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / public / platform / WebBlobRegistry.h
blob9a5842b4c3b359b1f0d09707d0ed9ea55c9a338d
1 /*
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
6 * met:
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
13 * distribution.
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.
31 #ifndef WebBlobRegistry_h
32 #define WebBlobRegistry_h
34 #include "WebCommon.h"
35 #include "WebThreadSafeData.h"
37 namespace blink {
39 class WebBlobData;
40 class WebString;
41 class WebURL;
43 // Acts as singleton facade for all Blob interactions ouside of blink. This
44 // includes blob:
45 // * creation,
46 // * reference counting,
47 // * publishing, and
48 // * streaming.
49 class WebBlobRegistry {
50 public:
51 // Builder class for creating blobs. The blob is built on calling the
52 // build() method, where IPCs are sent to the browser.
53 // Preconditions:
54 // * Not meant to be used on multiple threads.
55 // * Must not be kept alive longer than creator WebBlobRegistry (shouldn't
56 // be an issue because of the singleton nature of the WebBlobRegistry)
57 // * append.* methods are invalid after build() is called.
58 class Builder {
59 public:
60 virtual ~Builder() { }
61 virtual void appendData(const WebThreadSafeData&) = 0;
62 virtual void appendFile(const WebString& path, uint64_t offset, uint64_t length, double expectedModificationTime) = 0;
63 // Calling this method ensures the given blob lives for the creation of
64 // the new blob.
65 virtual void appendBlob(const WebString& uuid, uint64_t offset, uint64_t length) = 0;
66 virtual void appendFileSystemURL(const WebURL&, uint64_t offset, uint64_t length, double expectedModificationTime) = 0;
68 // Builds the blob. All calls to append* are invalid after calling this
69 // method.
70 virtual void build() = 0;
73 virtual ~WebBlobRegistry() { }
75 // TODO(dmurph): Deprecate and migrate to createBuilder
76 virtual void registerBlobData(const WebString& uuid, const WebBlobData&) { }
78 // Caller takes ownership of the Builder. The blob is finalized (and sent to
79 // the browser) on calling build() on the Builder object.
80 virtual Builder* createBuilder(const WebString& uuid, const WebString& contentType) { BLINK_ASSERT_NOT_REACHED(); return nullptr; }
82 virtual void addBlobDataRef(const WebString& uuid) { }
83 virtual void removeBlobDataRef(const WebString& uuid) { }
84 virtual void registerPublicBlobURL(const WebURL&, const WebString& uuid) { }
85 virtual void revokePublicBlobURL(const WebURL&) { }
87 // Registers a stream URL referring to a stream with the specified media
88 // type.
89 virtual void registerStreamURL(const WebURL&, const WebString&) { BLINK_ASSERT_NOT_REACHED(); }
91 // Registers a stream URL referring to the stream identified by the
92 // specified srcURL.
93 virtual void registerStreamURL(const WebURL&, const WebURL& srcURL) { BLINK_ASSERT_NOT_REACHED(); }
95 // Add data to the stream referred by the URL.
96 virtual void addDataToStream(const WebURL&, const char* data, size_t length) { BLINK_ASSERT_NOT_REACHED(); }
98 // Flush contents buffered in the stream to the corresponding reader.
99 virtual void flushStream(const WebURL&) { BLINK_ASSERT_NOT_REACHED(); }
101 // Tell the registry that construction of this stream has completed
102 // successfully and so it won't receive any more data.
103 virtual void finalizeStream(const WebURL&) { BLINK_ASSERT_NOT_REACHED(); }
105 // Tell the registry that construction of this stream has been aborted and
106 // so it won't receive any more data.
107 virtual void abortStream(const WebURL&) { BLINK_ASSERT_NOT_REACHED(); }
109 // Unregisters a stream referred by the URL.
110 virtual void unregisterStreamURL(const WebURL&) { BLINK_ASSERT_NOT_REACHED(); }
113 } // namespace blink
115 #endif // WebBlobRegistry_h