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..16b530d34e9bc606e45121233f00be0cb85c782f | 
| --- /dev/null | 
| +++ b/content/browser/service_worker/service_worker_data_pipe_reader.h | 
| @@ -0,0 +1,63 @@ | 
| +// 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 "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 ServiceWorkerDataPipeReader | 
| 
 
horo
2017/04/06 05:22:09
Can you have unittests for this class?
 
shimazu
2017/04/07 08:52:29
Done.
 
 | 
| + : public blink::mojom::ServiceWorkerStreamCallback { | 
| + public: | 
| + ServiceWorkerDataPipeReader( | 
| + ServiceWorkerURLRequestJob* owner, | 
| + scoped_refptr<ServiceWorkerVersion> streaming_version, | 
| + blink::mojom::ServiceWorkerStreamHandlePtr stream_handle); | 
| + ~ServiceWorkerDataPipeReader() override; | 
| + void Start(); | 
| + void OnHandleGotReadable(MojoResult); | 
| 
 
horo
2017/04/06 05:22:09
private?
 
shimazu
2017/04/07 08:52:29
Done.
 
 | 
| + int ReadRawData(net::IOBuffer* buf, int buf_size); | 
| 
 
horo
2017/04/06 05:22:09
Please add comments about these methods.
 
shimazu
2017/04/07 08:52:29
Done.
 
 | 
| + | 
| + // Implements mojom::ServiceWorkerStreamCallback. | 
| + void OnCompleted() override; | 
| + void OnAborted() override; | 
| + | 
| + private: | 
| + enum class State { STREAMING, COMPLETED, ABORTED }; | 
| + | 
| + void MaybeComplete(); | 
| + void MaybeAbort(); | 
| 
 
horo
2017/04/06 05:22:09
Delete
 
shimazu
2017/04/07 08:52:29
Done.
 
 | 
| + | 
| + 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_; | 
| +}; | 
| + | 
| +} // namespace content | 
| + | 
| +#endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATA_PIPE_READER_H_ |