Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1523)

Unified Diff: content/browser/service_worker/service_worker_data_pipe_reader.h

Issue 2703343002: ServiceWorker: Use mojo's data pipe for respondWith(stream) (Closed)
Patch Set: Addressed falken's comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..acd32383aad90713ac1eccbafd466c6b1eae32af
--- /dev/null
+++ b/content/browser/service_worker/service_worker_data_pipe_reader.h
@@ -0,0 +1,78 @@
+// 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;
+
+// Reads a stream response for ServiceWorkerURLRequestJob passed through
+// Mojo's data pipe. Owned by ServiceWorkerURLRequestJob.
+class CONTENT_EXPORT ServiceWorkerDataPipeReader
+ : public blink::mojom::ServiceWorkerStreamCallback {
+ public:
+ ServiceWorkerDataPipeReader(
+ ServiceWorkerURLRequestJob* owner,
+ scoped_refptr<ServiceWorkerVersion> streaming_version,
+ blink::mojom::ServiceWorkerStreamHandlePtr stream_handle);
+ ~ServiceWorkerDataPipeReader() override;
+
+ // Starts reading the stream. owner_->OnResponseStarted will be called when
+ // the response starts.
falken 2017/04/19 06:56:52 IIUC, this synchronously calls OnResponseStarted n
shimazu 2017/04/19 08:32:16 Done.
+ void Start();
+
+ // Same as URLRequestJob::ReadRawData. If ERR_IO_PENDING is returned,
+ // owner_->OnReadRawDataComplete will be called when the read completes.
+ int ReadRawData(net::IOBuffer* buf, int buf_size);
+
+ // Implements mojom::ServiceWorkerStreamCallback.
+ void OnCompleted() override;
+ void OnAborted() override;
+
+ private:
+ 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.
+
+ // 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_;
+ 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_

Powered by Google App Engine
This is Rietveld 408576698