Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATA_PIPE_READER_H_ | |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATA_PIPE_READER_H_ | |
| 7 | |
| 8 #include "base/memory/ref_counted.h" | |
| 9 #include "content/common/content_export.h" | |
| 10 #include "mojo/public/cpp/bindings/binding.h" | |
| 11 #include "mojo/public/cpp/system/data_pipe.h" | |
| 12 #include "mojo/public/cpp/system/simple_watcher.h" | |
| 13 #include "third_party/WebKit/public/platform/modules/serviceworker/service_worke r_stream_handle.mojom.h" | |
| 14 | |
| 15 namespace net { | |
| 16 class IOBuffer; | |
| 17 } // namespace net | |
| 18 | |
| 19 namespace content { | |
| 20 | |
| 21 class ServiceWorkerURLRequestJob; | |
| 22 class ServiceWorkerVersion; | |
| 23 | |
| 24 // Reads a stream response for ServiceWorkerURLRequestJob passed through | |
| 25 // Mojo's data pipe. Owned by ServiceWorkerURLRequestJob. | |
| 26 class CONTENT_EXPORT ServiceWorkerDataPipeReader | |
| 27 : public blink::mojom::ServiceWorkerStreamCallback { | |
| 28 public: | |
| 29 ServiceWorkerDataPipeReader( | |
| 30 ServiceWorkerURLRequestJob* owner, | |
| 31 scoped_refptr<ServiceWorkerVersion> streaming_version, | |
| 32 blink::mojom::ServiceWorkerStreamHandlePtr stream_handle); | |
| 33 ~ServiceWorkerDataPipeReader() override; | |
| 34 | |
| 35 // Starts reading the stream. owner_->OnResponseStarted will be called when | |
| 36 // the response starts. | |
|
falken
2017/04/19 06:56:52
IIUC, this synchronously calls OnResponseStarted n
shimazu
2017/04/19 08:32:16
Done.
| |
| 37 void Start(); | |
| 38 | |
| 39 // Same as URLRequestJob::ReadRawData. If ERR_IO_PENDING is returned, | |
| 40 // owner_->OnReadRawDataComplete will be called when the read completes. | |
| 41 int ReadRawData(net::IOBuffer* buf, int buf_size); | |
| 42 | |
| 43 // Implements mojom::ServiceWorkerStreamCallback. | |
| 44 void OnCompleted() override; | |
| 45 void OnAborted() override; | |
| 46 | |
| 47 private: | |
| 48 enum class State { STREAMING, COMPLETED, ABORTED }; | |
|
kinuko
2017/04/19 09:17:47
nit: kStreaming, kCompleted, kAborted ? (context:
shimazu
2017/04/20 04:20:41
Done.
| |
| 49 | |
| 50 // Callback method for |handle_watcher_|. | |
| 51 void OnHandleGotSignal(MojoResult); | |
| 52 | |
| 53 // Finalizes the job. These must be called when state() is not | |
| 54 // State::STREAMING. | |
| 55 int SyncComplete(); | |
| 56 void AsyncComplete(); | |
| 57 | |
| 58 State state(); | |
| 59 | |
| 60 ServiceWorkerURLRequestJob* owner_; | |
| 61 scoped_refptr<ServiceWorkerVersion> streaming_version_; | |
| 62 scoped_refptr<net::IOBuffer> stream_pending_buffer_; | |
| 63 int stream_pending_buffer_size_; | |
| 64 mojo::SimpleWatcher handle_watcher_; | |
| 65 mojo::ScopedDataPipeConsumerHandle stream_; | |
| 66 mojo::Binding<blink::mojom::ServiceWorkerStreamCallback> binding_; | |
| 67 // State notified via ServiceWorkerStreamCallback. |producer_state_| is | |
| 68 // STREAMING until OnCompleted or OnAborted is called. Note that |stream_| | |
| 69 // might be closed even if |producer_state_| is STREAMING. In order to see the | |
| 70 // state of ServiceWorkerDataPipeReader, use state() instead. | |
| 71 State producer_state_; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDataPipeReader); | |
| 74 }; | |
| 75 | |
| 76 } // namespace content | |
| 77 | |
| 78 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATA_PIPE_READER_H_ | |
| OLD | NEW |