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

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: 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>
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
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
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 // Create a stream useable from the |security_origin|
kinuko 2013/02/26 07:37:55 style-nit: Create -> Creates, end comment with '.'
Zachary Kuznia 2013/02/26 08:30:03 Done.
35 Stream(StreamRegistry* registry, const GURL& security_origin,
36 const GURL& url);
kinuko 2013/02/26 07:37:55 style-nit: can you break the line after 'registry,
Zachary Kuznia 2013/02/26 08:30:03 Done.
37
38 void AddReadObserver(StreamReadObserver* observer);
39 void RemoveReadObserver(StreamReadObserver* observer);
40
41 void AddWriteObserver(StreamWriteObserver* observer);
42 void RemoveWriteObserver(StreamWriteObserver* observer);
43
44 // Add the data in |buffer| to the stream. Takes ownership of |buffer|
45 void AddData(scoped_refptr<net::IOBuffer> buffer, size_t size);
46
47 // Indicate that this stream will not be receiving any more data.
48 void Finalize();
49
50 // Read a maximum of |buf_size| from the stream into |buf|. Sets
51 // |*bytes_read| to the number of bytes actually read.
52 // returns false if there is no data available, but the stream is not closed.
kinuko 2013/02/26 07:37:55 What is returned when the stream is closed?
Zachary Kuznia 2013/02/26 08:30:03 Improved the comment.
53 bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read);
54
55 // Indicates whether there is space in the buffer to add more data.
56 bool can_add_data() const { return can_add_data_; }
57
58 void SetStreamUrl(GURL url) { stream_url_ = url; }
kinuko 2013/02/26 07:37:55 nit: const GURL&
Zachary Kuznia 2013/02/26 08:30:03 Done.
59 GURL stream_url() { return stream_url_; }
kinuko 2013/02/26 07:37:55 could return const GURL& as well?
Zachary Kuznia 2013/02/26 08:30:03 Done.
60
61 GURL& security_origin() { return security_origin_; }
kinuko 2013/02/26 07:37:55 GURL& -> const GURL&
Zachary Kuznia 2013/02/26 08:30:03 Done.
62
63 private:
64 friend class base::RefCountedThreadSafe<Stream>;
65
66 void SpaceAvailable();
67 void DataAvailable();
68
69 ~Stream();
kinuko 2013/02/26 07:37:55 virtual style-nit: can we move this after line 64
Zachary Kuznia 2013/02/26 08:30:03 Done.
70
71 size_t bytes_read_;
72 bool can_add_data_;
73
74 GURL security_origin_;
75 GURL stream_url_;
76
77 scoped_refptr<net::IOBuffer> data_;
78 size_t data_length_;
79
80 scoped_ptr<ByteStreamWriter> writer_;
81 scoped_ptr<ByteStreamReader> reader_;
82
83 StreamRegistry* registry_;
84 ObserverList<StreamReadObserver> read_observers_;
85 ObserverList<StreamWriteObserver> write_observers_;
86
87 DISALLOW_COPY_AND_ASSIGN(Stream);
88 };
89
90 } // namespace content
91
92 #endif // CONTENT_BROWSER_STREAMS_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698