Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: mojo/services/network/public/cpp/web_socket_read_queue.h

Issue 1148913002: Fix WebSocket{Read,Write}Queue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "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 Reads on a DataPipe. It reads 15 // This class simplifies the handling of multiple Reads on a DataPipe. It reads
16 // the data in the expected chunk size, calling the callback once a full chunk 16 // the data in the expected chunk size, calling the callback once a full chunk
17 // is ready. Callbacks are owned by this class, and are guaranteed not to be 17 // is ready. Callbacks are owned by this class, and are guaranteed not to be
18 // called after this class is destroyed. 18 // called after this class is destroyed.
19 // See also: WebSocketWriteQueue 19 // See also: WebSocketWriteQueue
20 class WebSocketReadQueue { 20 class WebSocketReadQueue {
21 public: 21 public:
22 WebSocketReadQueue(DataPipeConsumerHandle handle); 22 explicit WebSocketReadQueue(DataPipeConsumerHandle handle);
23 ~WebSocketReadQueue(); 23 ~WebSocketReadQueue();
24 24
25 void Read(uint32_t num_bytes, base::Callback<void(const char*)> callback); 25 void Read(uint32_t num_bytes, base::Callback<void(const char*)> callback);
26 26
27 private: 27 private:
28 struct Operation; 28 struct Operation;
29 29
30 void TryToRead(); 30 void TryToRead();
31 void Wait(); 31 void Wait();
32 void OnHandleReady(MojoResult result); 32 void OnHandleReady(MojoResult result);
33 33
34 DataPipeConsumerHandle handle_; 34 DataPipeConsumerHandle handle_;
35 common::HandleWatcher handle_watcher_; 35 common::HandleWatcher handle_watcher_;
36 ScopedVector<Operation> queue_; 36 ScopedVector<Operation> queue_;
37 bool is_waiting_; 37 bool is_busy_;
38 // If non-null, the boolean it points to (allocated on the stack) will be set
39 // to true when this object is destructed.
40 bool* destructed_;
38 }; 41 };
39 42
40 } // namespace mojo 43 } // namespace mojo
41 44
42 #endif // MOJO_SERVICES_NETWORK_PUBLIC_CPP_WEB_SOCKET_READ_QUEUE_H_ 45 #endif // MOJO_SERVICES_NETWORK_PUBLIC_CPP_WEB_SOCKET_READ_QUEUE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698