Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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_LOADER_STREAM_WRITER_H_ | |
| 6 #define CONTENT_BROWSER_LOADER_STREAM_WRITER_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "content/browser/streams/stream_write_observer.h" | |
| 11 | |
| 12 class GURL; | |
| 13 | |
| 14 namespace net { | |
| 15 class IOBuffer; | |
| 16 } | |
| 17 | |
| 18 namespace content { | |
| 19 | |
| 20 class ResourceController; | |
| 21 class Stream; | |
| 22 class StreamRegistry; | |
| 23 | |
| 24 // StreamWriter is a helper class for ResourceHandlers which route their output | |
| 25 // into a Stream. It manages an internal buffer and handles back-pressure from | |
| 26 // the Stream's reader. | |
| 27 class StreamWriter : public StreamWriteObserver { | |
|
mmenke
2014/10/15 20:05:44
Hrm... This naming is really unfortunate. Sounds
| |
| 28 public: | |
| 29 // Creates a new StreamWriter without an initialized Stream or controller. The | |
| 30 // controller must be set before the writer is used. | |
| 31 StreamWriter(); | |
| 32 virtual ~StreamWriter(); | |
| 33 | |
| 34 Stream* stream() { return stream_.get(); } | |
| 35 | |
| 36 void set_controller(ResourceController* controller) { | |
| 37 controller_ = controller; | |
| 38 } | |
| 39 | |
| 40 // Initializes the writer with a new Stream in |registry|. |origin| will be | |
| 41 // used to construct the URL for the Stream. See WebCore::BlobURL and and | |
| 42 // WebCore::SecurityOrigin in Blink to understand how origin check is done on | |
| 43 // resource loading. | |
| 44 void InitializeStream(StreamRegistry* registry, | |
| 45 const GURL& origin); | |
|
mmenke
2014/10/15 20:05:44
nit: Do these fit on one line?
| |
| 46 | |
| 47 // Prepares a buffer to read data from the request. This call will be followed | |
| 48 // by either OnReadCompleted (on successful read or EOF) or destruction. The | |
| 49 // buffer may not be recycled until OnReadCompleted is called. If |min_size| | |
| 50 // is not -1, it is the minimum size of the returned buffer. | |
| 51 // | |
| 52 // OnWillRead may be called before the stream is initialized. This is to | |
| 53 // support BufferedResourceHandler which reads the initial chunk of data | |
| 54 // early. | |
| 55 void OnWillRead(scoped_refptr<net::IOBuffer>* buf, | |
| 56 int* buf_size, | |
| 57 int min_size); | |
| 58 | |
| 59 // A read was completed, forward the data to the Stream. If |*defer| is set to | |
| 60 // true, the implementation must not continue to process the request until | |
| 61 // Resume is called on |controller_|. | |
| 62 // | |
| 63 // InitializeStream must have been called before calling OnReadCompleted. | |
| 64 void OnReadCompleted(int bytes_read, bool* defer); | |
| 65 | |
| 66 // Called when there is no more data to read to the stream. | |
| 67 void Finalize(); | |
| 68 | |
| 69 private: | |
| 70 // StreamWriteObserver implementation. | |
| 71 virtual void OnSpaceAvailable(Stream* stream) override; | |
| 72 virtual void OnClose(Stream* stream) override; | |
|
mmenke
2014/10/15 20:05:44
I think the new hotness is to use override without
| |
| 73 | |
| 74 ResourceController* controller_; | |
| 75 scoped_refptr<Stream> stream_; | |
| 76 scoped_refptr<net::IOBuffer> read_buffer_; | |
| 77 | |
| 78 DISALLOW_COPY_AND_ASSIGN(StreamWriter); | |
| 79 }; | |
| 80 | |
| 81 } // namespace content | |
| 82 | |
| 83 #endif // CONTENT_BROWSER_LOADER_STREAM_WRITER_H_ | |
| OLD | NEW |