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

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 <deque>
kinuko 2013/03/07 08:35:40 not used?
Zachary Kuznia 2013/03/07 09:19:00 Done.
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"
darin (slow to review) 2013/03/07 07:54:03 nit: There should probably be a TODO to factor byt
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 arbitrary source to an internal URL
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
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
kinuko 2013/03/07 08:35:40 nit: returns -> Returns
Zachary Kuznia 2013/03/07 09:19:00 Done.
54 // finalized, and true otherwise.
kinuko 2013/03/07 08:35:40 This behavior still confuses me a bit. So we retu
Zachary Kuznia 2013/03/07 09:19:00 Changed to return an enum that matches ByteStream.
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 SetUrl(const GURL& url) { url_ = url; }
kinuko 2013/03/07 08:35:40 nit: set_url() should be fine for simple inline se
Zachary Kuznia 2013/03/07 09:19:00 Removed.
61 const GURL& url() const { return url_; }
62
63 const GURL& security_origin() const { 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 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_;
kinuko 2013/03/07 08:35:40 This one's ref-counted while StreamRegistry is not
Zachary Kuznia 2013/03/07 09:19:00 There should not be such a case. Other Stream ref
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698