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

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

Issue 12212031: Add support for redirecting ResourceHandlers to a blob: URL (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Code review fixes Created 7 years, 10 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
« no previous file with comments | « content/browser/storage_partition_impl_map.cc ('k') | content/browser/streams/stream.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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|
35 Stream(StreamRegistry* registry, const GURL& security_origin);
36
37 void AddReadObserver(StreamReadObserver* observer);
38 void RemoveReadObserver(StreamReadObserver* observer);
39
40 void AddWriteObserver(StreamWriteObserver* observer);
41 void RemoveWriteObserver(StreamWriteObserver* observer);
42
43 // Add the data in |buffer| to the stream. Takes ownership of |buffer|
44 void AddData(scoped_refptr<net::IOBuffer> buffer, size_t size);
45
46 // Indicate that this stream will not be receiving any more data.
47 void MarkComplete();
48
49 // Read a maximum of |buf_size| from the stream into |buf|. Sets
50 // |*bytes_read| to the number of bytes actually read.
51 // returns false if there is no data available, but the stream is not closed.
52 bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read);
53
54 // Indicates whether there is space in the buffer to add more data.
55 bool can_add_data() const { return can_add_data_; }
56
57 void SetStreamUrl(GURL url) { stream_url_ = url; }
58 GURL stream_url() { return stream_url_; }
59
60 GURL& security_origin() { return security_origin_; }
61
62 private:
63 friend class base::RefCountedThreadSafe<Stream>;
64
65 // Notify observers if the stream is fully read.
66 void MaybeNotifyComplete();
67
68 void SpaceAvailable();
69 void DataAvailable();
70
71 ~Stream();
72
73 size_t bytes_read_;
74 bool complete_;
75
76 bool can_add_data_;
77
78 GURL security_origin_;
79
80 GURL stream_url_;
81
82 scoped_refptr<net::IOBuffer> data_;
83 size_t data_length_;
84
85 scoped_ptr<ByteStreamWriter> writer_;
86 scoped_ptr<ByteStreamReader> reader_;
87
88 StreamRegistry* registry_;
89 ObserverList<StreamReadObserver> read_observers_;
90 ObserverList<StreamWriteObserver> write_observers_;
91
92 DISALLOW_COPY_AND_ASSIGN(Stream);
93 };
94
95 } // namespace content
96
97 #endif // CONTENT_BROWSER_STREAMS_STREAM_H_
OLDNEW
« no previous file with comments | « content/browser/storage_partition_impl_map.cc ('k') | content/browser/streams/stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698