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

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

Issue 2287323002: Implement BlobBytesConsumer (Closed)
Patch Set: fix Created 4 years, 2 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 // |handle| can be null. In that case this consumer gets closed.
32 BlobBytesConsumer(ExecutionContext*, PassRefPtr<BlobDataHandle> /* handle */ );
33 ~BlobBytesConsumer() override;
34
35 // BytesConsumer implementation
36 Result beginRead(const char** buffer, size_t* available) override;
37 Result endRead(size_t readSize) override;
38 PassRefPtr<BlobDataHandle> drainAsBlobDataHandle(BlobSizePolicy) override;
39 PassRefPtr<EncodedFormData> drainAsFormData() override;
40 void setClient(BytesConsumer::Client*) override;
41 void clearClient() override;
42 void cancel() override;
43 PublicState getPublicState() const override;
44 Error getError() const override;
45 String debugName() const override { return "BlobBytesConsumer"; }
46
47 // ContextLifecycleObserver implementation
48 void contextDestroyed() override;
49
50 // BytesConsumer::Client implementation
51 void onStateChange() override;
52
53 // ThreadableLoaderClient implementation
54 void didReceiveResponse(unsigned long identifier, const ResourceResponse&, s td::unique_ptr<WebDataConsumerHandle>) override;
55 void didFinishLoading(unsigned long identifier, double finishTime) override;
56 void didFail(const ResourceError&) override;
57 void didFailRedirectCheck() override;
58
59 DECLARE_TRACE();
60
61 static BlobBytesConsumer* createForTesting(ExecutionContext*, PassRefPtr<Blo bDataHandle>, ThreadableLoader*);
62
63 private:
64 BlobBytesConsumer(ExecutionContext*, PassRefPtr<BlobDataHandle>, ThreadableL oader*);
65 ThreadableLoader* createLoader();
66 void didFailInternal();
67 bool isClean() const { return m_blobDataHandle.get(); }
68 void close();
69 void error();
70 void clear();
71
72 KURL m_blobURL;
73 RefPtr<BlobDataHandle> m_blobDataHandle;
74 Member<BytesConsumer> m_body;
75 Member<BytesConsumer::Client> m_client;
76 Member<ThreadableLoader> m_loader;
77
78 PublicState m_state = PublicState::ReadableOrWaiting;
79 // These two booleans are meaningful only when m_state is ReadableOrWaiting.
80 bool m_hasSeenEndOfData = false;
81 bool m_hasFinishedLoading = false;
82 };
83
84 } // namespace blink
85
86 #endif // BlobBytesConsumer_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698