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