Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(976)

Side by Side Diff: third_party/WebKit/Source/modules/fetch/BlobBytesConsumer.h

Issue 2287323002: Implement BlobBytesConsumer (Closed)
Patch Set: fix Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef BlobBytesConsumer_h
6 #define BlobBytesConsumer_h
7
8 #include "core/dom/ContextLifecycleObserver.h"
9 #include "core/loader/ThreadableLoaderClient.h"
10 #include "modules/ModulesExport.h"
11 #include "modules/fetch/BytesConsumer.h"
12 #include "platform/heap/Handle.h"
13 #include "wtf/PassRefPtr.h"
14 #include "wtf/RefPtr.h"
15 #include <memory>
16
17 namespace blink {
18
19 class BlobDataHandle;
20 class EncodedFormData;
21 class ExecutionContext;
22 class ThreadableLoader;
23 class WebDataConsumerHandle;
24
25 // A BlobBytesConsumer is created from a blob handle and it will
26 // return a valid handle from drainAsBlobDataHandle as much as possible.
27 class MODULES_EXPORT BlobBytesConsumer final : public BytesConsumer, public Cont extLifecycleObserver, public BytesConsumer::Client, public ThreadableLoaderClien t {
28 USING_GARBAGE_COLLECTED_MIXIN(BlobBytesConsumer);
29 USING_PRE_FINALIZER(BlobBytesConsumer, cancel);
30 public:
31 BlobBytesConsumer(ExecutionContext*, PassRefPtr<BlobDataHandle>);
32 ~BlobBytesConsumer() override;
33
34 // BytesConsumer implementation
35 Result beginRead(const char** buffer, size_t* available) override;
36 Result endRead(size_t readSize) override;
37 PassRefPtr<BlobDataHandle> drainAsBlobDataHandle(BlobSizePolicy) override;
38 PassRefPtr<EncodedFormData> drainAsFormData() override;
39 void setClient(BytesConsumer::Client*) override;
40 void clearClient() override;
41 void cancel() override;
42 PublicState getPublicState() const override;
43 Error getError() const override;
44 String debugName() const override { return "BlobBytesConsumer"; }
45
46 // ContextLifecycleObserver implementation
47 void contextDestroyed() override;
48
49 // BytesConsumer::Client implementation
50 void onStateChange() override;
51
52 // ThreadableLoaderClient implementation
53 void didReceiveResponse(unsigned long identifier, const ResourceResponse&, s td::unique_ptr<WebDataConsumerHandle>) override;
54 void didFinishLoading(unsigned long identifier, double finishTime) override;
55 void didFail(const ResourceError&) override;
56 void didFailRedirectCheck() override;
57
58 DECLARE_TRACE();
59
60 static BlobBytesConsumer* createForTesting(ExecutionContext*, PassRefPtr<Blo bDataHandle>, ThreadableLoader*);
61
62 private:
63 BlobBytesConsumer(ExecutionContext*, PassRefPtr<BlobDataHandle>, ThreadableL oader*);
64 ThreadableLoader* createLoader();
65 void didFailInternal();
66 bool isClean() const { return m_blobDataHandle.get(); }
67 void close();
68 void error();
69 void clear();
70
71 KURL m_blobURL;
72 RefPtr<BlobDataHandle> m_blobDataHandle;
73 Member<BytesConsumer> m_body;
74 Member<BytesConsumer::Client> m_client;
75 Member<ThreadableLoader> m_loader;
76
77 PublicState m_state = PublicState::ReadableOrWaiting;
78 // These two booleans are meaningful only when m_state is ReadableOrWaiting.
79 bool m_hasSeenEndOfData = false;
80 bool m_hasFinishedLoading = false;
81 };
82
83 } // namespace blink
84
85 #endif // BlobBytesConsumer_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698