OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_STREAMS_STREAM_H_ | 5 #ifndef CONTENT_BROWSER_STREAMS_STREAM_H_ |
6 #define CONTENT_BROWSER_STREAMS_STREAM_H_ | 6 #define CONTENT_BROWSER_STREAMS_STREAM_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "content/browser/download/byte_stream.h" | 11 #include "content/browser/download/byte_stream.h" |
12 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
14 | 14 |
15 namespace net { | 15 namespace net { |
16 class IOBuffer; | 16 class IOBuffer; |
17 } | 17 } |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 | 20 |
| 21 class StreamHandle; |
| 22 class StreamHandleImpl; |
21 class StreamReadObserver; | 23 class StreamReadObserver; |
22 class StreamRegistry; | 24 class StreamRegistry; |
23 class StreamWriteObserver; | 25 class StreamWriteObserver; |
24 | 26 |
25 // A stream that sends data from an arbitrary source to an internal URL | 27 // A stream that sends data from an arbitrary source to an internal URL |
26 // that can be read by an internal consumer. It will continue to pull from the | 28 // that can be read by an internal consumer. It will continue to pull from the |
27 // original URL as long as there is data available. It can be read from | 29 // original URL as long as there is data available. It can be read from |
28 // multiple clients, but only one can be reading at a time. This allows a | 30 // multiple clients, but only one can be reading at a time. This allows a |
29 // reader to consume part of the stream, then pass it along to another client | 31 // reader to consume part of the stream, then pass it along to another client |
30 // to continue processing the stream. | 32 // to continue processing the stream. |
(...skipping 11 matching lines...) Expand all Loading... |
42 const GURL& security_origin, | 44 const GURL& security_origin, |
43 const GURL& url); | 45 const GURL& url); |
44 | 46 |
45 // Sets the reader of this stream. Returns true on success, or false if there | 47 // Sets the reader of this stream. Returns true on success, or false if there |
46 // is already a reader. | 48 // is already a reader. |
47 bool SetReadObserver(StreamReadObserver* observer); | 49 bool SetReadObserver(StreamReadObserver* observer); |
48 | 50 |
49 // Removes the read observer. |observer| must be the current observer. | 51 // Removes the read observer. |observer| must be the current observer. |
50 void RemoveReadObserver(StreamReadObserver* observer); | 52 void RemoveReadObserver(StreamReadObserver* observer); |
51 | 53 |
| 54 // Removes the write observer. |observer| must be the current observer. |
| 55 void RemoveWriteObserver(StreamWriteObserver* observer); |
| 56 |
52 // Adds the data in |buffer| to the stream. Takes ownership of |buffer|. | 57 // Adds the data in |buffer| to the stream. Takes ownership of |buffer|. |
53 void AddData(scoped_refptr<net::IOBuffer> buffer, size_t size); | 58 void AddData(scoped_refptr<net::IOBuffer> buffer, size_t size); |
54 | 59 |
55 // Notifies this stream that it will not be receiving any more data. | 60 // Notifies this stream that it will not be receiving any more data. |
56 void Finalize(); | 61 void Finalize(); |
57 | 62 |
58 // Reads a maximum of |buf_size| from the stream into |buf|. Sets | 63 // Reads a maximum of |buf_size| from the stream into |buf|. Sets |
59 // |*bytes_read| to the number of bytes actually read. | 64 // |*bytes_read| to the number of bytes actually read. |
60 // Returns STREAM_HAS_DATA if data was read, STREAM_EMPTY if no data was read, | 65 // Returns STREAM_HAS_DATA if data was read, STREAM_EMPTY if no data was read, |
61 // and STREAM_COMPLETE if the stream is finalized and all data has been read. | 66 // and STREAM_COMPLETE if the stream is finalized and all data has been read. |
62 StreamState ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read); | 67 StreamState ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read); |
63 | 68 |
| 69 scoped_ptr<StreamHandle> CreateHandle(); |
| 70 void CloseHandle(); |
| 71 |
64 // Indicates whether there is space in the buffer to add more data. | 72 // Indicates whether there is space in the buffer to add more data. |
65 bool can_add_data() const { return can_add_data_; } | 73 bool can_add_data() const { return can_add_data_; } |
66 | 74 |
67 const GURL& url() const { return url_; } | 75 const GURL& url() const { return url_; } |
68 | 76 |
69 const GURL& security_origin() const { return security_origin_; } | 77 const GURL& security_origin() const { return security_origin_; } |
70 | 78 |
71 private: | 79 private: |
72 friend class base::RefCountedThreadSafe<Stream>; | 80 friend class base::RefCountedThreadSafe<Stream>; |
73 | 81 |
(...skipping 11 matching lines...) Expand all Loading... |
85 scoped_refptr<net::IOBuffer> data_; | 93 scoped_refptr<net::IOBuffer> data_; |
86 size_t data_length_; | 94 size_t data_length_; |
87 | 95 |
88 scoped_ptr<ByteStreamWriter> writer_; | 96 scoped_ptr<ByteStreamWriter> writer_; |
89 scoped_ptr<ByteStreamReader> reader_; | 97 scoped_ptr<ByteStreamReader> reader_; |
90 | 98 |
91 StreamRegistry* registry_; | 99 StreamRegistry* registry_; |
92 StreamReadObserver* read_observer_; | 100 StreamReadObserver* read_observer_; |
93 StreamWriteObserver* write_observer_; | 101 StreamWriteObserver* write_observer_; |
94 | 102 |
| 103 StreamHandleImpl* stream_handle_; |
| 104 |
95 base::WeakPtrFactory<Stream> weak_ptr_factory_; | 105 base::WeakPtrFactory<Stream> weak_ptr_factory_; |
96 DISALLOW_COPY_AND_ASSIGN(Stream); | 106 DISALLOW_COPY_AND_ASSIGN(Stream); |
97 }; | 107 }; |
98 | 108 |
99 } // namespace content | 109 } // namespace content |
100 | 110 |
101 #endif // CONTENT_BROWSER_STREAMS_STREAM_H_ | 111 #endif // CONTENT_BROWSER_STREAMS_STREAM_H_ |
OLD | NEW |