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_READ_QUEUE_H_ | 5 #ifndef MOJO_SERVICES_NETWORK_PUBLIC_CPP_WEB_SOCKET_READ_QUEUE_H_ |
6 #define MOJO_SERVICES_NETWORK_PUBLIC_CPP_WEB_SOCKET_READ_QUEUE_H_ | 6 #define MOJO_SERVICES_NETWORK_PUBLIC_CPP_WEB_SOCKET_READ_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 "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "mojo/message_pump/handle_watcher.h" | 11 #include "mojo/message_pump/handle_watcher.h" |
12 #include "third_party/mojo/src/mojo/public/cpp/system/data_pipe.h" | 12 #include "third_party/mojo/src/mojo/public/cpp/system/data_pipe.h" |
13 | 13 |
14 namespace mojo { | 14 namespace mojo { |
15 | 15 |
16 // This class simplifies the handling of multiple Reads on a DataPipe. It reads | 16 // This class simplifies the handling of multiple Reads on a DataPipe. It reads |
17 // the data in the expected chunk size, calling the callback once a full chunk | 17 // the data in the expected chunk size, calling the callback once a full chunk |
18 // is ready. Callbacks are owned by this class, and are guaranteed not to be | 18 // is ready. Callbacks are owned by this class, and are guaranteed not to be |
19 // called after this class is destroyed. | 19 // called after this class is destroyed. |
20 // See also: WebSocketWriteQueue | 20 // See also: WebSocketWriteQueue |
21 class WebSocketReadQueue { | 21 class WebSocketReadQueue { |
22 public: | 22 public: |
23 explicit WebSocketReadQueue(DataPipeConsumerHandle handle); | 23 explicit WebSocketReadQueue(DataPipeConsumerHandle handle); |
24 ~WebSocketReadQueue(); | 24 ~WebSocketReadQueue(); |
25 | 25 |
26 void Read(uint32_t num_bytes, base::Callback<void(const char*)> callback); | 26 void Read(uint32_t num_bytes, |
| 27 const base::Callback<void(const char*)>& callback); |
27 | 28 |
28 private: | 29 private: |
29 struct Operation; | 30 struct Operation; |
30 | 31 |
31 void TryToRead(); | 32 void TryToRead(); |
32 void Wait(); | 33 void Wait(); |
33 void OnHandleReady(MojoResult result); | 34 void OnHandleReady(MojoResult result); |
34 | 35 |
35 DataPipeConsumerHandle handle_; | 36 DataPipeConsumerHandle handle_; |
36 common::HandleWatcher handle_watcher_; | 37 common::HandleWatcher handle_watcher_; |
37 ScopedVector<Operation> queue_; | 38 ScopedVector<Operation> queue_; |
38 bool is_busy_; | 39 bool is_busy_; |
39 base::WeakPtrFactory<WebSocketReadQueue> weak_factory_; | 40 base::WeakPtrFactory<WebSocketReadQueue> weak_factory_; |
40 }; | 41 }; |
41 | 42 |
42 } // namespace mojo | 43 } // namespace mojo |
43 | 44 |
44 #endif // MOJO_SERVICES_NETWORK_PUBLIC_CPP_WEB_SOCKET_READ_QUEUE_H_ | 45 #endif // MOJO_SERVICES_NETWORK_PUBLIC_CPP_WEB_SOCKET_READ_QUEUE_H_ |
OLD | NEW |