Chromium Code Reviews| 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..6f0e706a680da93b2732f5e16163aca1bebc79b5 |
| --- /dev/null |
| +++ b/content/browser/streams/stream.h |
| @@ -0,0 +1,94 @@ |
| +// 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 |
|
darin (slow to review)
2013/02/27 06:18:59
nit: probably best not to mention ResourceHandler
Zachary Kuznia
2013/02/27 07:36:56
Changed to arbitrary source.
|
| +// 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 |
|
darin (slow to review)
2013/02/27 06:18:59
nit: "from from"
Zachary Kuznia
2013/02/27 07:36:56
Done.
|
| +// 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: |
| + // Creates a stream useable from the |security_origin|. |
| + Stream(StreamRegistry* registry, |
| + const GURL& security_origin, |
| + const GURL& url); |
| + |
| + void AddReadObserver(StreamReadObserver* observer); |
| + void RemoveReadObserver(StreamReadObserver* observer); |
| + |
| + void AddWriteObserver(StreamWriteObserver* observer); |
| + void RemoveWriteObserver(StreamWriteObserver* observer); |
| + |
| + // Adds the data in |buffer| to the stream. Takes ownership of |buffer|. |
| + void AddData(scoped_refptr<net::IOBuffer> buffer, size_t size); |
| + |
| + // Notifies this stream that it will not be receiving any more data. |
| + void Finalize(); |
| + |
| + // Reads 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 |
| + // finalized, and true otherwise. |
| + 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(const GURL& url) { stream_url_ = url; } |
|
darin (slow to review)
2013/02/27 06:18:59
nit: set_stream_url
actually, since the class nam
Zachary Kuznia
2013/02/27 07:36:56
Done.
|
| + const GURL& stream_url() { return stream_url_; } |
|
darin (slow to review)
2013/02/27 06:18:59
nit: getters probably should be 'const' methods
Zachary Kuznia
2013/02/27 07:36:56
Done.
|
| + |
| + const GURL& security_origin() { return security_origin_; } |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<Stream>; |
| + |
| + ~Stream(); |
| + |
| + void OnSpaceAvailable(); |
| + void OnDataAvailable(); |
| + |
| + 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_ |