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

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

Issue 12645004: Add Resource Handler for creating Streams to forward to extensions (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Disable Stream Resource Throttle 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
« no previous file with comments | « content/browser/loader/stream_resource_handler.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
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_STREAMS_STREAM_H_ 5 #ifndef CONTENT_BROWSER_STREAMS_STREAM_H_
6 #define CONTENT_BROWSER_STREAMS_STREAM_H_ 6 #define CONTENT_BROWSER_STREAMS_STREAM_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "content/browser/download/byte_stream.h" 11 #include "content/browser/download/byte_stream.h"
12 #include "content/common/content_export.h" 12 #include "content/common/content_export.h"
13 #include "googleurl/src/gurl.h" 13 #include "googleurl/src/gurl.h"
14 14
15 namespace net { 15 namespace net {
16 class IOBuffer; 16 class IOBuffer;
17 } 17 }
18 18
19 namespace content { 19 namespace content {
20 20
21 class StreamHandle;
22 class StreamHandleImpl;
21 class StreamReadObserver; 23 class StreamReadObserver;
22 class StreamRegistry; 24 class StreamRegistry;
23 class StreamWriteObserver; 25 class StreamWriteObserver;
24 26
25 // A stream that sends data from an arbitrary source to an internal URL 27 // A stream that sends data from an arbitrary source to an internal URL
26 // that can be read by an internal consumer. It will continue to pull from the 28 // that can be read by an internal consumer. It will continue to pull from the
27 // original URL as long as there is data available. It can be read from 29 // original URL as long as there is data available. It can be read from
28 // multiple clients, but only one can be reading at a time. This allows a 30 // multiple clients, but only one can be reading at a time. This allows a
29 // reader to consume part of the stream, then pass it along to another client 31 // reader to consume part of the stream, then pass it along to another client
30 // to continue processing the stream. 32 // to continue processing the stream.
(...skipping 11 matching lines...) Expand all
42 const GURL& security_origin, 44 const GURL& security_origin,
43 const GURL& url); 45 const GURL& url);
44 46
45 // Sets the reader of this stream. Returns true on success, or false if there 47 // Sets the reader of this stream. Returns true on success, or false if there
46 // is already a reader. 48 // is already a reader.
47 bool SetReadObserver(StreamReadObserver* observer); 49 bool SetReadObserver(StreamReadObserver* observer);
48 50
49 // Removes the read observer. |observer| must be the current observer. 51 // Removes the read observer. |observer| must be the current observer.
50 void RemoveReadObserver(StreamReadObserver* observer); 52 void RemoveReadObserver(StreamReadObserver* observer);
51 53
54 // Removes the write observer. |observer| must be the current observer.
55 void RemoveWriteObserver(StreamWriteObserver* observer);
56
52 // Adds the data in |buffer| to the stream. Takes ownership of |buffer|. 57 // Adds the data in |buffer| to the stream. Takes ownership of |buffer|.
53 void AddData(scoped_refptr<net::IOBuffer> buffer, size_t size); 58 void AddData(scoped_refptr<net::IOBuffer> buffer, size_t size);
54 59
55 // Notifies this stream that it will not be receiving any more data. 60 // Notifies this stream that it will not be receiving any more data.
56 void Finalize(); 61 void Finalize();
57 62
58 // Reads a maximum of |buf_size| from the stream into |buf|. Sets 63 // Reads a maximum of |buf_size| from the stream into |buf|. Sets
59 // |*bytes_read| to the number of bytes actually read. 64 // |*bytes_read| to the number of bytes actually read.
60 // Returns STREAM_HAS_DATA if data was read, STREAM_EMPTY if no data was read, 65 // Returns STREAM_HAS_DATA if data was read, STREAM_EMPTY if no data was read,
61 // and STREAM_COMPLETE if the stream is finalized and all data has been read. 66 // and STREAM_COMPLETE if the stream is finalized and all data has been read.
62 StreamState ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read); 67 StreamState ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read);
63 68
69 scoped_ptr<StreamHandle> CreateHandle(const GURL& original_url,
70 const std::string& mime_type);
71 void CloseHandle();
72
64 // Indicates whether there is space in the buffer to add more data. 73 // Indicates whether there is space in the buffer to add more data.
65 bool can_add_data() const { return can_add_data_; } 74 bool can_add_data() const { return can_add_data_; }
66 75
67 const GURL& url() const { return url_; } 76 const GURL& url() const { return url_; }
68 77
69 const GURL& security_origin() const { return security_origin_; } 78 const GURL& security_origin() const { return security_origin_; }
70 79
71 private: 80 private:
72 friend class base::RefCountedThreadSafe<Stream>; 81 friend class base::RefCountedThreadSafe<Stream>;
73 82
(...skipping 11 matching lines...) Expand all
85 scoped_refptr<net::IOBuffer> data_; 94 scoped_refptr<net::IOBuffer> data_;
86 size_t data_length_; 95 size_t data_length_;
87 96
88 scoped_ptr<ByteStreamWriter> writer_; 97 scoped_ptr<ByteStreamWriter> writer_;
89 scoped_ptr<ByteStreamReader> reader_; 98 scoped_ptr<ByteStreamReader> reader_;
90 99
91 StreamRegistry* registry_; 100 StreamRegistry* registry_;
92 StreamReadObserver* read_observer_; 101 StreamReadObserver* read_observer_;
93 StreamWriteObserver* write_observer_; 102 StreamWriteObserver* write_observer_;
94 103
104 StreamHandleImpl* stream_handle_;
105
95 base::WeakPtrFactory<Stream> weak_ptr_factory_; 106 base::WeakPtrFactory<Stream> weak_ptr_factory_;
96 DISALLOW_COPY_AND_ASSIGN(Stream); 107 DISALLOW_COPY_AND_ASSIGN(Stream);
97 }; 108 };
98 109
99 } // namespace content 110 } // namespace content
100 111
101 #endif // CONTENT_BROWSER_STREAMS_STREAM_H_ 112 #endif // CONTENT_BROWSER_STREAMS_STREAM_H_
OLDNEW
« no previous file with comments | « content/browser/loader/stream_resource_handler.cc ('k') | content/browser/streams/stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698