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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/streams/chrome_stream.h
diff --git a/content/browser/streams/chrome_stream.h b/content/browser/streams/chrome_stream.h
new file mode 100644
index 0000000000000000000000000000000000000000..e4882666b662e05885cb19df10e973933930390a
--- /dev/null
+++ b/content/browser/streams/chrome_stream.h
@@ -0,0 +1,100 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_STREAMS_CHROME_STREAM_H_
+#define CONTENT_BROWSER_STREAMS_CHROME_STREAM_H_
+
+#include <deque>
+
+#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
+#include "base/observer_list.h"
+#include "googleurl/src/gurl.h"
+
+namespace net {
+class IOBuffer;
+}
+
+namespace content {
+
+class ChromeStream;
+
+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.
+ public:
+ // Sent when there is data available to be read from the stream.
+ virtual void OnDataAvailable(ChromeStream* stream) = 0;
+
+ // Sent when the stream has been fully read, and will not be recieving more
+ // data.
+ virtual void OnStreamComplete(ChromeStream* stream) = 0;
+
+ // Sent when space becomes available in the stream, and the source should
+ // resume reading.
+ virtual void OnBufferAvailable(ChromeStream* stream) = 0;
+
+ protected:
+ virtual ~ChromeStreamObserver() {}
+};
+
+// A stream that sends data from an existing ResourceHandler to an internal URL
+// that can be read by an internal consumer.
+class ChromeStream
+ : public base::RefCountedThreadSafe<ChromeStream> {
+ public:
+ // Create a stream useable from the |security_origin|
+ ChromeStream(const GURL& security_origin);
+
+ 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
+ void RemoveObserver(ChromeStreamObserver* observer);
+
+ // Add the data in |buffer| to the stream. Takes ownership of |buffer|
+ void AddData(scoped_refptr<net::IOBuffer> buffer, size_t size);
+
+ // Indicate that this stream will not be receiving any more data.
+ void MarkComplete();
+
+ // Read a maximum of |buf_size| from the stream into |buf|. Sets
+ // |*bytes_read| to the number of bytes actually read.
+ // returns false if there is no data available, but the stream is not closed.
+ bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read);
+
+ // Indicates that the stream's buffer is getting full, and future reads from
+ // the source should be deferred.
+ bool should_defer() const { return should_defer_; }
+
+ void SetStreamUrl(GURL url) { stream_url_ = url; }
+ GURL stream_url() { return stream_url_; }
+
+ GURL& security_origin() { return security_origin_; }
+
+ private:
+ friend class base::RefCountedThreadSafe<ChromeStream>;
+
+ typedef std::deque<std::pair<scoped_refptr<net::IOBuffer>,
+ size_t> > ContentVector;
+
+ // Notify observers if the stream is fully read.
+ void MaybeNotifyComplete();
+
+ ~ChromeStream();
+
+ ContentVector buffer_;
+ size_t current_size_;
+ size_t bytes_read_;
+ bool complete_;
+
+ bool should_defer_;
+
+ GURL security_origin_;
+
+ GURL stream_url_;
+
+ ObserverList<ChromeStreamObserver> observers_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChromeStream);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_STREAMS_CHROME_STREAM_H_

Powered by Google App Engine
This is Rietveld 408576698