Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 // Sets the reader of this stream. Returns true on success, or false if there | 51 // Sets the reader of this stream. Returns true on success, or false if there |
| 52 // is already a reader. | 52 // is already a reader. |
| 53 bool SetReadObserver(StreamReadObserver* observer); | 53 bool SetReadObserver(StreamReadObserver* observer); |
| 54 | 54 |
| 55 // Removes the read observer. |observer| must be the current observer. | 55 // Removes the read observer. |observer| must be the current observer. |
| 56 void RemoveReadObserver(StreamReadObserver* observer); | 56 void RemoveReadObserver(StreamReadObserver* observer); |
| 57 | 57 |
| 58 // Removes the write observer. |observer| must be the current observer. | 58 // Removes the write observer. |observer| must be the current observer. |
| 59 void RemoveWriteObserver(StreamWriteObserver* observer); | 59 void RemoveWriteObserver(StreamWriteObserver* observer); |
| 60 | 60 |
| 61 // Stops accepting new data, clears all buffer, unregisters this stream from | |
| 62 // |registry_| and make coming ReadRawData() calls return STREAM_ABORTED. | |
| 63 void Abort(); | |
|
kinuko
2013/08/27 13:35:56
(ok this looks to be the right (same) order as in
| |
| 64 | |
| 61 // Adds the data in |buffer| to the stream. Takes ownership of |buffer|. | 65 // Adds the data in |buffer| to the stream. Takes ownership of |buffer|. |
| 62 void AddData(scoped_refptr<net::IOBuffer> buffer, size_t size); | 66 void AddData(scoped_refptr<net::IOBuffer> buffer, size_t size); |
| 63 // Adds data of |size| at |data| to the stream. This method creates a copy | 67 // Adds data of |size| at |data| to the stream. This method creates a copy |
| 64 // of the data, and then passes it to |writer_|. | 68 // of the data, and then passes it to |writer_|. |
| 65 void AddData(const char* data, size_t size); | 69 void AddData(const char* data, size_t size); |
| 66 | 70 |
| 67 // Notifies this stream that it will not be receiving any more data. | 71 // Notifies this stream that it will not be receiving any more data. |
| 68 void Finalize(); | 72 void Finalize(); |
| 69 | 73 |
| 70 // Reads a maximum of |buf_size| from the stream into |buf|. Sets | 74 // Reads a maximum of |buf_size| from the stream into |buf|. Sets |
| 71 // |*bytes_read| to the number of bytes actually read. | 75 // |*bytes_read| to the number of bytes actually read. |
| 72 // Returns STREAM_HAS_DATA if data was read, STREAM_EMPTY if no data was read, | 76 // Returns STREAM_HAS_DATA if data was read, STREAM_EMPTY if no data was read, |
| 73 // and STREAM_COMPLETE if the stream is finalized and all data has been read. | 77 // and STREAM_COMPLETE if the stream is finalized and all data has been read. |
| 74 StreamState ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read); | 78 StreamState ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read); |
| 75 | 79 |
| 76 scoped_ptr<StreamHandle> CreateHandle(const GURL& original_url, | 80 scoped_ptr<StreamHandle> CreateHandle(const GURL& original_url, |
| 77 const std::string& mime_type); | 81 const std::string& mime_type); |
| 78 void CloseHandle(); | 82 void CloseHandle(); |
| 79 | 83 |
| 80 // Indicates whether there is space in the buffer to add more data. | 84 // Indicates whether there is space in the buffer to add more data. |
| 81 bool can_add_data() const { return can_add_data_; } | 85 bool can_add_data() const { return can_add_data_; } |
| 82 | 86 |
| 83 const GURL& url() const { return url_; } | 87 const GURL& url() const { return url_; } |
| 84 | 88 |
| 85 // For StreamRegistry to remember the last memory usage reported to it. | 89 // For StreamRegistry to remember the last memory usage reported to it. |
| 86 size_t last_total_buffered_bytes() const { | 90 size_t last_total_buffered_bytes() const { |
| 87 return last_total_buffered_bytes_; | 91 return last_total_buffered_bytes_; |
| 88 } | 92 } |
| 89 | 93 |
| 90 protected: | |
| 91 // Stops accepting new data and make ReadRawData() return STREAM_ABORTED. | |
| 92 void Abort(); | |
| 93 | |
| 94 private: | 94 private: |
| 95 friend class base::RefCountedThreadSafe<Stream>; | 95 friend class base::RefCountedThreadSafe<Stream>; |
| 96 | 96 |
| 97 virtual ~Stream(); | 97 virtual ~Stream(); |
| 98 | 98 |
| 99 void OnSpaceAvailable(); | 99 void OnSpaceAvailable(); |
| 100 void OnDataAvailable(); | 100 void OnDataAvailable(); |
| 101 | 101 |
| 102 // Clears |data_| and related variables. | 102 // Clears |data_| and related variables. |
| 103 void ClearBuffer(); | 103 void ClearBuffer(); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 128 | 128 |
| 129 StreamHandleImpl* stream_handle_; | 129 StreamHandleImpl* stream_handle_; |
| 130 | 130 |
| 131 base::WeakPtrFactory<Stream> weak_ptr_factory_; | 131 base::WeakPtrFactory<Stream> weak_ptr_factory_; |
| 132 DISALLOW_COPY_AND_ASSIGN(Stream); | 132 DISALLOW_COPY_AND_ASSIGN(Stream); |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 } // namespace content | 135 } // namespace content |
| 136 | 136 |
| 137 #endif // CONTENT_BROWSER_STREAMS_STREAM_H_ | 137 #endif // CONTENT_BROWSER_STREAMS_STREAM_H_ |
| OLD | NEW |