| 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 REMOTING_BASE_BUFFERED_SOCKET_WRITER_H_ | 5 #ifndef REMOTING_BASE_BUFFERED_SOCKET_WRITER_H_ |
| 6 #define REMOTING_BASE_BUFFERED_SOCKET_WRITER_H_ | 6 #define REMOTING_BASE_BUFFERED_SOCKET_WRITER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <memory> |
| 9 | 10 |
| 10 #include "base/callback.h" | 11 #include "base/callback.h" |
| 11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 12 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 13 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 14 #include "net/base/completion_callback.h" | 15 #include "net/base/completion_callback.h" |
| 15 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
| 16 | 17 |
| 17 namespace net { | 18 namespace net { |
| 18 class Socket; | 19 class Socket; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 45 // Puts a new data chunk in the buffer. If called before Start() then all data | 46 // Puts a new data chunk in the buffer. If called before Start() then all data |
| 46 // is buffered until Start(). | 47 // is buffered until Start(). |
| 47 void Write(const scoped_refptr<net::IOBufferWithSize>& buffer, | 48 void Write(const scoped_refptr<net::IOBufferWithSize>& buffer, |
| 48 const base::Closure& done_task); | 49 const base::Closure& done_task); |
| 49 | 50 |
| 50 // Returns true when there is data waiting to be written. | 51 // Returns true when there is data waiting to be written. |
| 51 bool has_data_pending() { return !queue_.empty(); } | 52 bool has_data_pending() { return !queue_.empty(); } |
| 52 | 53 |
| 53 private: | 54 private: |
| 54 struct PendingPacket; | 55 struct PendingPacket; |
| 55 typedef std::list<PendingPacket*> DataQueue; | |
| 56 | 56 |
| 57 void DoWrite(); | 57 void DoWrite(); |
| 58 void HandleWriteResult(int result); | 58 void HandleWriteResult(int result); |
| 59 void OnWritten(int result); | 59 void OnWritten(int result); |
| 60 | 60 |
| 61 base::ThreadChecker thread_checker_; | 61 base::ThreadChecker thread_checker_; |
| 62 | 62 |
| 63 WriteCallback write_callback_; | 63 WriteCallback write_callback_; |
| 64 WriteFailedCallback write_failed_callback_; | 64 WriteFailedCallback write_failed_callback_; |
| 65 | 65 |
| 66 bool closed_ = false; | 66 bool closed_ = false; |
| 67 | 67 |
| 68 DataQueue queue_; | 68 std::list<std::unique_ptr<PendingPacket>> queue_; |
| 69 | 69 |
| 70 bool write_pending_ = false; | 70 bool write_pending_ = false; |
| 71 | 71 |
| 72 base::WeakPtrFactory<BufferedSocketWriter> weak_factory_; | 72 base::WeakPtrFactory<BufferedSocketWriter> weak_factory_; |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 } // namespace remoting | 75 } // namespace remoting |
| 76 | 76 |
| 77 #endif // REMOTING_BASE_BUFFERED_SOCKET_WRITER_H_ | 77 #endif // REMOTING_BASE_BUFFERED_SOCKET_WRITER_H_ |
| OLD | NEW |