OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef FetchDataConsumerHandle_h | 5 #ifndef FetchDataConsumerHandle_h |
6 #define FetchDataConsumerHandle_h | 6 #define FetchDataConsumerHandle_h |
7 | 7 |
8 #include "modules/ModulesExport.h" | 8 #include "modules/ModulesExport.h" |
9 #include "platform/blob/BlobData.h" | 9 #include "platform/blob/BlobData.h" |
10 #include "platform/network/FormData.h" | |
10 #include "public/platform/WebDataConsumerHandle.h" | 11 #include "public/platform/WebDataConsumerHandle.h" |
11 #include "wtf/Forward.h" | 12 #include "wtf/Forward.h" |
12 #include "wtf/PassRefPtr.h" | 13 #include "wtf/PassRefPtr.h" |
13 | 14 |
14 namespace blink { | 15 namespace blink { |
15 | 16 |
16 // This is an interface class that adds Reader's blobDataHandle() to | 17 // This is an interface class that adds Reader's blobDataHandle() to |
17 // WebDataConsumerHandle. | 18 // WebDataConsumerHandle. |
18 // This class works not very well with Oilpan: As this class is not garbage | 19 // This class works not very well with Oilpan: As this class is not garbage |
19 // collected while many clients or related objects may be, it is very easy | 20 // collected while many clients or related objects may be, it is very easy |
20 // to create a reference cycle. When an client is garbage collected, making | 21 // to create a reference cycle. When an client is garbage collected, making |
21 // the client own the handle is the right way. | 22 // the client own the handle is the right way. |
22 class MODULES_EXPORT FetchDataConsumerHandle : public WebDataConsumerHandle { | 23 class MODULES_EXPORT FetchDataConsumerHandle : public WebDataConsumerHandle { |
23 public: | 24 public: |
24 class Reader : public WebDataConsumerHandle::Reader { | 25 class Reader : public WebDataConsumerHandle::Reader { |
25 public: | 26 public: |
26 enum BlobSizePolicy { | 27 enum BlobSizePolicy { |
27 // The returned blob must have a valid size (i.e. != kuint64max). | 28 // The returned blob must have a valid size (i.e. != kuint64max). |
28 DisallowBlobWithInvalidSize, | 29 DisallowBlobWithInvalidSize, |
29 // The returned blob can have an invalid size. | 30 // The returned blob can have an invalid size. |
30 AllowBlobWithInvalidSize | 31 AllowBlobWithInvalidSize |
31 }; | 32 }; |
32 | 33 |
33 // Drains the data as a BlobDataHandle. | 34 // Drains the data as a BlobDataHandle. |
34 // If this function returns non-null BlobDataHandle: | 35 // If this function returns non-null BlobDataHandle: |
35 // - The bytes that will be read from the returned BlobDataHandle | 36 // - The bytes that will be read from the returned BlobDataHandle |
36 // must be idential to the bytes that would be read through | 37 // must be idential to the bytes that would be read through |
37 // WebDataConsumerHandle::Reader APIs without calling this function. | 38 // WebDataConsumerHandle::Reader APIs without calling this function. |
38 // - Subsequent calls to read() / beginRead() return |Done|. | 39 // - Subsequent calls to read() / beginRead() return |Done|. |
hiroshige
2015/08/11 09:35:01
Please add "and subsequent calls to drainAsFormDat
yhirano
2015/08/11 11:36:01
I rewrote comments.
| |
39 // This function can return |nullptr|, and in such cases this | 40 // This function can return |nullptr|, and in such cases this |
40 // function is no-op. | 41 // function is no-op. |
41 // This function returns |nullptr| when called during two-phase read. | 42 // This function returns |nullptr| when called during two-phase read. |
42 virtual PassRefPtr<BlobDataHandle> drainAsBlobDataHandle(BlobSizePolicy = DisallowBlobWithInvalidSize) { return nullptr; } | 43 virtual PassRefPtr<BlobDataHandle> drainAsBlobDataHandle(BlobSizePolicy = DisallowBlobWithInvalidSize) { return nullptr; } |
44 | |
45 // Drains the data as a FormData. | |
46 // This function returns a non-null form data when | |
47 // - The handle is made from a FormData-convertible type, | |
48 // - The reader is running on a suitable thread, and | |
hiroshige
2015/08/11 09:35:01
What is "a suitable thread"? Isn't this a general
yhirano
2015/08/11 11:36:01
Sorry the restriction was gone.
| |
49 // - No data is read yet. | |
50 // After that read() / beginRead() will return |Done|. | |
hiroshige
2015/08/11 09:35:01
Please add "and drainAsBlobDataHandle() will retur
yhirano
2015/08/11 11:36:01
I rewrote comments.
| |
51 // Otherwise this function does nothing and returns null. | |
52 // This function returns |nullptr| when called during two-phase read. | |
53 virtual PassRefPtr<FormData> drainAsFormData() { return nullptr; } | |
43 }; | 54 }; |
44 | 55 |
45 // TODO(yhirano): obtainReader() is currently non-virtual override, and | 56 // TODO(yhirano): obtainReader() is currently non-virtual override, and |
46 // will be changed into virtual override when we can use scoped_ptr / | 57 // will be changed into virtual override when we can use scoped_ptr / |
47 // unique_ptr in both Blink and Chromium. | 58 // unique_ptr in both Blink and Chromium. |
48 PassOwnPtr<Reader> obtainReader(Client* client) { return adoptPtr(obtainRead erInternal(client)); } | 59 PassOwnPtr<Reader> obtainReader(Client* client) { return adoptPtr(obtainRead erInternal(client)); } |
49 | 60 |
50 private: | 61 private: |
51 Reader* obtainReaderInternal(Client*) override = 0; | 62 Reader* obtainReaderInternal(Client*) override = 0; |
52 }; | 63 }; |
53 | 64 |
54 } // namespace blink | 65 } // namespace blink |
55 | 66 |
56 #endif // FetchDataConsumerHandle_h | 67 #endif // FetchDataConsumerHandle_h |
OLD | NEW |