| 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 |
| 34 // The following "draining" functions drain and return the data. They |
| 35 // can return null when it is impossible to drain, and in such cases the |
| 36 // operation is no-op. |
| 37 // When they return a non-null value, the data will be drained and |
| 38 // subsequent calls of read() / beginRead() will return |Done|. |
| 39 // Moreover subsequent calls of draining functions will return null. |
| 40 // |
| 41 // A draining function will return null when any data was read, i.e. |
| 42 // read() / bedingRead() was called or any draining functions returned |
| 43 // a non-null value. There is one exception: when read() is called |
| 44 // with zero |size| and its return value is Ok or ShouldWait, no data |
| 45 // is regarded as read. |
| 46 |
| 33 // Drains the data as a BlobDataHandle. | 47 // Drains the data as a BlobDataHandle. |
| 34 // If this function returns non-null BlobDataHandle: | 48 // The returned non-null blob handle contains bytes that would be read |
| 35 // - The bytes that will be read from the returned BlobDataHandle | 49 // through WebDataConsumerHandle::Reader APIs without calling this |
| 36 // must be idential to the bytes that would be read through | 50 // function. |
| 37 // WebDataConsumerHandle::Reader APIs without calling this function. | 51 // When |policy| is DisallowBlobWithInvalidSize, this function doesn't |
| 38 // - Subsequent calls to read() / beginRead() return |Done|. | 52 // return a non-null blob handle with unspecified size. |
| 39 // This function can return |nullptr|, and in such cases this | |
| 40 // function is no-op. | |
| 41 // This function returns |nullptr| when called during two-phase read. | |
| 42 virtual PassRefPtr<BlobDataHandle> drainAsBlobDataHandle(BlobSizePolicy
= DisallowBlobWithInvalidSize) { return nullptr; } | 53 virtual PassRefPtr<BlobDataHandle> drainAsBlobDataHandle(BlobSizePolicy
= DisallowBlobWithInvalidSize) { return nullptr; } |
| 54 |
| 55 // Drains the data as a FormData. |
| 56 // This function returns a non-null form data when the handle is made |
| 57 // from a FormData-convertible value. |
| 58 virtual PassRefPtr<FormData> drainAsFormData() { return nullptr; } |
| 43 }; | 59 }; |
| 44 | 60 |
| 45 // TODO(yhirano): obtainReader() is currently non-virtual override, and | 61 // TODO(yhirano): obtainReader() is currently non-virtual override, and |
| 46 // will be changed into virtual override when we can use scoped_ptr / | 62 // will be changed into virtual override when we can use scoped_ptr / |
| 47 // unique_ptr in both Blink and Chromium. | 63 // unique_ptr in both Blink and Chromium. |
| 48 PassOwnPtr<Reader> obtainReader(Client* client) { return adoptPtr(obtainRead
erInternal(client)); } | 64 PassOwnPtr<Reader> obtainReader(Client* client) { return adoptPtr(obtainRead
erInternal(client)); } |
| 49 | 65 |
| 50 private: | 66 private: |
| 51 Reader* obtainReaderInternal(Client*) override = 0; | 67 Reader* obtainReaderInternal(Client*) override = 0; |
| 52 }; | 68 }; |
| 53 | 69 |
| 54 } // namespace blink | 70 } // namespace blink |
| 55 | 71 |
| 56 #endif // FetchDataConsumerHandle_h | 72 #endif // FetchDataConsumerHandle_h |
| OLD | NEW |