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

Side by Side 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: Make SWDataPipeReader::State private 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 unified diff | Download patch
OLDNEW
(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
falken 2017/04/18 05:05:33 nit: add a class-level comment like ServiceWorkerS
shimazu 2017/04/19 05:49:46 Done.
24 class CONTENT_EXPORT ServiceWorkerDataPipeReader
25 : public blink::mojom::ServiceWorkerStreamCallback {
26 public:
27 ServiceWorkerDataPipeReader(
28 ServiceWorkerURLRequestJob* owner,
29 scoped_refptr<ServiceWorkerVersion> streaming_version,
30 blink::mojom::ServiceWorkerStreamHandlePtr stream_handle);
31 ~ServiceWorkerDataPipeReader() override;
32 void Start();
falken 2017/04/18 05:05:33 Can you document it calls owner_->OnResponseStarte
shimazu 2017/04/19 05:49:46 Done.
33
34 // Copies the data provided from the service worker to |buf| up to |bus_size|
falken 2017/04/18 05:05:33 nit: buf_size
shimazu 2017/04/19 05:49:46 Done.
35 // bytes. The returned value is the size actually copied to |buf|. It will be
36 // net::OK when all data have received, and net::ERR_* when failure or pending
37 // io.
falken 2017/04/18 05:05:33 It's kind of vague to group failure and pending IO
shimazu 2017/04/19 05:49:46 Done.
38 int ReadRawData(net::IOBuffer* buf, int buf_size);
39
40 // Implements mojom::ServiceWorkerStreamCallback.
41 void OnCompleted() override;
42 void OnAborted() override;
43
44 private:
45 enum class State { STREAMING, COMPLETED, ABORTED };
46
47 // Callback method for |handle_watcher_|.
48 void OnHandleGotSignal(MojoResult);
49
50 // Finalizes the job. These must be called when state() is not
51 // State::STREAMING.
52 int SyncComplete();
53 void AsyncComplete();
54
55 State state();
56
57 ServiceWorkerURLRequestJob* owner_;
58 scoped_refptr<ServiceWorkerVersion> streaming_version_;
59 scoped_refptr<net::IOBuffer> stream_pending_buffer_;
60 int stream_pending_buffer_size_ = 0;
61 mojo::SimpleWatcher handle_watcher_;
62 mojo::ScopedDataPipeConsumerHandle stream_;
63 mojo::Binding<blink::mojom::ServiceWorkerStreamCallback> binding_;
64 // State notified via ServiceWorkerStreamCallback. |producer_state_| is
65 // STREAMING until OnCompleted or OnAborted is called. Note that |stream_|
66 // might be closed even if |producer_state_| is STREAMING. In order to see the
67 // state of ServiceWorkerDataPipeReader, use state() instead.
68 State producer_state_;
falken 2017/04/18 05:05:33 nit: initialize both |buffer_size_| and |producer_
shimazu 2017/04/19 05:49:46 Done.
69
70 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDataPipeReader);
71 };
72
73 } // namespace content
74
75 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATA_PIPE_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698