| 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. Calls owner_->OnResponseStarted. |
| 36 void Start(); |
| 37 |
| 38 // Same as URLRequestJob::ReadRawData. If ERR_IO_PENDING is returned, |
| 39 // owner_->OnReadRawDataComplete will be called when the read completes. |
| 40 int ReadRawData(net::IOBuffer* buf, int buf_size); |
| 41 |
| 42 // Implements mojom::ServiceWorkerStreamCallback. |
| 43 void OnCompleted() override; |
| 44 void OnAborted() override; |
| 45 |
| 46 private: |
| 47 enum class State { kStreaming, kCompleted, kAborted }; |
| 48 |
| 49 // Callback method for |handle_watcher_|. |
| 50 void OnHandleGotSignal(MojoResult); |
| 51 |
| 52 // Finalizes the job. These must be called when state() is not |
| 53 // State::STREAMING. |
| 54 int SyncComplete(); |
| 55 void AsyncComplete(); |
| 56 |
| 57 State state(); |
| 58 |
| 59 ServiceWorkerURLRequestJob* owner_; |
| 60 scoped_refptr<ServiceWorkerVersion> streaming_version_; |
| 61 scoped_refptr<net::IOBuffer> stream_pending_buffer_; |
| 62 int stream_pending_buffer_size_; |
| 63 mojo::SimpleWatcher handle_watcher_; |
| 64 mojo::ScopedDataPipeConsumerHandle stream_; |
| 65 mojo::Binding<blink::mojom::ServiceWorkerStreamCallback> binding_; |
| 66 // State notified via ServiceWorkerStreamCallback. |producer_state_| is |
| 67 // STREAMING until OnCompleted or OnAborted is called. Note that |stream_| |
| 68 // might be closed even if |producer_state_| is STREAMING. In order to see the |
| 69 // state of ServiceWorkerDataPipeReader, use state() instead. |
| 70 State producer_state_; |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDataPipeReader); |
| 73 }; |
| 74 |
| 75 } // namespace content |
| 76 |
| 77 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATA_PIPE_READER_H_ |
| OLD | NEW |