OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_BROWSER_STREAMS_STREAM_H_ | |
6 #define CONTENT_BROWSER_STREAMS_STREAM_H_ | |
7 | |
8 #include <deque> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/observer_list.h" | |
13 #include "content/browser/download/byte_stream.h" | |
14 #include "googleurl/src/gurl.h" | |
15 | |
16 namespace net { | |
17 class IOBuffer; | |
18 } | |
19 | |
20 namespace content { | |
21 | |
22 class StreamReadObserver; | |
23 class StreamRegistry; | |
24 class StreamWriteObserver; | |
25 | |
26 // 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.
| |
27 // that can be read by an internal consumer. It will continue to pull from the | |
28 // 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.
| |
29 // multiple clients, but results are undefined if more than one client reads at | |
30 // the same time. This allows a reader to consume part of the stream, then pass | |
31 // it along to another client to continue processing the stream. | |
32 class Stream : public base::RefCountedThreadSafe<Stream> { | |
33 public: | |
34 // Creates a stream useable from the |security_origin|. | |
35 Stream(StreamRegistry* registry, | |
36 const GURL& security_origin, | |
37 const GURL& url); | |
38 | |
39 void AddReadObserver(StreamReadObserver* observer); | |
40 void RemoveReadObserver(StreamReadObserver* observer); | |
41 | |
42 void AddWriteObserver(StreamWriteObserver* observer); | |
43 void RemoveWriteObserver(StreamWriteObserver* observer); | |
44 | |
45 // Adds the data in |buffer| to the stream. Takes ownership of |buffer|. | |
46 void AddData(scoped_refptr<net::IOBuffer> buffer, size_t size); | |
47 | |
48 // Notifies this stream that it will not be receiving any more data. | |
49 void Finalize(); | |
50 | |
51 // Reads a maximum of |buf_size| from the stream into |buf|. Sets | |
52 // |*bytes_read| to the number of bytes actually read. | |
53 // returns false if there is no data available, but the stream is not | |
54 // finalized, and true otherwise. | |
55 bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read); | |
56 | |
57 // Indicates whether there is space in the buffer to add more data. | |
58 bool can_add_data() const { return can_add_data_; } | |
59 | |
60 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.
| |
61 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.
| |
62 | |
63 const GURL& security_origin() { return security_origin_; } | |
64 | |
65 private: | |
66 friend class base::RefCountedThreadSafe<Stream>; | |
67 | |
68 ~Stream(); | |
69 | |
70 void OnSpaceAvailable(); | |
71 void OnDataAvailable(); | |
72 | |
73 size_t bytes_read_; | |
74 bool can_add_data_; | |
75 | |
76 GURL security_origin_; | |
77 GURL stream_url_; | |
78 | |
79 scoped_refptr<net::IOBuffer> data_; | |
80 size_t data_length_; | |
81 | |
82 scoped_ptr<ByteStreamWriter> writer_; | |
83 scoped_ptr<ByteStreamReader> reader_; | |
84 | |
85 StreamRegistry* registry_; | |
86 ObserverList<StreamReadObserver> read_observers_; | |
87 ObserverList<StreamWriteObserver> write_observers_; | |
88 | |
89 DISALLOW_COPY_AND_ASSIGN(Stream); | |
90 }; | |
91 | |
92 } // namespace content | |
93 | |
94 #endif // CONTENT_BROWSER_STREAMS_STREAM_H_ | |
OLD | NEW |