Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: content/browser/streams/stream.h

Issue 12335087: Implement the Stream registry in content (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Code review fixes Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "content/browser/download/byte_stream.h"
11 #include "googleurl/src/gurl.h"
12
13 namespace net {
14 class IOBuffer;
15 }
16
17 namespace content {
18
19 class StreamReadObserver;
20 class StreamRegistry;
21 class StreamWriteObserver;
22
23 // A stream that sends data from an arbitrary source to an internal URL
24 // that can be read by an internal consumer. It will continue to pull from the
25 // original URL as long as there is data available. It can be read from
26 // multiple clients, but results are undefined if more than one client reads at
27 // the same time. This allows a reader to consume part of the stream, then pass
28 // it along to another client to continue processing the stream.
kinuko 2013/03/07 09:35:12 Should we also update the comment?
Zachary Kuznia 2013/03/08 06:44:52 Done.
29 class Stream : public base::RefCountedThreadSafe<Stream> {
30 public:
31 enum StreamState {
32 STREAM_HAS_DATA,
33 STREAM_COMPLETE,
34 STREAM_EMPTY,
35 };
36
37 // Creates a stream useable from the |security_origin|.
38 Stream(StreamRegistry* registry,
39 StreamWriteObserver* write_observer,
40 const GURL& security_origin,
41 const GURL& url);
42
43 // Set the reader of this stream. Returns true on success, or false if there
44 // is already a reader.
kinuko 2013/03/07 09:41:23 It'd be nice to note that this doesn't exactly mat
Zachary Kuznia 2013/03/08 06:44:52 This shouldn't impact the behavior in the Stream s
45 bool SetReadObserver(StreamReadObserver* observer);
46
47 // Remove the read observer. |observer| must be the current observer.
48 void RemoveReadObserver(StreamReadObserver* observer);
49
50 // Adds the data in |buffer| to the stream. Takes ownership of |buffer|.
51 void AddData(scoped_refptr<net::IOBuffer> buffer, size_t size);
52
53 // Notifies this stream that it will not be receiving any more data.
54 void Finalize();
55
56 // Reads a maximum of |buf_size| from the stream into |buf|. Sets
57 // |*bytes_read| to the number of bytes actually read.
58 // Returns STREAM_HAS_DATA if data was read, STREAM_EMPTY if no data was read,
59 // and STREAM_COMPLETE if the stream is finalized and all data has been read.
kinuko 2013/03/07 09:35:12 Thanks, this looks much clearer.
60 StreamState ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read);
61
62 // Indicates whether there is space in the buffer to add more data.
63 bool can_add_data() const { return can_add_data_; }
64
65 const GURL& url() const { return url_; }
66
67 const GURL& security_origin() const { return security_origin_; }
68
69 private:
70 friend class base::RefCountedThreadSafe<Stream>;
71
72 ~Stream();
73
74 void OnSpaceAvailable();
75 void OnDataAvailable();
76
77 size_t bytes_read_;
78 bool can_add_data_;
79
80 GURL security_origin_;
81 GURL url_;
82
83 scoped_refptr<net::IOBuffer> data_;
84 size_t data_length_;
85
86 scoped_ptr<ByteStreamWriter> writer_;
87 scoped_ptr<ByteStreamReader> reader_;
88
89 StreamRegistry* registry_;
90 StreamReadObserver* read_observer_;
91 StreamWriteObserver* write_observer_;
92
93 DISALLOW_COPY_AND_ASSIGN(Stream);
94 };
95
96 } // namespace content
97
98 #endif // CONTENT_BROWSER_STREAMS_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698