| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 MOJO_SERVICES_NETWORK_PUBLIC_CPP_WEB_SOCKET_WRITE_QUEUE_H_ | 5 #ifndef MOJO_SERVICES_NETWORK_PUBLIC_CPP_WEB_SOCKET_WRITE_QUEUE_H_ |
| 6 #define MOJO_SERVICES_NETWORK_PUBLIC_CPP_WEB_SOCKET_WRITE_QUEUE_H_ | 6 #define MOJO_SERVICES_NETWORK_PUBLIC_CPP_WEB_SOCKET_WRITE_QUEUE_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "mojo/common/handle_watcher.h" | 10 #include "mojo/common/handle_watcher.h" |
| 11 #include "third_party/mojo/src/mojo/public/cpp/system/data_pipe.h" | 11 #include "third_party/mojo/src/mojo/public/cpp/system/data_pipe.h" |
| 12 | 12 |
| 13 namespace mojo { | 13 namespace mojo { |
| 14 | 14 |
| 15 // This class simplifies the handling of multiple Writes on a DataPipe. It | 15 // This class simplifies the handling of multiple Writes on a DataPipe. It |
| 16 // writes each chunk all at once (or waits until the pipe is ready before | 16 // writes each chunk all at once (or waits until the pipe is ready before |
| 17 // writing), calling the callback when finished. Callbacks are owned by this | 17 // writing), calling the callback when finished. Callbacks are owned by this |
| 18 // class, and are guaranteed not to be called after this class is destroyed. | 18 // class, and are guaranteed not to be called after this class is destroyed. |
| 19 // See also: WebSocketReadQueue | 19 // See also: WebSocketReadQueue |
| 20 class WebSocketWriteQueue { | 20 class WebSocketWriteQueue { |
| 21 public: | 21 public: |
| 22 WebSocketWriteQueue(DataPipeProducerHandle handle); | 22 explicit WebSocketWriteQueue(DataPipeProducerHandle handle); |
| 23 ~WebSocketWriteQueue(); | 23 ~WebSocketWriteQueue(); |
| 24 | 24 |
| 25 void Write(const char* data, | 25 void Write(const char* data, |
| 26 uint32_t num_bytes, | 26 uint32_t num_bytes, |
| 27 base::Callback<void(const char*)> callback); | 27 base::Callback<void(const char*)> callback); |
| 28 | 28 |
| 29 private: | 29 private: |
| 30 struct Operation; | 30 struct Operation; |
| 31 | 31 |
| 32 MojoResult TryToWrite(); | 32 void TryToWrite(); |
| 33 void Wait(); | 33 void Wait(); |
| 34 void OnHandleReady(MojoResult result); | 34 void OnHandleReady(MojoResult result); |
| 35 | 35 |
| 36 DataPipeProducerHandle handle_; | 36 DataPipeProducerHandle handle_; |
| 37 common::HandleWatcher handle_watcher_; | 37 common::HandleWatcher handle_watcher_; |
| 38 ScopedVector<Operation> queue_; | 38 ScopedVector<Operation> queue_; |
| 39 bool is_waiting_; | 39 bool is_busy_; |
| 40 // If non-null, the boolean it points to (allocated on the stack) will be set |
| 41 // to true when this object is destructed. |
| 42 bool* destructed_; |
| 40 }; | 43 }; |
| 41 | 44 |
| 42 } // namespace mojo | 45 } // namespace mojo |
| 43 | 46 |
| 44 #endif // MOJO_SERVICES_NETWORK_PUBLIC_CPP_WEB_SOCKET_WRITE_QUEUE_H_ | 47 #endif // MOJO_SERVICES_NETWORK_PUBLIC_CPP_WEB_SOCKET_WRITE_QUEUE_H_ |
| OLD | NEW |