| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_DOWNLOAD_BYTE_STREAM_H_ | 5 #ifndef CONTENT_BROWSER_DOWNLOAD_BYTE_STREAM_H_ |
| 6 #define CONTENT_BROWSER_DOWNLOAD_BYTE_STREAM_H_ | 6 #define CONTENT_BROWSER_DOWNLOAD_BYTE_STREAM_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 75 |
| 76 // Register a callback to be called when the stream transitions from | 76 // Register a callback to be called when the stream transitions from |
| 77 // full to having space available. The callback will always be | 77 // full to having space available. The callback will always be |
| 78 // called on the task runner associated with the ByteStreamInput. | 78 // called on the task runner associated with the ByteStreamInput. |
| 79 // This callback will only be called if a call to Write has previously | 79 // This callback will only be called if a call to Write has previously |
| 80 // returned false (i.e. the ByteStream has been filled). | 80 // returned false (i.e. the ByteStream has been filled). |
| 81 // Multiple calls to this function are supported, though note that it | 81 // Multiple calls to this function are supported, though note that it |
| 82 // is the callers responsibility to handle races with space becoming | 82 // is the callers responsibility to handle races with space becoming |
| 83 // available (i.e. in the case of that race either of the before | 83 // available (i.e. in the case of that race either of the before |
| 84 // or after callbacks may be called). | 84 // or after callbacks may be called). |
| 85 // The callback will not be called after ByteStreamInput destruction. |
| 85 virtual void RegisterCallback(const base::Closure& source_callback) = 0; | 86 virtual void RegisterCallback(const base::Closure& source_callback) = 0; |
| 86 }; | 87 }; |
| 87 | 88 |
| 88 class CONTENT_EXPORT ByteStreamOutput { | 89 class CONTENT_EXPORT ByteStreamOutput { |
| 89 public: | 90 public: |
| 90 enum StreamState { STREAM_EMPTY, STREAM_HAS_DATA, STREAM_COMPLETE }; | 91 enum StreamState { STREAM_EMPTY, STREAM_HAS_DATA, STREAM_COMPLETE }; |
| 91 | 92 |
| 92 virtual ~ByteStreamOutput() = 0; | 93 virtual ~ByteStreamOutput() = 0; |
| 93 | 94 |
| 94 // Returns STREAM_EMPTY if there is no data on the ByteStream and | 95 // Returns STREAM_EMPTY if there is no data on the ByteStream and |
| 95 // Close() has not been called, and STREAM_COMPLETE if there | 96 // Close() has not been called, and STREAM_COMPLETE if there |
| 96 // is no data on the ByteStream and Close() has been called. | 97 // is no data on the ByteStream and Close() has been called. |
| 97 // If there is data on the ByteStream, returns STREAM_HAS_DATA | 98 // If there is data on the ByteStream, returns STREAM_HAS_DATA |
| 98 // and fills in |*data| with a pointer to the data, and |*length| | 99 // and fills in |*data| with a pointer to the data, and |*length| |
| 99 // with its length. | 100 // with its length. |
| 100 virtual StreamState Read(scoped_refptr<net::IOBuffer>* data, | 101 virtual StreamState Read(scoped_refptr<net::IOBuffer>* data, |
| 101 size_t* length) = 0; | 102 size_t* length) = 0; |
| 102 | 103 |
| 103 // Only valid to call if Read() has returned STREAM_COMPLETE. | 104 // Only valid to call if Read() has returned STREAM_COMPLETE. |
| 104 virtual DownloadInterruptReason GetStatus() const = 0; | 105 virtual DownloadInterruptReason GetStatus() const = 0; |
| 105 | 106 |
| 106 // Register a callback to be called when data is added or the source | 107 // Register a callback to be called when data is added or the source |
| 107 // completes. The callback will be always be called on the owning | 108 // completes. The callback will be always be called on the owning |
| 108 // task runner. Multiple calls to this function are supported, | 109 // task runner. Multiple calls to this function are supported, |
| 109 // though note that it is the callers responsibility to handle races | 110 // though note that it is the callers responsibility to handle races |
| 110 // with data becoming available (i.e. in the case of that race | 111 // with data becoming available (i.e. in the case of that race |
| 111 // either of the before or after callbacks may be called). | 112 // either of the before or after callbacks may be called). |
| 113 // The callback will not be called after ByteStreamOutput destruction. |
| 112 virtual void RegisterCallback(const base::Closure& sink_callback) = 0; | 114 virtual void RegisterCallback(const base::Closure& sink_callback) = 0; |
| 113 }; | 115 }; |
| 114 | 116 |
| 115 CONTENT_EXPORT void CreateByteStream( | 117 CONTENT_EXPORT void CreateByteStream( |
| 116 scoped_refptr<base::SequencedTaskRunner> input_task_runner, | 118 scoped_refptr<base::SequencedTaskRunner> input_task_runner, |
| 117 scoped_refptr<base::SequencedTaskRunner> output_task_runner, | 119 scoped_refptr<base::SequencedTaskRunner> output_task_runner, |
| 118 size_t buffer_size, | 120 size_t buffer_size, |
| 119 scoped_ptr<ByteStreamInput>* input, | 121 scoped_ptr<ByteStreamInput>* input, |
| 120 scoped_ptr<ByteStreamOutput>* output); | 122 scoped_ptr<ByteStreamOutput>* output); |
| 121 | 123 |
| 122 } // namespace content | 124 } // namespace content |
| 123 | 125 |
| 124 #endif // CONTENT_BROWSER_DOWNLOAD_BYTE_STREAM_H_ | 126 #endif // CONTENT_BROWSER_DOWNLOAD_BYTE_STREAM_H_ |
| OLD | NEW |