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

Side by Side Diff: content/browser/streams/chrome_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: Rebase 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
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_CHROME_STREAM_H_
6 #define CONTENT_BROWSER_STREAMS_CHROME_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 "googleurl/src/gurl.h"
14
15 namespace net {
16 class IOBuffer;
17 }
18
19 namespace content {
20
21 class ChromeStream;
22
23 class ChromeStreamObserver {
darin (slow to review) 2013/02/13 09:18:12 nit: We don't usually name classes with a Chrome*
Zachary Kuznia 2013/02/13 16:37:14 Done.
24 public:
25 // Sent when there is data available to be read from the stream.
26 virtual void OnDataAvailable(ChromeStream* stream) = 0;
27
28 // Sent when the stream has been fully read, and will not be recieving more
29 // data.
30 virtual void OnStreamComplete(ChromeStream* stream) = 0;
31
32 // Sent when space becomes available in the stream, and the source should
33 // resume reading.
34 virtual void OnBufferAvailable(ChromeStream* stream) = 0;
35
36 protected:
37 virtual ~ChromeStreamObserver() {}
38 };
39
40 // A stream that sends data from an existing ResourceHandler to an internal URL
41 // that can be read by an internal consumer.
42 class ChromeStream
43 : public base::RefCountedThreadSafe<ChromeStream> {
44 public:
45 // Create a stream useable from the |security_origin|
46 ChromeStream(const GURL& security_origin);
47
48 void AddObserver(ChromeStreamObserver* observer);
darin (slow to review) 2013/02/13 09:18:12 It seems like the observer interface is used both
Zachary Kuznia 2013/02/13 16:37:14 Split the observers into StreamReadObserver and St
49 void RemoveObserver(ChromeStreamObserver* observer);
50
51 // Add the data in |buffer| to the stream. Takes ownership of |buffer|
52 void AddData(scoped_refptr<net::IOBuffer> buffer, size_t size);
53
54 // Indicate that this stream will not be receiving any more data.
55 void MarkComplete();
56
57 // Read a maximum of |buf_size| from the stream into |buf|. Sets
58 // |*bytes_read| to the number of bytes actually read.
59 // returns false if there is no data available, but the stream is not closed.
60 bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read);
61
62 // Indicates that the stream's buffer is getting full, and future reads from
63 // the source should be deferred.
64 bool should_defer() const { return should_defer_; }
65
66 void SetStreamUrl(GURL url) { stream_url_ = url; }
67 GURL stream_url() { return stream_url_; }
68
69 GURL& security_origin() { return security_origin_; }
70
71 private:
72 friend class base::RefCountedThreadSafe<ChromeStream>;
73
74 typedef std::deque<std::pair<scoped_refptr<net::IOBuffer>,
75 size_t> > ContentVector;
76
77 // Notify observers if the stream is fully read.
78 void MaybeNotifyComplete();
79
80 ~ChromeStream();
81
82 ContentVector buffer_;
83 size_t current_size_;
84 size_t bytes_read_;
85 bool complete_;
86
87 bool should_defer_;
88
89 GURL security_origin_;
90
91 GURL stream_url_;
92
93 ObserverList<ChromeStreamObserver> observers_;
94
95 DISALLOW_COPY_AND_ASSIGN(ChromeStream);
96 };
97
98 } // namespace content
99
100 #endif // CONTENT_BROWSER_STREAMS_CHROME_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698