| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 NET_FILTER_MOCK_SOURCE_STREAM_H_ | 5 #ifndef NET_FILTER_MOCK_SOURCE_STREAM_H_ |
| 6 #define NET_FILTER_MOCK_SOURCE_STREAM_H_ | 6 #define NET_FILTER_MOCK_SOURCE_STREAM_H_ |
| 7 | 7 |
| 8 #include <queue> | 8 #include <queue> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 // Enqueues a result to be returned by |Read|. This method does not make a | 39 // Enqueues a result to be returned by |Read|. This method does not make a |
| 40 // copy of |data|, so |data| must outlive this object. If |mode| is SYNC, | 40 // copy of |data|, so |data| must outlive this object. If |mode| is SYNC, |
| 41 // |Read| will return the supplied data synchronously; otherwise, consumer | 41 // |Read| will return the supplied data synchronously; otherwise, consumer |
| 42 // needs to call |CompleteNextRead| | 42 // needs to call |CompleteNextRead| |
| 43 void AddReadResult(const char* data, int len, Error error, Mode mode); | 43 void AddReadResult(const char* data, int len, Error error, Mode mode); |
| 44 | 44 |
| 45 // Completes a pending Read() call. Crash in debug build if there is no | 45 // Completes a pending Read() call. Crash in debug build if there is no |
| 46 // pending read. | 46 // pending read. |
| 47 void CompleteNextRead(); | 47 void CompleteNextRead(); |
| 48 | 48 |
| 49 // Affects behavior or AddReadResult. When set to true, each character in |
| 50 // |data| passed to AddReadResult will be read as an individual byte, instead |
| 51 // of all at once. Default to false. |
| 52 // Note that setting it only affects future calls to AddReadResult, not |
| 53 // previous ones. |
| 54 void set_read_one_byte_at_a_time(bool read_one_byte_at_a_time) { |
| 55 read_one_byte_at_a_time_ = read_one_byte_at_a_time; |
| 56 } |
| 57 |
| 58 // Returns true if a read is waiting to be completed. |
| 59 bool awaiting_completion() const { return awaiting_completion_; } |
| 60 |
| 49 private: | 61 private: |
| 50 struct QueuedResult { | 62 struct QueuedResult { |
| 51 QueuedResult(const char* data, int len, Error error, Mode mode); | 63 QueuedResult(const char* data, int len, Error error, Mode mode); |
| 52 | 64 |
| 53 const char* data; | 65 const char* data; |
| 54 const int len; | 66 const int len; |
| 55 const Error error; | 67 const Error error; |
| 56 const Mode mode; | 68 const Mode mode; |
| 57 }; | 69 }; |
| 58 | 70 |
| 71 bool read_one_byte_at_a_time_; |
| 59 std::queue<QueuedResult> results_; | 72 std::queue<QueuedResult> results_; |
| 60 bool awaiting_completion_; | 73 bool awaiting_completion_; |
| 61 scoped_refptr<IOBuffer> dest_buffer_; | 74 scoped_refptr<IOBuffer> dest_buffer_; |
| 62 CompletionCallback callback_; | 75 CompletionCallback callback_; |
| 63 int dest_buffer_size_; | 76 int dest_buffer_size_; |
| 64 | 77 |
| 65 DISALLOW_COPY_AND_ASSIGN(MockSourceStream); | 78 DISALLOW_COPY_AND_ASSIGN(MockSourceStream); |
| 66 }; | 79 }; |
| 67 | 80 |
| 68 } // namespace net | 81 } // namespace net |
| 69 | 82 |
| 70 #endif // NET_FILTER_MOCK_SOURCE_STREAM_H_ | 83 #endif // NET_FILTER_MOCK_SOURCE_STREAM_H_ |
| OLD | NEW |