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

Unified Diff: mojo/services/public/cpp/network/web_socket_read_queue.cc

Issue 789243002: Restructure public side of network service. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Rebase Created 6 years 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 side-by-side diff with in-line comments
Download patch
Index: mojo/services/public/cpp/network/web_socket_read_queue.cc
diff --git a/mojo/services/public/cpp/network/web_socket_read_queue.cc b/mojo/services/public/cpp/network/web_socket_read_queue.cc
deleted file mode 100644
index 66b5a66e52566469b846dfdcd83e018c6c17cf09..0000000000000000000000000000000000000000
--- a/mojo/services/public/cpp/network/web_socket_read_queue.cc
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/services/public/cpp/network/web_socket_read_queue.h"
-
-#include "base/bind.h"
-
-namespace mojo {
-
-struct WebSocketReadQueue::Operation {
- uint32_t num_bytes_;
- base::Callback<void(const char*)> callback_;
-};
-
-WebSocketReadQueue::WebSocketReadQueue(DataPipeConsumerHandle handle)
- : handle_(handle), is_waiting_(false) {
-}
-
-WebSocketReadQueue::~WebSocketReadQueue() {
-}
-
-void WebSocketReadQueue::Read(uint32_t num_bytes,
- base::Callback<void(const char*)> callback) {
- Operation* op = new Operation;
- op->num_bytes_ = num_bytes;
- op->callback_ = callback;
- queue_.push_back(op);
-
- if (!is_waiting_)
- TryToRead();
-}
-
-void WebSocketReadQueue::TryToRead() {
- Operation* op = queue_[0];
- const void* buffer = NULL;
- uint32_t bytes_read = op->num_bytes_;
- MojoResult result = BeginReadDataRaw(
- handle_, &buffer, &bytes_read, MOJO_READ_DATA_FLAG_ALL_OR_NONE);
- if (result == MOJO_RESULT_SHOULD_WAIT) {
- EndReadDataRaw(handle_, bytes_read);
- Wait();
- return;
- }
-
- // Ensure |op| is deleted, whether or not |this| goes away.
- scoped_ptr<Operation> op_deleter(op);
- queue_.weak_erase(queue_.begin());
- if (result != MOJO_RESULT_OK)
- return;
- DataPipeConsumerHandle handle = handle_;
- op->callback_.Run(static_cast<const char*>(buffer)); // may delete |this|
- EndReadDataRaw(handle, bytes_read);
-}
-
-void WebSocketReadQueue::Wait() {
- is_waiting_ = true;
- handle_watcher_.Start(
- handle_,
- MOJO_HANDLE_SIGNAL_READABLE,
- MOJO_DEADLINE_INDEFINITE,
- base::Bind(&WebSocketReadQueue::OnHandleReady, base::Unretained(this)));
-}
-
-void WebSocketReadQueue::OnHandleReady(MojoResult result) {
- is_waiting_ = false;
- TryToRead();
-}
-
-} // namespace mojo
« no previous file with comments | « mojo/services/public/cpp/network/web_socket_read_queue.h ('k') | mojo/services/public/cpp/network/web_socket_write_queue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698