| 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..834b8a22cac0e45211086571799fb237fb1ad38a
|
| --- /dev/null
|
| +++ b/content/browser/streams/stream.h
|
| @@ -0,0 +1,97 @@
|
| +// 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|
|
| + Stream(StreamRegistry* registry, const GURL& security_origin);
|
| +
|
| + 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 MarkComplete();
|
| +
|
| + // 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.
|
| + 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; }
|
| + GURL stream_url() { return stream_url_; }
|
| +
|
| + GURL& security_origin() { return security_origin_; }
|
| +
|
| + private:
|
| + friend class base::RefCountedThreadSafe<Stream>;
|
| +
|
| + // Notify observers if the stream is fully read.
|
| + void MaybeNotifyComplete();
|
| +
|
| + void SpaceAvailable();
|
| + void DataAvailable();
|
| +
|
| + ~Stream();
|
| +
|
| + size_t bytes_read_;
|
| + bool complete_;
|
| +
|
| + 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_
|
|
|