Index: content/browser/streams/stream.h |
diff --git a/content/browser/streams/stream.h b/content/browser/streams/stream.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..97587ed7a5e6196233e3b0f0fb58d6cbbdb66337 |
--- /dev/null |
+++ b/content/browser/streams/stream.h |
@@ -0,0 +1,92 @@ |
+// Copyright (c) 2013 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_STREAMS_STREAM_H_ |
+#define CONTENT_BROWSER_STREAMS_STREAM_H_ |
+ |
+#include <deque> |
+ |
+#include "base/basictypes.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/observer_list.h" |
+#include "content/browser/download/byte_stream.h" |
+#include "googleurl/src/gurl.h" |
+ |
+namespace net { |
+class IOBuffer; |
+} |
+ |
+namespace content { |
+ |
+class StreamReadObserver; |
+class StreamRegistry; |
+class StreamWriteObserver; |
+ |
+// A stream that sends data from an existing ResourceHandler to an internal URL |
+// that can be read by an internal consumer. It will continue to pull from the |
+// original URL as long as there is data available. It can be read from from |
+// multiple clients, but results are undefined if more than one client reads at |
+// the same time. This allows a reader to consume part of the stream, then pass |
+// it along to another client to continue processing the stream. |
+class Stream : public base::RefCountedThreadSafe<Stream> { |
+ public: |
+ // Create a stream useable from the |security_origin| |
kinuko
2013/02/26 07:37:55
style-nit: Create -> Creates, end comment with '.'
Zachary Kuznia
2013/02/26 08:30:03
Done.
|
+ Stream(StreamRegistry* registry, const GURL& security_origin, |
+ const GURL& url); |
kinuko
2013/02/26 07:37:55
style-nit: can you break the line after 'registry,
Zachary Kuznia
2013/02/26 08:30:03
Done.
|
+ |
+ void AddReadObserver(StreamReadObserver* observer); |
+ void RemoveReadObserver(StreamReadObserver* observer); |
+ |
+ void AddWriteObserver(StreamWriteObserver* observer); |
+ void RemoveWriteObserver(StreamWriteObserver* observer); |
+ |
+ // Add the data in |buffer| to the stream. Takes ownership of |buffer| |
+ void AddData(scoped_refptr<net::IOBuffer> buffer, size_t size); |
+ |
+ // Indicate that this stream will not be receiving any more data. |
+ void Finalize(); |
+ |
+ // Read a maximum of |buf_size| from the stream into |buf|. Sets |
+ // |*bytes_read| to the number of bytes actually read. |
+ // returns false if there is no data available, but the stream is not closed. |
kinuko
2013/02/26 07:37:55
What is returned when the stream is closed?
Zachary Kuznia
2013/02/26 08:30:03
Improved the comment.
|
+ bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read); |
+ |
+ // Indicates whether there is space in the buffer to add more data. |
+ bool can_add_data() const { return can_add_data_; } |
+ |
+ void SetStreamUrl(GURL url) { stream_url_ = url; } |
kinuko
2013/02/26 07:37:55
nit: const GURL&
Zachary Kuznia
2013/02/26 08:30:03
Done.
|
+ GURL stream_url() { return stream_url_; } |
kinuko
2013/02/26 07:37:55
could return const GURL& as well?
Zachary Kuznia
2013/02/26 08:30:03
Done.
|
+ |
+ GURL& security_origin() { return security_origin_; } |
kinuko
2013/02/26 07:37:55
GURL& -> const GURL&
Zachary Kuznia
2013/02/26 08:30:03
Done.
|
+ |
+ private: |
+ friend class base::RefCountedThreadSafe<Stream>; |
+ |
+ void SpaceAvailable(); |
+ void DataAvailable(); |
+ |
+ ~Stream(); |
kinuko
2013/02/26 07:37:55
virtual
style-nit: can we move this after line 64
Zachary Kuznia
2013/02/26 08:30:03
Done.
|
+ |
+ size_t bytes_read_; |
+ bool can_add_data_; |
+ |
+ GURL security_origin_; |
+ GURL stream_url_; |
+ |
+ scoped_refptr<net::IOBuffer> data_; |
+ size_t data_length_; |
+ |
+ scoped_ptr<ByteStreamWriter> writer_; |
+ scoped_ptr<ByteStreamReader> reader_; |
+ |
+ StreamRegistry* registry_; |
+ ObserverList<StreamReadObserver> read_observers_; |
+ ObserverList<StreamWriteObserver> write_observers_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(Stream); |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_BROWSER_STREAMS_STREAM_H_ |