| 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 FetchDataLoader_h | 5 #ifndef FetchDataLoader_h |
| 6 #define FetchDataLoader_h | 6 #define FetchDataLoader_h |
| 7 | 7 |
| 8 #include "core/dom/DOMArrayBuffer.h" | 8 #include "core/dom/DOMArrayBuffer.h" |
| 9 #include "core/streams/Stream.h" | 9 #include "core/streams/Stream.h" |
| 10 #include "modules/ModulesExport.h" | 10 #include "modules/ModulesExport.h" |
| 11 #include "mojo/public/cpp/system/data_pipe.h" | 11 #include "mojo/public/cpp/system/data_pipe.h" |
| 12 #include "platform/blob/BlobData.h" | 12 #include "platform/blob/BlobData.h" |
| 13 #include "platform/heap/Handle.h" | 13 #include "platform/heap/Handle.h" |
| 14 #include "platform/wtf/Forward.h" | 14 #include "platform/wtf/Forward.h" |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 class BytesConsumer; | 18 class BytesConsumer; |
| 19 class FormData; |
| 19 | 20 |
| 20 // FetchDataLoader subclasses | 21 // FetchDataLoader subclasses |
| 21 // 1. take a BytesConsumer, | 22 // 1. take a BytesConsumer, |
| 22 // 2. read all data, and | 23 // 2. read all data, and |
| 23 // 3. call either didFetchDataLoaded...() on success or | 24 // 3. call either didFetchDataLoaded...() on success or |
| 24 // difFetchDataLoadFailed() otherwise | 25 // difFetchDataLoadFailed() otherwise |
| 25 // on the thread where FetchDataLoader is created. | 26 // on the thread where FetchDataLoader is created. |
| 26 // | 27 // |
| 27 // - Client's methods can be called synchronously in start(). | 28 // - Client's methods can be called synchronously in start(). |
| 28 // - If FetchDataLoader::cancel() is called, Client's methods will not be | 29 // - If FetchDataLoader::cancel() is called, Client's methods will not be |
| 29 // called anymore. | 30 // called anymore. |
| 30 class MODULES_EXPORT FetchDataLoader | 31 class MODULES_EXPORT FetchDataLoader |
| 31 : public GarbageCollectedFinalized<FetchDataLoader> { | 32 : public GarbageCollectedFinalized<FetchDataLoader> { |
| 32 public: | 33 public: |
| 33 class MODULES_EXPORT Client : public GarbageCollectedMixin { | 34 class MODULES_EXPORT Client : public GarbageCollectedMixin { |
| 34 public: | 35 public: |
| 35 virtual ~Client() {} | 36 virtual ~Client() {} |
| 36 | 37 |
| 37 // The method corresponding to createLoaderAs... is called on success. | 38 // The method corresponding to createLoaderAs... is called on success. |
| 38 virtual void DidFetchDataLoadedBlobHandle(PassRefPtr<BlobDataHandle>) { | 39 virtual void DidFetchDataLoadedBlobHandle(PassRefPtr<BlobDataHandle>) { |
| 39 NOTREACHED(); | 40 NOTREACHED(); |
| 40 } | 41 } |
| 41 virtual void DidFetchDataLoadedArrayBuffer(DOMArrayBuffer*) { | 42 virtual void DidFetchDataLoadedArrayBuffer(DOMArrayBuffer*) { |
| 42 NOTREACHED(); | 43 NOTREACHED(); |
| 43 } | 44 } |
| 45 virtual void DidFetchDataLoadedFormData(FormData*) { NOTREACHED(); } |
| 44 virtual void DidFetchDataLoadedString(const String&) { NOTREACHED(); } | 46 virtual void DidFetchDataLoadedString(const String&) { NOTREACHED(); } |
| 45 // This is called after all data are read from |handle| and written | 47 // This is called after all data are read from |handle| and written |
| 46 // to |out_data_pipe|, and |out_data_pipe| is closed or aborted. | 48 // to |out_data_pipe|, and |out_data_pipe| is closed or aborted. |
| 47 virtual void DidFetchDataLoadedDataPipe() { NOTREACHED(); } | 49 virtual void DidFetchDataLoadedDataPipe() { NOTREACHED(); } |
| 48 | 50 |
| 49 // This function is called when a "custom" FetchDataLoader (none of the | 51 // This function is called when a "custom" FetchDataLoader (none of the |
| 50 // ones listed above) finishes loading. | 52 // ones listed above) finishes loading. |
| 51 virtual void DidFetchDataLoadedCustomFormat() { NOTREACHED(); } | 53 virtual void DidFetchDataLoadedCustomFormat() { NOTREACHED(); } |
| 52 | 54 |
| 53 virtual void DidFetchDataLoadFailed() = 0; | 55 virtual void DidFetchDataLoadFailed() = 0; |
| 54 | 56 |
| 55 DEFINE_INLINE_VIRTUAL_TRACE() {} | 57 DEFINE_INLINE_VIRTUAL_TRACE() {} |
| 56 }; | 58 }; |
| 57 | 59 |
| 58 static FetchDataLoader* CreateLoaderAsBlobHandle(const String& mime_type); | 60 static FetchDataLoader* CreateLoaderAsBlobHandle(const String& mime_type); |
| 59 static FetchDataLoader* CreateLoaderAsArrayBuffer(); | 61 static FetchDataLoader* CreateLoaderAsArrayBuffer(); |
| 62 static FetchDataLoader* CreateLoaderAsFormData( |
| 63 const String& multipart_boundary); |
| 60 static FetchDataLoader* CreateLoaderAsString(); | 64 static FetchDataLoader* CreateLoaderAsString(); |
| 61 static FetchDataLoader* CreateLoaderAsDataPipe( | 65 static FetchDataLoader* CreateLoaderAsDataPipe( |
| 62 mojo::ScopedDataPipeProducerHandle out_data_pipe); | 66 mojo::ScopedDataPipeProducerHandle out_data_pipe); |
| 63 | 67 |
| 64 virtual ~FetchDataLoader() {} | 68 virtual ~FetchDataLoader() {} |
| 65 | 69 |
| 66 // |consumer| must not have a client when called. | 70 // |consumer| must not have a client when called. |
| 67 virtual void Start(BytesConsumer* /* consumer */, Client*) = 0; | 71 virtual void Start(BytesConsumer* /* consumer */, Client*) = 0; |
| 68 | 72 |
| 69 virtual void Cancel() = 0; | 73 virtual void Cancel() = 0; |
| 70 | 74 |
| 71 DEFINE_INLINE_VIRTUAL_TRACE() {} | 75 DEFINE_INLINE_VIRTUAL_TRACE() {} |
| 72 }; | 76 }; |
| 73 | 77 |
| 74 } // namespace blink | 78 } // namespace blink |
| 75 | 79 |
| 76 #endif // FetchDataLoader_h | 80 #endif // FetchDataLoader_h |
| OLD | NEW |