Chromium Code Reviews| Index: content/browser/service_worker/service_worker_data_pipe_reader.h |
| diff --git a/content/browser/service_worker/service_worker_data_pipe_reader.h b/content/browser/service_worker/service_worker_data_pipe_reader.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2001fb59779125994ebe044892afc2ca4b7ae386 |
| --- /dev/null |
| +++ b/content/browser/service_worker/service_worker_data_pipe_reader.h |
| @@ -0,0 +1,75 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATA_PIPE_READER_H_ |
| +#define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATA_PIPE_READER_H_ |
| + |
| +#include "base/memory/ref_counted.h" |
| +#include "content/common/content_export.h" |
| +#include "mojo/public/cpp/bindings/binding.h" |
| +#include "mojo/public/cpp/system/data_pipe.h" |
| +#include "mojo/public/cpp/system/simple_watcher.h" |
| +#include "third_party/WebKit/public/platform/modules/serviceworker/service_worker_stream_handle.mojom.h" |
| + |
| +namespace net { |
| +class IOBuffer; |
| +} // namespace net |
| + |
| +namespace content { |
| + |
| +class ServiceWorkerURLRequestJob; |
| +class ServiceWorkerVersion; |
| + |
| +class CONTENT_EXPORT ServiceWorkerDataPipeReader |
| + : public blink::mojom::ServiceWorkerStreamCallback { |
| + public: |
| + ServiceWorkerDataPipeReader( |
| + ServiceWorkerURLRequestJob* owner, |
| + scoped_refptr<ServiceWorkerVersion> streaming_version, |
| + blink::mojom::ServiceWorkerStreamHandlePtr stream_handle); |
| + ~ServiceWorkerDataPipeReader() override; |
| + void Start(); |
| + |
| + // Copies the data provided from the service worker to |buf| up to |bus_size| |
| + // bytes. The returned value is the size actually copied to |buf|. It will be |
| + // net::OK when all data have received, and net::ERR_* when failure or pending |
| + // io. |
| + int ReadRawData(net::IOBuffer* buf, int buf_size); |
| + |
| + // Implements mojom::ServiceWorkerStreamCallback. |
| + void OnCompleted() override; |
| + void OnAborted() override; |
| + |
| + enum class State { STREAMING, COMPLETED, ABORTED }; |
|
kinuko
2017/04/13 02:22:27
state() getter is private, does this enum need to
shimazu
2017/04/18 01:50:04
Oops, it seems become public at some point by mist
|
| + |
| + private: |
| + // Callback method for |handle_watcher_|. |
| + void OnHandleGotSignal(MojoResult); |
| + |
| + // Finalizes the job. These must be called when state() is not |
| + // State::STREAMING. |
| + int SyncComplete(); |
| + void AsyncComplete(); |
| + |
| + State state(); |
| + |
| + ServiceWorkerURLRequestJob* owner_; |
| + scoped_refptr<ServiceWorkerVersion> streaming_version_; |
| + scoped_refptr<net::IOBuffer> stream_pending_buffer_; |
| + int stream_pending_buffer_size_ = 0; |
| + mojo::SimpleWatcher handle_watcher_; |
| + mojo::ScopedDataPipeConsumerHandle stream_; |
| + mojo::Binding<blink::mojom::ServiceWorkerStreamCallback> binding_; |
| + // State notified via ServiceWorkerStreamCallback. |producer_state_| is |
| + // STREAMING until OnCompleted or OnAborted is called. Note that |stream_| |
| + // might be closed even if |producer_state_| is STREAMING. In order to see the |
| + // state of ServiceWorkerDataPipeReader, use state() instead. |
| + State producer_state_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDataPipeReader); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATA_PIPE_READER_H_ |