| 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 "platform/blob/BlobData.h" |  12 #include "platform/blob/BlobData.h" | 
|  12 #include "platform/heap/Handle.h" |  13 #include "platform/heap/Handle.h" | 
|  13 #include "wtf/Forward.h" |  14 #include "wtf/Forward.h" | 
|  14  |  15  | 
|  15 namespace blink { |  16 namespace blink { | 
|  16  |  17  | 
|  17 class BytesConsumer; |  18 class BytesConsumer; | 
|  18  |  19  | 
|  19 // FetchDataLoader subclasses |  20 // FetchDataLoader subclasses | 
|  20 // 1. take a BytesConsumer, |  21 // 1. take a BytesConsumer, | 
|  21 // 2. read all data, and |  22 // 2. read all data, and | 
|  22 // 3. call either didFetchDataLoaded...() on success or |  23 // 3. call either didFetchDataLoaded...() on success or | 
|  23 //    difFetchDataLoadFailed() otherwise |  24 //    difFetchDataLoadFailed() otherwise | 
|  24 //    on the thread where FetchDataLoader is created. |  25 //    on the thread where FetchDataLoader is created. | 
|  25 // |  26 // | 
|  26 // - Client's methods can be called synchronously in start(). |  27 // - Client's methods can be called synchronously in start(). | 
|  27 // - If FetchDataLoader::cancel() is called, Client's methods will not be |  28 // - If FetchDataLoader::cancel() is called, Client's methods will not be | 
|  28 //   called anymore. |  29 //   called anymore. | 
|  29 class MODULES_EXPORT FetchDataLoader |  30 class MODULES_EXPORT FetchDataLoader | 
|  30     : public GarbageCollectedFinalized<FetchDataLoader> { |  31     : public GarbageCollectedFinalized<FetchDataLoader> { | 
|  31  public: |  32  public: | 
|  32   class MODULES_EXPORT Client : public GarbageCollectedMixin { |  33   class MODULES_EXPORT Client : public GarbageCollectedMixin { | 
|  33    public: |  34    public: | 
|  34     virtual ~Client() {} |  35     virtual ~Client() {} | 
|  35  |  36  | 
|  36     // The method corresponding to createLoaderAs... is called on success. |  37     // The method corresponding to createLoaderAs... is called on success. | 
|  37     virtual void didFetchDataLoadedBlobHandle(PassRefPtr<BlobDataHandle>) { |  38     virtual void didFetchDataLoadedBlobHandle(PassRefPtr<BlobDataHandle>) { | 
|  38       ASSERT_NOT_REACHED(); |  39       NOTREACHED(); | 
|  39     } |  40     } | 
|  40     virtual void didFetchDataLoadedArrayBuffer(DOMArrayBuffer*) { |  41     virtual void didFetchDataLoadedArrayBuffer(DOMArrayBuffer*) { | 
|  41       ASSERT_NOT_REACHED(); |  42       NOTREACHED(); | 
|  42     } |  43     } | 
|  43     virtual void didFetchDataLoadedString(const String&) { |  44     virtual void didFetchDataLoadedString(const String&) { NOTREACHED(); } | 
|  44       ASSERT_NOT_REACHED(); |  | 
|  45     } |  | 
|  46     // This is called after all data are read from |handle| and written |  45     // This is called after all data are read from |handle| and written | 
|  47     // to |outStream|, and |outStream| is closed or aborted. |  46     // to |outDataPipe|, and |outDataPipe| is closed or aborted. | 
|  48     virtual void didFetchDataLoadedStream() { ASSERT_NOT_REACHED(); } |  47     virtual void didFetchDataLoadedDataPipe() { NOTREACHED(); } | 
|  49  |  48  | 
|  50     virtual void didFetchDataLoadFailed() = 0; |  49     virtual void didFetchDataLoadFailed() = 0; | 
|  51  |  50  | 
|  52     DEFINE_INLINE_VIRTUAL_TRACE() {} |  51     DEFINE_INLINE_VIRTUAL_TRACE() {} | 
|  53   }; |  52   }; | 
|  54  |  53  | 
|  55   static FetchDataLoader* createLoaderAsBlobHandle(const String& mimeType); |  54   static FetchDataLoader* createLoaderAsBlobHandle(const String& mimeType); | 
|  56   static FetchDataLoader* createLoaderAsArrayBuffer(); |  55   static FetchDataLoader* createLoaderAsArrayBuffer(); | 
|  57   static FetchDataLoader* createLoaderAsString(); |  56   static FetchDataLoader* createLoaderAsString(); | 
|  58   static FetchDataLoader* createLoaderAsStream(Stream* outStream); |  57   static FetchDataLoader* createLoaderAsDataPipe( | 
 |  58       mojo::ScopedDataPipeProducerHandle outDataPipe); | 
|  59  |  59  | 
|  60   virtual ~FetchDataLoader() {} |  60   virtual ~FetchDataLoader() {} | 
|  61  |  61  | 
|  62   // |consumer| must not have a client when called. |  62   // |consumer| must not have a client when called. | 
|  63   virtual void start(BytesConsumer* /* consumer */, Client*) = 0; |  63   virtual void start(BytesConsumer* /* consumer */, Client*) = 0; | 
|  64  |  64  | 
|  65   virtual void cancel() = 0; |  65   virtual void cancel() = 0; | 
|  66  |  66  | 
|  67   DEFINE_INLINE_VIRTUAL_TRACE() {} |  67   DEFINE_INLINE_VIRTUAL_TRACE() {} | 
|  68 }; |  68 }; | 
|  69  |  69  | 
|  70 }  // namespace blink |  70 }  // namespace blink | 
|  71  |  71  | 
|  72 #endif  // FetchDataLoader_h |  72 #endif  // FetchDataLoader_h | 
| OLD | NEW |