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

Unified Diff: mojo/system/local_message_pipe_endpoint.cc

Issue 621153003: Move mojo edk into mojo/edk (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix checkdeps Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/system/local_message_pipe_endpoint.h ('k') | mojo/system/mapping_table.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/system/local_message_pipe_endpoint.cc
diff --git a/mojo/system/local_message_pipe_endpoint.cc b/mojo/system/local_message_pipe_endpoint.cc
deleted file mode 100644
index 24b7e7c90596174d16206901c4f13fbf1d4cabad..0000000000000000000000000000000000000000
--- a/mojo/system/local_message_pipe_endpoint.cc
+++ /dev/null
@@ -1,176 +0,0 @@
-// Copyright 2013 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/system/local_message_pipe_endpoint.h"
-
-#include <string.h>
-
-#include "base/logging.h"
-#include "mojo/system/dispatcher.h"
-#include "mojo/system/message_in_transit.h"
-
-namespace mojo {
-namespace system {
-
-LocalMessagePipeEndpoint::LocalMessagePipeEndpoint()
- : is_open_(true), is_peer_open_(true) {
-}
-
-LocalMessagePipeEndpoint::~LocalMessagePipeEndpoint() {
- DCHECK(!is_open_);
- DCHECK(message_queue_.IsEmpty()); // Should be implied by not being open.
-}
-
-MessagePipeEndpoint::Type LocalMessagePipeEndpoint::GetType() const {
- return kTypeLocal;
-}
-
-bool LocalMessagePipeEndpoint::OnPeerClose() {
- DCHECK(is_open_);
- DCHECK(is_peer_open_);
-
- HandleSignalsState old_state = GetHandleSignalsState();
- is_peer_open_ = false;
- HandleSignalsState new_state = GetHandleSignalsState();
-
- if (!new_state.equals(old_state))
- waiter_list_.AwakeWaitersForStateChange(new_state);
-
- return true;
-}
-
-void LocalMessagePipeEndpoint::EnqueueMessage(
- scoped_ptr<MessageInTransit> message) {
- DCHECK(is_open_);
- DCHECK(is_peer_open_);
-
- bool was_empty = message_queue_.IsEmpty();
- message_queue_.AddMessage(message.Pass());
- if (was_empty)
- waiter_list_.AwakeWaitersForStateChange(GetHandleSignalsState());
-}
-
-void LocalMessagePipeEndpoint::Close() {
- DCHECK(is_open_);
- is_open_ = false;
- message_queue_.Clear();
-}
-
-void LocalMessagePipeEndpoint::CancelAllWaiters() {
- DCHECK(is_open_);
- waiter_list_.CancelAllWaiters();
-}
-
-MojoResult LocalMessagePipeEndpoint::ReadMessage(
- UserPointer<void> bytes,
- UserPointer<uint32_t> num_bytes,
- DispatcherVector* dispatchers,
- uint32_t* num_dispatchers,
- MojoReadMessageFlags flags) {
- DCHECK(is_open_);
- DCHECK(!dispatchers || dispatchers->empty());
-
- const uint32_t max_bytes = num_bytes.IsNull() ? 0 : num_bytes.Get();
- const uint32_t max_num_dispatchers = num_dispatchers ? *num_dispatchers : 0;
-
- if (message_queue_.IsEmpty()) {
- return is_peer_open_ ? MOJO_RESULT_SHOULD_WAIT
- : MOJO_RESULT_FAILED_PRECONDITION;
- }
-
- // TODO(vtl): If |flags & MOJO_READ_MESSAGE_FLAG_MAY_DISCARD|, we could pop
- // and release the lock immediately.
- bool enough_space = true;
- MessageInTransit* message = message_queue_.PeekMessage();
- if (!num_bytes.IsNull())
- num_bytes.Put(message->num_bytes());
- if (message->num_bytes() <= max_bytes)
- bytes.PutArray(message->bytes(), message->num_bytes());
- else
- enough_space = false;
-
- if (DispatcherVector* queued_dispatchers = message->dispatchers()) {
- if (num_dispatchers)
- *num_dispatchers = static_cast<uint32_t>(queued_dispatchers->size());
- if (enough_space) {
- if (queued_dispatchers->empty()) {
- // Nothing to do.
- } else if (queued_dispatchers->size() <= max_num_dispatchers) {
- DCHECK(dispatchers);
- dispatchers->swap(*queued_dispatchers);
- } else {
- enough_space = false;
- }
- }
- } else {
- if (num_dispatchers)
- *num_dispatchers = 0;
- }
-
- message = nullptr;
-
- if (enough_space || (flags & MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)) {
- message_queue_.DiscardMessage();
-
- // Now it's empty, thus no longer readable.
- if (message_queue_.IsEmpty()) {
- // It's currently not possible to wait for non-readability, but we should
- // do the state change anyway.
- waiter_list_.AwakeWaitersForStateChange(GetHandleSignalsState());
- }
- }
-
- if (!enough_space)
- return MOJO_RESULT_RESOURCE_EXHAUSTED;
-
- return MOJO_RESULT_OK;
-}
-
-HandleSignalsState LocalMessagePipeEndpoint::GetHandleSignalsState() const {
- HandleSignalsState rv;
- if (!message_queue_.IsEmpty()) {
- rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_READABLE;
- rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE;
- }
- if (is_peer_open_) {
- rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_WRITABLE;
- rv.satisfiable_signals |=
- MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE;
- }
- return rv;
-}
-
-MojoResult LocalMessagePipeEndpoint::AddWaiter(
- Waiter* waiter,
- MojoHandleSignals signals,
- uint32_t context,
- HandleSignalsState* signals_state) {
- DCHECK(is_open_);
-
- HandleSignalsState state = GetHandleSignalsState();
- if (state.satisfies(signals)) {
- if (signals_state)
- *signals_state = state;
- return MOJO_RESULT_ALREADY_EXISTS;
- }
- if (!state.can_satisfy(signals)) {
- if (signals_state)
- *signals_state = state;
- return MOJO_RESULT_FAILED_PRECONDITION;
- }
-
- waiter_list_.AddWaiter(waiter, signals, context);
- return MOJO_RESULT_OK;
-}
-
-void LocalMessagePipeEndpoint::RemoveWaiter(Waiter* waiter,
- HandleSignalsState* signals_state) {
- DCHECK(is_open_);
- waiter_list_.RemoveWaiter(waiter);
- if (signals_state)
- *signals_state = GetHandleSignalsState();
-}
-
-} // namespace system
-} // namespace mojo
« no previous file with comments | « mojo/system/local_message_pipe_endpoint.h ('k') | mojo/system/mapping_table.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698